Browse Source

first commit

liuhairui 9 months ago
parent
commit
a71e1ce465

+ 272 - 29
application/api/controller/Manufacture.php

@@ -1041,79 +1041,210 @@ class Manufacture extends Api
     /**
      * 月度车间报工汇总-列表数据
      */
+
+//    public function MachineDetail()
+//    {
+//        if ($this->request->isGet() === false) {
+//            $this->error('请求错误');
+//        }
+//
+//        $param = $this->request->param();
+//        if (empty($param)) {
+//            $this->error('参数错误');
+//        }
+//
+//        $where = [];
+//
+//        // 获取当前年份
+//        $currentYear = date('Y');
+//
+//        // 处理日期参数(可选)
+//        if (!empty($param['date'])) {
+//            if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
+//                $where['a.sys_rq'] = ['like', "{$param['date']}%"];
+//            } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
+//                $monthDay = $param['date'];
+//                $where['a.sys_rq'] = ['like', "%-$monthDay%"];
+//            } elseif (preg_match('/^\d{2}$/', $param['date'])) {
+//                $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
+//            }
+//        }
+//
+//        // 订单编号筛选
+//        if (!empty($param['order'])) {
+//            $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
+//        }
+//
+//        // 机台号筛选
+//        if (!empty($param['machine'])) {
+//            $machineMapping = [
+//                '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
+//                '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
+//            ];
+//
+//            if (isset($machineMapping[$param['machine']])) {
+//                $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
+//            } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
+//                $where['a.sczl_jtbh'] = '';  // 若为日期格式,清空该字段
+//            } else {
+//                $where['a.sczl_jtbh'] = $param['machine'];
+//            }
+//        }
+//
+//        // 查询数据
+//        $list = \db('设备_产量计酬')->alias('a')
+//            ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
+//            ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
+//            ->field('
+//        a.工序名称, b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
+//        a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
+//        j.客户编号, j.生产款号, j.款式
+//    ')
+//            ->where($where)
+//            ->where('a.mod_rq', null)
+//            ->order('a.sys_rq desc, a.UniqId desc')
+//            ->group('a.UniqId')
+//            ->select();
+//
+//        // 提取所有的尺码,并去重,去除空格
+//        $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
+//
+//        // 自定义排序规则(已存在的排序逻辑)
+//        $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
+//        usort($sizeList, function ($a, $b) use ($sizeOrder) {
+//            // 数字优先比较
+//            if (is_numeric($a) && is_numeric($b)) {
+//                return $a - $b;
+//            }
+//            if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
+//                return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
+//            }
+//            if (is_numeric($a)) return -1;
+//            if (is_numeric($b)) return 1;
+//
+//            return strcmp($a, $b);
+//        });
+//
+//        // 不合并相同的子订单编号,而是按 "子订单编号 + 工序名称" 作为唯一键
+//        $mergedList = [];
+//        foreach ($list as $item) {
+//            $uniqueKey = $item['子订单编号'] . '-' . $item['工序名称']; // 关键点:加入工序名称
+//
+//            if (!isset($mergedList[$uniqueKey])) {
+//                $mergedList[$uniqueKey] = $item;
+//            } else {
+//                // 汇总数量
+//                foreach ($sizeList as $size) {
+//                    // 如果当前行有这个尺码,累加数量
+//                    if (isset($item['尺码']) && $item['尺码'] == $size) {
+//                        $mergedList[$uniqueKey][$size] = isset($mergedList[$uniqueKey][$size])
+//                            ? $mergedList[$uniqueKey][$size] + $item['数量']
+//                            : $item['数量'];
+//                    }
+//                }
+//            }
+//        }
+//
+//        // 转换合并后的数组为列表
+//        $finalList = array_values($mergedList);
+//
+//        // 将合并后的结果转换为列表形式
+//        $finalList = array_values($mergedList);
+//
+//        // 返回结果
+//        $this->success('请求成功', [
+//            'table' => $finalList,
+//            'length' => count($finalList),
+//            'headers' => $sizeList  // 返回所有的尺码作为表头
+//        ]);
+//    }
+
+
+    /**
+     * 月度车间报工汇总-列表详情数据
+     */
     public function MachineDetail()
     {
-        if ($this->request->isGet() === false) {$this->error('请求错误');}
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+
         $param = $this->request->param();
-        if (empty($param)) {$this->error('参数错误');}
+        if (empty($param)) {
+            $this->error('参数错误');
+        }
 
         $where = [];
 
-// 获取当前年份
+        // 获取当前年份
         $currentYear = date('Y');
 
-// 处理日期参数(可选)
+        // 处理日期参数(可选)
         if (!empty($param['date'])) {
-            // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
+            // 日期参数的格式处理
             if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
-                // 如果格式为 "YYYY-MM",查询当月数据
                 $where['a.sys_rq'] = ['like', "{$param['date']}%"];
             } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
-                // 如果格式为 "MM-DD",查询指定的月份和日期
                 $monthDay = $param['date'];
                 $where['a.sys_rq'] = ['like', "%-$monthDay%"];
             } elseif (preg_match('/^\d{2}$/', $param['date'])) {
-                // 如果格式为 "MM"(仅月份),自动补全为 "YYYY-MM"
                 $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
             }
         }
 
