Przeglądaj źródła

优化大货报表接口

liuhairui 15 godzin temu
rodzic
commit
2d3b6a9bf8

+ 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);
 }
 }

+ 54 - 20
application/api/controller/OrderSuperLoss.php

@@ -161,28 +161,43 @@ class OrderSuperLoss extends Api
 
     //     $this->success('成功', $list);
     // }
+
     /**
      * 根据月份获取工单数据
      */
     public function getWorkOrdersByMonth()
     {
-        // 1. 请求方法校验
         if (!$this->request->isGet()) {
             return $this->error('请求错误');
         }
 
-        // 2. 参数接收与严格校验
+        $params = Request::instance()->param();
         $rq = $this->request->get('rq', '', 'trim');
-        if (empty($rq) || !preg_match('/^\d{4}-\d{2}$/', $rq)) {
-            return $this->error('参数格式错误,请使用 YYYY-MM 格式');
+
+        // 分页参数
+        $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'] . '%');
         }
+        // 通用删除标记条件
+        $where['g.Mod_rq'] = null;
 
-        // 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"));
+        //月份条件非必传
+        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('订单编号')
@@ -194,14 +209,16 @@ class OrderSuperLoss extends Api
                 "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 生产组别'),
+                // 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') // 这里补上!
+            ->whereNull('Mod_rq')
             ->group('order_id')
             ->field([
                 'order_id',
@@ -209,14 +226,21 @@ class OrderSuperLoss extends Api
             ])
             ->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('g.落货日期', '>=', $start)
-            ->where('g.落货日期', '<', $end)
-            ->whereNull('g.Mod_rq')
+            ->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.订单编号',
@@ -230,6 +254,7 @@ class OrderSuperLoss extends Api
                 'g.款式',
                 'g.客户编号 AS 客人编号',
                 'g.辅料计划入库时间',
+                'g.计划生产小组',
                 's.面料入库时间',
                 'p.开裁日期',
                 'p.实裁数量',
@@ -237,6 +262,7 @@ class OrderSuperLoss extends Api
                 'p.车位完成日期',
                 'p.后道完成日期',
                 'p.已完成数量',
+                'p.机台号',
                 'p.生产组别',
                 \think\Db::raw('NULL AS 辅料入库时间'),
                 \think\Db::raw('NULL AS 台产'),
@@ -245,7 +271,7 @@ class OrderSuperLoss extends Api
             ])
             ->select();
 
-
+        // 日期格式化 + 数据类型处理
         $dateFields = [
             '下单日期', '货期', '面料入库时间', '开裁日期',
             '上车位日期', '车位完成日期', '后道完成日期'
@@ -259,11 +285,19 @@ class OrderSuperLoss extends Api
             $item['已完成数量'] = (int)($item['已完成数量'] ?? 0);
             $item['订单数量'] = (int)($item['订单数量'] ?? 0);
             $item['入库数量'] = (int)($item['入库数量'] ?? 0);
-            $item['生产组别'] = $item['生产组别'] ?? '';
+            $item['机台号'] = $item['机台号'] ?? '';
+            $item['实际生产小组'] = $item['生产组别'] ?? '';
         }
 
-        return $this->success('成功', $list);
+        // 返回格式:data + total
+        return $this->success('成功', [
+            'list' => $list,
+            'total' => $total,
+            'page' => $page,
+            'limit' => $limit
+        ]);
     }
 
+
 }