-// 判断是否传入订单编号参数(可选)
+        // 订单编号筛选
         if (!empty($param['order'])) {
-            $where['b.订单编号|b.款号'] = ['like', '%' . $param['order'] . '%'];
+            $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
         }
 
-// 处理机台号参数(可选)
+        // 机台号筛选
         if (!empty($param['machine'])) {
-            $where['a.sczl_jtbh'] = $param['machine'];
+            // 针对机台号的特定条件判断
+            $machineMapping = [
+                '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
+                '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
+            ];
+
+            if (isset($machineMapping[$param['machine']])) {
+                $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
+            } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
+                $where['a.sczl_jtbh'] = '';  // 若为日期格式,清空该字段
+            } else {
+                $where['a.sczl_jtbh'] = $param['machine'];
+            }
         }
 
-// 查询数据
+        // 查询数据
         $list = \db('设备_产量计酬')->alias('a')
             ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
             ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
             ->field('
-        b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
-        a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
-        j.客户编号, j.生产款号, j.款式
-    ')
+            a.工序名称, b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
+            a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
+            j.客户编号, j.生产款号, j.款式
+        ')
             ->where($where)
             ->where('a.mod_rq', null)
             ->order('a.sys_rq desc, a.UniqId desc')
             ->group('a.UniqId')
             ->select();
 
+        // 提取所有的尺码,并去重,去除空格
+        $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
 
-        // 提取所有的尺码,并去重
-        $sizeList = array_values(array_unique(array_column($list, '尺码')));
-
-        // **自定义排序规则**
-        $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
-
+        // 自定义排序规则(已存在的排序逻辑)
+        $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
         usort($sizeList, function ($a, $b) use ($sizeOrder) {
-            // 如果是数字,直接比较大小
+            // 数字优先比较
             if (is_numeric($a) && is_numeric($b)) {
                 return $a - $b;
             }
-            // 如果是字母,按 $sizeOrder 的索引排序
             if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
                 return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
             }
-            // 如果一个是数字,一个是字母,数字排在前面
             if (is_numeric($a)) return -1;
             if (is_numeric($b)) return 1;
 
-            // 如果都不符合,按字典顺序(备用)
             return strcmp($a, $b);
         });
 
@@ -1121,18 +1252,130 @@ class Manufacture extends Api
         foreach ($list as &$item) {
             $size = $item['尺码'];
             $item[$size] = $item['数量'];
-            // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
         }
 
         // 返回结果
         $this->success('请求成功', [
             'table' => $list,
             'length' => count($list),
-            'headers' => $sizeList // 返回所有的尺码作为表头
+            'headers' => $sizeList  // 返回所有的尺码作为表头
         ]);
     }
 
 
+//    public function MachineDetail()
+//    {
+//        if ($this->request->isGet() === false) {$this->error('请求错误');}
+//        $param = $this->request->param();
+//        if (empty($param)) {$this->error('参数错误');}
+//
+//        $where = [];
+//
+//        // 获取当前年份
+//        $currentYear = date('Y');
+//
+//        // 处理日期参数(可选)
+//        if (!empty($param['date'])) {
+//            // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
+//            if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
+//                // 如果格式为 "YYYY-MM",查询当月数据
+//                $where['a.sys_rq'] = ['like', "{$param['date']}%"];
+//            } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
+//                // 如果格式为 "MM-DD",查询指定的月份和日期
+//                $monthDay = $param['date'];
+//                $where['a.sys_rq'] = ['like', "%-$monthDay%"];
+//            } elseif (preg_match('/^\d{2}$/', $param['date'])) {
+//                // 如果格式为 "MM"(仅月份),自动补全为 "YYYY-MM"
+//                $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
+//            }
+//        }
+//
+//        // 判断是否传入订单编号参数(可选)
+//        if (!empty($param['order'])) {
+//            $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
+//        }
+//
+//        // 处理机台号参数(可选)
+//        if (!empty($param['machine'])) {
+//            // 判断是否为年-月格式(2025-02)
+//            if (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
+//                // 如果是日期格式,则设为空
+//                $where['a.sczl_jtbh'] = '';
+//            } else {
+//                // 如果不是日期格式,则正常赋值
+//                $where['a.sczl_jtbh'] = $param['machine'];
+//            }
+//        }
+//
+//        if($param['machine'] === '裁剪'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'CQ' . '%'];
+//        }else if($param['machine'] === '车缝'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'CF' . '%'];
+//        }else if($param['machine'] === '手工'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'HD' . '%'];
+//        }else if($param['machine'] === '大烫'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'DT' . '%'];
+//        }else if($param['machine'] === '总检'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'ZJ' . '%'];
+//        }else if($param['machine'] === '包装'){
+//            $where['a.sczl_jtbh'] = ['like', '%' . 'BZ' . '%'];
+//        }
+//
+//
+//        // 查询数据
+//        $list = \db('设备_产量计酬')->alias('a')
+//            ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
+//            ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
+//            ->field('
+//                a.工序名称,b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
+//                a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
+//                j.客户编号, j.生产款号, j.款式
+//            ')
+//            ->where($where)
+//            ->where('a.mod_rq', null)
+//            ->order('a.sys_rq desc, a.UniqId desc')
+//            ->group('a.UniqId')
+//            ->select();
+//
+//        // 提取所有的尺码,并去重
+//        $sizeList = array_values(array_unique(array_column($list, '尺码')));
+//
+//        // **自定义排序规则**
+//        $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
+//
+//        usort($sizeList, function ($a, $b) use ($sizeOrder) {
+//            // 如果是数字,直接比较大小
+//            if (is_numeric($a) && is_numeric($b)) {
+//                return $a - $b;
+//            }
+//            // 如果是字母,按 $sizeOrder 的索引排序
+//            if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
+//                return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
+//            }
+//            // 如果一个是数字,一个是字母,数字排在前面
+//            if (is_numeric($a)) return -1;
+//            if (is_numeric($b)) return 1;
+//
+//            // 如果都不符合,按字典顺序(备用)
+//            return strcmp($a, $b);
+//        });
+//
+//        // 动态将尺码的数量添加到每个订单中,并替换已完成字段
+//        foreach ($list as &$item) {
+//            $size = $item['尺码'];
+//            $item[$size] = $item['数量'];
+//            // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
+//        }
+//
+//        // 返回结果
+//        $this->success('请求成功', [
+//            'table' => $list,
+//            'length' => count($list),
+//            'headers' => $sizeList // 返回所有的尺码作为表头
+//        ]);
+//    }
+
+
     /**
      * 工单审核
      * @return void

+ 1 - 1
application/api/controller/WorkOrder.php

@@ -2544,7 +2544,7 @@ class WorkOrder extends Api
         }
         $list = \db('设备_报工日志')
             ->where('rq','like','%'.$param['mouth'].'%')
-            ->field('receipt_number as 出库单,order_id as 订单编号,款号,物料名称,rq as 日期,sys_id as 操作机台,recipient as 领料人员')
+            ->field('receipt_number as 出库单,order_id as 订单编号,款号,物料名称,rq as 日期,sys_id as 操作机台,recipient as 领料人员,name as 单号类型')
             ->group('出库单')
             ->order('rq desc')
             ->select();

File diff suppressed because it is too large
+ 601 - 345
application/api/controller/WorkOrderSpotCheck.php


+ 82 - 66
application/api/controller/WorkOrderVerification.php

@@ -27,52 +27,52 @@ class WorkOrderVerification extends Api
      * 获取报工后历史记录
      *
      */
-    public function getTab(){
-        //get请求
-        if(!$this->request->isGet()){
-            $this->error('请求方式错误');
-        }
-        $param = $this->request->param();
-        $where = [
-            '子订单编号' => $param['order_id'],
-            'sczl_jtbh' => $param['sczl_jtbh']
-        ];
-        //通过当前子订单编号和机台查看历史记录数据
-        $table_list = \db('设备_产量计酬')->alias('c')
-            ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.尾包,c.UniqId,c.ci_num,c.s_num,
-                         c.sys_rq, c.serial, y.zdtotal, y.sctotal, j.款式, y.颜色')
-            ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
-            ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
-            ->where('c.子订单编号', $param['order_id'])
-            ->where('c.工序名称', '手工')
-            ->where('c.sczl_jtbh', $param['sczl_jtbh'])
-            ->whereNull('c.mod_rq') // 查询未删除数据
-            ->where(function($query) {
-                $query->whereNotNull('y.ck_rq')->where('y.ck_rq', '<>', '');
-            }) // 查询出库数据
-            ->order('c.UniqId', 'desc')
-            ->distinct('c.子订单编号')
-            ->select();
-        $output = [];
-        foreach ($table_list as $record) {
-            $output[] = [
-                'serial' => '第('.$record['serial'].')包',
-                'sys_rq' => $record['sys_rq'],
-                '订单编号' => $record['订单编号'],
-                '子订单编号' => $record['子订单编号'],
-                '颜色' => $record['颜色'],
-                '尺码' => $record['尺码'],
-                '数量' => $record['数量'],
-                '上报数量' => $record['s_num'],
-                '尾包' => $record['尾包'],
-                '组别' => $record['sczl_jtbh'],
-            ];
-        }
-
-        $this->success('请求成功', [
-            'records' => $output
-        ]);
-    }
+//    public function getTab(){
+//        //get请求
+//        if(!$this->request->isGet()){
+//            $this->error('请求方式错误');
+//        }
+//        $param = $this->request->param();
+//        $where = [
+//            '子订单编号' => $param['order_id'],
+//            'sczl_jtbh' => $param['sczl_jtbh']
+//        ];
+//        //通过当前子订单编号和机台查看历史记录数据
+//        $table_list = \db('设备_产量计酬')->alias('c')
+//            ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.尾包,c.UniqId,c.ci_num,c.s_num,
+//                         c.sys_rq, c.serial, y.zdtotal, y.sctotal, j.款式, y.颜色')
+//            ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
+//            ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
+//            ->where('c.子订单编号', $param['order_id'])
+//            ->where('c.工序名称', '手工')
+//            ->where('c.sczl_jtbh', $param['sczl_jtbh'])
+//            ->whereNull('c.mod_rq') // 查询未删除数据
+//            ->where(function($query) {
+//                $query->whereNotNull('y.ck_rq')->where('y.ck_rq', '<>', '');
+//            }) // 查询出库数据
+//            ->order('c.UniqId', 'desc')
+//            ->distinct('c.子订单编号')
+//            ->select();
+//        $output = [];
+//        foreach ($table_list as $record) {
+//            $output[] = [
+//                'serial' => '第('.$record['serial'].')包',
+//                'sys_rq' => $record['sys_rq'],
+//                '订单编号' => $record['订单编号'],
+//                '子订单编号' => $record['子订单编号'],
+//                '颜色' => $record['颜色'],
+//                '尺码' => $record['尺码'],
+//                '数量' => $record['数量'],
+//                '上报数量' => $record['s_num'],
+//                '尾包' => $record['尾包'],
+//                '组别' => $record['sczl_jtbh'],
+//            ];
+//        }
+//
+//        $this->success('请求成功', [
+//            'records' => $output
+//        ]);
+//    }
 
     /**
      * 记录报工日志历史记录
@@ -160,16 +160,12 @@ class WorkOrderVerification extends Api
         }
 
         $param = $this->request->param();
-        $currentMonth = date('Y-m', strtotime($param['riqi']));  // 获取前端传来的日期所在月份,格式为 Y-m
-        $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month'));  // 获取前端日期的上个月,格式为 Y-m
-
-        // 当前月份的查询条件
-        $where['c.sczl_rq'] = ['like', '%' . $currentMonth . '%'];
 
         // 查询当前订单的生产总数和整单总数
         $totals = db()->table('工单_印件资料')->alias('y')
             ->field('y.订单编号, SUM(y.sctotal) as sctotal, SUM(y.zdtotal) as zdtotal')
             ->group('y.订单编号')
+            ->whereNull('y.Mod_rq')
             ->order('y.订单编号')
             ->select();
 
@@ -182,30 +178,43 @@ class WorkOrderVerification extends Api
             ];
         }
 
-        // 查询上月累计数据
-        $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%'];
+        // 获取上个月的日期,格式为 Y-m
+        $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month'));
+
+        // 构造查询条件
+        $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%'];  // 查询上个月的数据
+        $wheres['sczl_bh'] = ['neq', '']; // 根据需要加上你想要的工序条件(假设 sczl_bh 是工序字段)
+
         $sql = db()->table('设备_产量计酬')
-            ->field('订单编号, SUM(数量) as 上月累计') // 使用SUM函数统计上月累计数量
+            ->field('订单编号, sczl_jtbh, sczl_bh, SUM(数量) as 上月累计')  // 加上工序字段
             ->where($wheres)
-            ->group('订单编号')
+            ->whereNull('mod_rq')  // 确保 mod_rq 字段为空
+            ->group('订单编号, sczl_jtbh, sczl_bh')  // 按 订单编号, sczl_jtbh, sczl_bh 分组
             ->select();
 
-        // 将上个月的累计数据保存到一个数组
+        // 将上个月的累计数据保存到一个数组,确保按订单编号和机台号保存
         $lastMonthMap = [];
         foreach ($sql as $lastRow) {
-            $lastMonthMap[$lastRow['订单编号']] = $lastRow['上月累计'];
+            $lastMonthMap[$lastRow['订单编号']][$lastRow['sczl_jtbh']] = (int)$lastRow['上月累计'];
         }
 
+        $currentMonth = date('Y-m', strtotime($param['riqi']));  // 获取前端传来的日期所在月份,格式为 Y-m
+        $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month'));  // 获取前端日期的上个月,格式为 Y-m
+
+        // 当前月份的查询条件
+        $where['c.sczl_rq'] = ['like', '%' . $currentMonth . '%'];
+
         // 查询每天的上报数量,并关联生产总数和整单总数
         $rows = db()->table('设备_产量计酬')->alias('c')
             ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
             ->field('
-            c.订单编号, j.款式, j.生产款号, j.客户编号, 
-            c.sczl_jtbh, c.工序名称 as 工序,c.sczl_bh,
-            c.数量 as 上报数量,  
-            c.sczl_rq as 上报时间  
-        ')
+        c.订单编号, j.款式, j.生产款号, j.客户编号, 
+        c.sczl_jtbh, c.工序名称 as 工序, c.sczl_bh,
+        c.数量 as 上报数量,  
+        c.sczl_rq as 上报时间  
+    ')
             ->where($where)
+            ->whereNull('c.mod_rq')
             ->order('c.sczl_rq desc')
             ->select();
 
@@ -219,8 +228,8 @@ class WorkOrderVerification extends Api
             $sctotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['sctotal'] : 0;
             $zdtotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['zdtotal'] : 0;
 
-            // 获取上个月的累计数量
-            $lastMonthTotal = isset($lastMonthMap[$row['订单编号']]) ? $lastMonthMap[$row['订单编号']] : 0;
+            // 获取上个月的累计数量,按机台号获取
+            $lastMonthTotal = isset($lastMonthMap[$row['订单编号']][$row['sczl_jtbh']]) ? $lastMonthMap[$row['订单编号']][$row['sczl_jtbh']] : 0;
 
             // 初始化当前订单编号和组别的数据
             if (!isset($result[$key])) {
@@ -234,7 +243,7 @@ class WorkOrderVerification extends Api
                     '组别' => $row['sczl_bh'],
                     '制单数' => $zdtotal,
                     '裁剪数' => $sctotal,
-                    '上月累计数量' => $lastMonthTotal, // 上个月累计数量
+                    '上月累计' => $lastMonthTotal,
                     '上报数量' => 0,
                 ];
 
@@ -265,19 +274,26 @@ class WorkOrderVerification extends Api
                 }
             }
         }
-        //排序
+
+        // 排序
         usort($result, function ($a, $b) {
+            // 先按客户编号排序
             $clientComparison = strcmp($a['客户编号'], $b['客户编号']);
             if ($clientComparison !== 0) {
                 return $clientComparison;
             }
+
+            // 再按组别排序
             $groupComparison = strcmp($a['组别'], $b['组别']);
             if ($groupComparison !== 0) {
                 return $groupComparison;
             }
+
+            // 最后按订单编号排序
             return strcmp($a['订单编号'], $b['订单编号']);
         });
         $result = array_values($result);
+
         $this->success('成功', $result);
     }
 

Some files were not shown because too many files changed in this diff