liuhairui 1 жил өмнө
parent
commit
f60bfed8e2

+ 115 - 25
application/api/controller/Manufacture.php

@@ -932,7 +932,7 @@ class Manufacture extends Api
     }
 
     /**
-     * 车缝班组菜单显示
+     * 生产数据菜单显示
      * @return void
      */
     public function MachineList()
@@ -1017,7 +1017,7 @@ class Manufacture extends Api
             $this->error('参数错误');
         }
         $data['审核'] = $param['sys_id'];
-        $data['审核日期'] = date('Y-m-d H:i:s',time());
+        $data['审核日期'] = date('Y-m-d H:i:s');
         $sql = \db('工单_基本资料')
             ->where('Uniqid',$param['Uniqid'])
             ->fetchSql(true)
@@ -1046,11 +1046,13 @@ class Manufacture extends Api
         if (isset($param)){
             $where['订单编号'] = ['like','%'.$param['search'].'%'];
         }
-        $where['审核'] = null;
-        $where['审核日期'] = null;
+//        $where['审核'] = null;
+//        $where['审核日期'] = null;
         $where['Mod_rq'] = null;
         $list = \db('工单_基本资料')
             ->where($where)
+            ->orderRaw("FIELD(gd_statu, '1-计划中', '2-生产中')")  // 自定义状态排序,'1-计划中'排在前
+            ->order('订单编号 desc')  // 按订单编号降序排序
             ->select();
         $this->success('成功',$list);
     }
@@ -1064,13 +1066,15 @@ class Manufacture extends Api
      */
     public function OrderYieldList()
     {
+        // 判断是否是GET请求
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
+
+        // 获取请求参数
         $param = $this->request->param();
-//        if(empty($param)){
-//            $this->error('参数错误');
-//        }
+
+        // 处理搜索条件
         if (isset($param['search'])){
             $where['a.订单编号'] = ['like','%'.$param['search'].'%'];
         }
@@ -1078,41 +1082,52 @@ class Manufacture extends Api
             $where['b.客户编号'] = $param['client'];
         }
 
+        // 只查询生产中的工单
         $where['b.gd_statu'] = '2-生产中';
-//        $time = date('Y-m',strtotime($param['mouth']));
-//        $where['b.Sys_rq'] = ['like',$time.'%'];
+
+        // 查询第一个表,获取产量信息,添加a.sys_rq字段
         $list = \db('设备_产量计酬')
             ->alias('a')
-            ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
-            ->join('工单_印件资料 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
-            ->field('c.订单编号,c.子订单编号,c.款号,c.颜色,c.zdtotal as 制单总数,c.sctotal as 裁切总数,c.ck_rq as 出库日期,
-            SUM(a.数量) as 产量,a.工序名称')
+            ->join('工单_基本资料 b', 'a.订单编号 = b.订单编号')
+            ->join('工单_印件资料 c', 'a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
+            ->field('c.订单编号, c.子订单编号, c.款号, c.颜色, c.zdtotal as 制单总数, c.sctotal as 裁切总数, c.ck_rq as 出库日期, a.sys_rq, 
+                 SUM(a.数量) as 产量, a.工序名称')
             ->where($where)
-            ->whereNotNull('c.sc_rq')
-            ->group('a.订单编号,a.工序名称')
+            ->whereNotNull('c.sc_rq')  // 过滤出生产日期不为空的数据
+            ->group('a.订单编号, a.工序名称')
             ->order('c.Uniqid')
             ->select();
+
+        // 查询第二个表,获取订单的基本信息
         $orderList = \db('工单_印件资料')
             ->alias('a')
-            ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
-            ->field('a.订单编号,a.子订单编号,a.款号,a.颜色,a.zdtotal as 制单总数,a.sctotal as 裁切总数,a.ck_rq as 出库日期')
+            ->join('工单_基本资料 b', 'a.订单编号 = b.订单编号')
+            ->field('a.订单编号, a.子订单编号, a.款号, a.颜色, a.zdtotal as 制单总数, a.sctotal as 裁切总数, a.ck_rq as 出库日期')
             ->where($where)
             ->whereNotNull('a.sc_rq')
             ->group('a.子订单编号')
             ->order('a.Uniqid')
             ->select();
-        $data=[];
-        foreach ($orderList as $key=>$value){
-            $data[$key] = $value;
-            foreach ($list as $k=>$v){
-                if ($value['子订单编号'] === $v['子订单编号']){
-                    if (isset($data[$key][$v['工序名称']]) === false){
+
+        $data = [];
+
+        // 合并两个查询结果
+        foreach ($orderList as $key => $value){
+            $data[$key] = $value; // 先将订单基本信息放入$data
+            foreach ($list as $k => $v){
+                if ($value['子订单编号'] === $v['子订单编号']) {
+                    // 根据工序名称,将对应的产量数据加入到订单信息中
+                    if (!isset($data[$key][$v['工序名称']])){
                         $data[$key][$v['工序名称']] = $v['产量'];
                     }
+                    // 添加sys_rq到结果
+                    $data[$key]['sys_rq'] = $v['sys_rq'];
                 }
             }
         }
-        $this->success('成功',$data);
+
+        // 返回成功的结果,包含合并后的数据
+        $this->success('成功', $data);
     }
 
     /**
@@ -1148,6 +1163,81 @@ class Manufacture extends Api
 //        return $result;
 //    }
 
+    /**车缝派单菜单
+     * @return void
+     */
+    public function CfmachineList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $list = \db('设备_基本资料')
+            ->where('生产工序','车缝')
+            ->column('设备编号');
+        $this->success('成功',$list);
+    }
 
+    /**
+     * 车缝派单列表
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function CfdataList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_排程班次')
+            ->where('班组编号',$param['machine'])
+            ->where('mod_rq',null)
+            ->order('sys_rq desc')
+            ->field('订单编号,子订单编号,班组编号,sys_rq as 创建时间,sys_id as 创建人员,UniqId')
+            ->group('子订单编号')
+            ->select();
+        $this->success('成功',$list);
+    }
+
+    //车缝派单删除
+    public function CfdataDel()
+    {
+        if ($this->request->isGet() === false)
+        {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $sql = \db('工单_排程班次')
+            ->where('UniqId',$param['UniqId'])
+            ->fetchSql(true)
+            ->update(['mod_rq'=>date('Y-m-d H:i:s',time())]);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
 
-}
+    //车缝派单数据
+    public function CfdataAllList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $list = \db('工单_排程班次')
+            ->where('mod_rq',null)
+            ->order('sys_rq desc')
+            ->field('订单编号,子订单编号,班组编号,sys_rq as 创建时间,sys_id as 创建人员,UniqId')
+            ->group('子订单编号')
+            ->select();
+        $this->success('成功',$list);
+    }
+}

+ 188 - 32
application/api/controller/WorkOrder.php

@@ -11,6 +11,9 @@ use think\Config;
 use think\Db;
 use think\Request;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+
 
 /**
  * 工单资料管理
@@ -20,6 +23,22 @@ class WorkOrder extends Api
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
+
+    public function _initialize()
+    {
+
+        if (isset($_SERVER['HTTP_ORIGIN'])) {
+            header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
+        }
+        //跨域检测
+        check_cors_request();
+
+        if (!isset($_COOKIE['PHPSESSID'])) {
+            Config::set('session.id', $this->request->server("HTTP_SID"));
+        }
+        parent::_initialize();
+    }
+
     /**
      * 工单资料菜单列表
      *
@@ -63,7 +82,7 @@ class WorkOrder extends Api
         $total = \db('工单_基本资料')->where($where)->distinct(true)->count();
         $list = \db('工单_基本资料')
             ->where($where)
-            ->order('Gd_statu desc,Sys_rq desc')
+            ->order('订单编号 desc,Gd_statu desc,Sys_rq desc')
             ->limit(($page-1)*$limit,$limit)
             ->select();
         foreach ($list as $key=>$value){
@@ -1132,7 +1151,7 @@ class WorkOrder extends Api
     /**
      * 新增工单->添加工单
      * @ApiMethod (POST)
-     * @param 
+     * @param
      * @return void
      * @throws \think\Exception
      * @throws \think\db\exception\BindParamException
@@ -1144,6 +1163,7 @@ class WorkOrder extends Api
 
     public function WorkOrderAdd()
     {
+//        var_dump(1);exit;
         if (Request::instance()->isPost() === false){
             $this->error('请求错误');
         }
@@ -1151,8 +1171,23 @@ class WorkOrder extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $param['Sys_rq'] = date('Y-m-d',time());
+        $param['Sys_rq'] = date('Y-m-d H:i:s');
         $param['gd_statu'] = '1-计划中';
+
+        $prefix = substr($param['订单编号'], 0, 2);  // e.g., "DC"
+        $maxOrder = \db('工单_基本资料')
+            ->where('订单编号', 'like', "{$prefix}%")
+            ->order('订单编号', 'desc')
+            ->limit(1)
+            ->value('订单编号');
+
+        if ($maxOrder) {
+            $numericPart = substr($maxOrder, 2);
+            $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
+            $param['订单编号'] = $prefix . $newNumericPart;
+        } else {
+            $param['订单编号'] = $param['订单编号'];
+        }
         $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
         $res = \db()->query($sql);
         if ($res !== false){
@@ -1443,7 +1478,7 @@ class WorkOrder extends Api
         }
         $data['型号'] = $arr;
         $data['列表'] = $list;
-         $this->success('成功',$data);
+        $this->success('成功',$data);
     }
 
     /**
@@ -1618,7 +1653,7 @@ class WorkOrder extends Api
 //
 //        $this->success('成功');
 //    }
-    
+
     /**
      * 产品附件修改
      * @ApiMethod (GET)
@@ -1691,7 +1726,7 @@ class WorkOrder extends Api
             '附件内容',
             '附件类型',
             '关联编号'
-            ];
+        ];
         $data = [];
         foreach ($arr as $key => $value){
             if (!isset($req[$value])){
@@ -1700,7 +1735,49 @@ class WorkOrder extends Api
             $data[$value] = $req[$value];
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
-
+        //检测目录是否存在
+        if(is_dir(ROOT_PATH.'public/uploads/'.$req['关联编号']) == null)
+        {
+            mkdir(ROOT_PATH.'public/uploads/'.$req['关联编号'],0777,true);
+        }
+        $base64Data = $req['附件内容'];
+        if (strpos($base64Data, 'base64,') !== false) {
+            $base64Data = explode('base64,', $base64Data)[1]; // 去掉前缀
+        }
+        // 解码 Base64 数据
+        $tempFileContent = base64_decode($base64Data);
+
+        // 创建一个临时文件
+        $tempFile = tempnam(sys_get_temp_dir(), 'excel_') . '.xlsx';
+
+        // 将解码后的内容写入临时文件
+        file_put_contents($tempFile, $tempFileContent);
+
+        // 加载 Excel 文件
+        $spreadsheet =IOFactory::load($tempFile);
+        //储存pdf地址
+        $address = '';
+        // 遍历每个工作表
+        foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
+            // 创建新 Spreadsheet 对象,仅包含当前工作表
+            $pdfSpreadsheet = new Spreadsheet();
+            $pdfSpreadsheet->addExternalSheet($sheet);
+
+            // 设置 PDF 写入器
+            $pdfWriter = new Tcpdf($pdfSpreadsheet);
+
+            // 生成 PDF 文件名
+            $pdfFileName = 'output_sheet_' . ($index + 1) . '.pdf';
+
+            //设置保存地址
+            $pdfOutputPath = ROOT_PATH.'public/uploads/'.$req['关联编号'] . $pdfFileName;
+            // 保存到服务器指定目录
+            $pdfWriter->save($pdfOutputPath);
+            // 编辑pdf地址
+            $address = $pdfOutputPath.',' . $address;
+        }
+        //  清理临时文件
+        unlink($tempFile);;
         //开启事务
         db()->startTrans();
         try{
@@ -1718,7 +1795,7 @@ class WorkOrder extends Api
 
         $this->success('成功');
     }
-    
+
     /**
      * 产品附件修改
      * @ApiMethod (GET)
@@ -2181,13 +2258,13 @@ class WorkOrder extends Api
         $list = \db('工单_基本资料')
             ->where('订单编号',$param['order'])
             ->where($where)
-            ->field('订单编号,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期')
+            ->field('订单编号,生产款号,要求,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,img')
             ->find();
         $xhdata = \db('工单_印件资料')
             ->where('订单编号',$param['order'])
             ->where('船样',0)
             ->where($where)
-            ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
+            ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,款号')
             ->select();
         $arr = [];
         foreach ($xhdata as $key => $value){
@@ -2201,8 +2278,8 @@ class WorkOrder extends Api
         $processlist = \db('工单_印件资料')
             ->where('订单编号',$param['order'])
             ->where($where)
-            ->where('船样',0)
-            ->field('子订单编号,颜色,zdtotal,cm1,cm2,cm3,cm4,cm5,cm6,
+            // ->where('船样',0)
+            ->field('子订单编号,颜色,款号,zdtotal,cm1,cm2,cm3,cm4,cm5,cm6,
             cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
             ->select();
         foreach ($processlist as $key=>$value){
@@ -2271,22 +2348,84 @@ class WorkOrder extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $data = \db('工单_印件资料')
-            ->where('订单编号',$param['order'])
-            ->where('船样',0)
-            ->order('子订单编号 desc')
-            ->find();
-       if(empty($data)){
-           $order = $param['order'].'-01';
-       }else{
-           $num = (int)substr($data['子订单编号'],10) + 1;
-           if ($num<10){
-               $order = $param['order'].'-0'.$num;
-           }else{
-               $order = $param['order'].'-'.$num;
-           }
-       }
-        $this->success('成功',$order);
+
+        if($param['cy'] == '否'){
+            $data = \db('工单_印件资料')
+                ->where('订单编号', $param['order'])
+                ->where('船样', '=', 0)
+                ->order('子订单编号 desc')
+                ->find();
+            if (empty($data)) {
+                $order = $param['order'] . '-01';
+            } else {
+                $num = (int)substr($data['子订单编号'], 10) + 1;
+                if ($num < 10) {
+                    $order = $param['order'] . '-0' . $num;
+                } else {
+                    $order = $param['order'] . '-' . $num;
+                }
+            }
+            $cm_data = [
+                'cm1' => $data['cm1'] ?? '',
+                'cm2' => $data['cm2'] ?? '',
+                'cm3' => $data['cm3'] ?? '',
+                'cm4' => $data['cm4'] ?? '',
+                'cm5' => $data['cm5'] ?? '',
+                'cm6' => $data['cm6'] ?? '',
+                'cm7' => $data['cm7'] ?? '',
+                'cm8' => $data['cm8'] ?? '',
+                'cm9' => $data['cm9'] ?? '',
+                'cm10' => $data['cm10'] ?? ''
+            ];
+
+            $result = [
+                'order' => $order,
+                'cm' => $cm_data
+            ];
+
+            $this->success('成功', $result);
+        }else if ($param['cy'] == '是') {
+
+            // 获取工单信息
+            $data = \db('工单_印件资料')
+                ->where('订单编号', $param['order'])
+                ->where('船样', '=', 1)
+                ->order('子订单编号 asc')
+                ->find();
+            if(empty($data)){
+                $order = $param['order'].'-99';
+            }else{
+                // 提取子订单编号中的数字部分
+                $subOrder = $data['子订单编号'];  // 例如 "DC2410006-99"
+                // 使用正则匹配找到 "-数字" 的部分,并减去 1
+                if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
+                    $numberPart = (int)$matches[1];  // 提取到的数字部分,转换为整数
+                    $newNumber = $numberPart - 1;    // 减 1
+                    // 将新的数字拼接回订单编号
+                    $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
+                } else {
+                    // 如果没有找到子订单中的数字部分,保持原订单编号不变
+                    $order = $subOrder;
+                }
+            }
+            $this->success('成功', $order);
+        }
+//        $data = \db('工单_印件资料')
+//            ->where('订单编号',$param['order'])
+//            ->where('船样',0)
+//            ->order('子订单编号 desc')
+//            ->find();
+//        if(empty($data)){
+//            $order = $param['order'].'-01';
+//        }else{
+//            $num = (int)substr($data['子订单编号'],10) + 1;
+//            if ($num<10){
+//                $order = $param['order'].'-0'.$num;
+//            }else{
+//                $order = $param['order'].'-'.$num;
+//            }
+//        }
+//        $this->success('成功',$order);
     }
 
 
@@ -2339,6 +2478,8 @@ class WorkOrder extends Api
         }
         $id = $param['id'];
         unset($param['id']);
+        $param['updatatime'] = date('Y-m-d H:i:s');
+
         $sql = \db('工单_印件资料')
             ->where('Uniqid',$id)
             ->fetchSql(true)
@@ -2355,18 +2496,33 @@ class WorkOrder extends Api
      * 图片上传
      * @return void
      */
+//    public function ImgUpload(){
+//        $file = request()->file('image');
+//        if($file){
+//            $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
+//            if($info){
+//                $fileName =  $info->getSaveName();
+//                $this->success('成功','public' . DS . 'uploads'. DS . $fileName);
+//            }else{
+//                $res = $file->getError();
+//                $this->error('失败',$res);
+//            }
+//        }
+//    }
     public function ImgUpload(){
         $file = request()->file('image');
         if($file){
             $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
             if($info){
-                $fileName =  $info->getSaveName();
-                $this->success('成功','public' . DS . 'uploads'. DS . $fileName);
+                $fileName = $info->getSaveName();
+                $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
+                return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
             }else{
                 $res = $file->getError();
-                $this->error('失败',$res);
+                return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
             }
         }
+        return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
     }
 
     /**
@@ -2392,4 +2548,4 @@ class WorkOrder extends Api
             ->select();
         $this->success('成功',$list);
     }
-}
+}

+ 319 - 95
application/api/controller/WorkOrderSpotCheck.php

@@ -21,7 +21,7 @@ class WorkOrderSpotCheck extends Api{
 
     /**
      * 报工查询
-     * 通过订单编号列表显示
+     *
      */
     public function getList() {
         // 判断请求是否为 GET 请求
@@ -49,12 +49,13 @@ class WorkOrderSpotCheck extends Api{
                     ->field('y.订单编号, y.子订单编号, y.颜色, y.款号, j.款式, y.ck_rq')
                     ->distinct('y.子订单编号')
                     ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'inner');
-
+                // 判断是查询子订单编号还是订单编号
                 if (strpos($order, '-') !== false) {
                     $query->where('y.子订单编号', $order);
                 } else {
-                    $query->where('y.订单编号', $order);
+                    $query->where('y.订单编号', 'like', '%' . $order . '%');
                 }
+
                 $query->where(function($query) {
                     $query->whereNull('y.Mod_rq')
                         ->whereOr('y.Mod_rq', '');
@@ -95,7 +96,7 @@ class WorkOrderSpotCheck extends Api{
                 // 查询订单编号对应的数据
                 function getOrderData($order) {
                     $query = \db('工单_基本资料')->alias('j')
-                        ->field('y.订单编号,y.子订单编号,y.款号,j.生产款号, j.款式,y.颜色,y.zdtotal,y.sctotal, j.单位, y.Sys_id, y.Sys_rq,y.UniqId')
+                        ->field('y.订单编号,y.子订单编号,y.款号,y.款号, j.款式,y.颜色,y.zdtotal,y.sctotal, j.单位, y.Sys_id, y.Sys_rq,y.UniqId')
                         ->distinct('y.子订单编号')
                         ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
                         ->where(function($query) {
@@ -111,13 +112,13 @@ class WorkOrderSpotCheck extends Api{
                     return $data;
                 }
 
-                // 查询子订单编号对应的数据
-                function getSubOrderData($order) {
+                if (strpos($order, '-') !== false) {
+                    //查询子订单编号 历史记录
                     $query = \db('工单_基本资料')->alias('j')
-                        ->field('y.订单编号, y.子订单编号, y.款号, j.生产款号, j.款式, y.颜色, y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq, y.UniqId,y.sc_rq,
-                 y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,
-                 y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
-                 y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10')
+                        ->field('y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色, y.zdtotal, y.sctotal, j.单位, y.Sys_id, y.Sys_rq, y.UniqId, y.sc_rq,
+                                y.cm1, y.cm2, y.cm3, y.cm4, y.cm5, y.cm6, y.cm7, y.cm8, y.cm9, y.cm10,
+                                y.cmsl1, y.cmsl2, y.cmsl3, y.cmsl4, y.cmsl5, y.cmsl6, y.cmsl7, y.cmsl8, y.cmsl9, y.cmsl10,
+                                y.scsl1, y.scsl2, y.scsl3, y.scsl4, y.scsl5, y.scsl6, y.scsl7, y.scsl8, y.scsl9, y.scsl10')
                         ->distinct('y.子订单编号')
                         ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号', 'left')
                         ->where(function($query) {
@@ -131,26 +132,56 @@ class WorkOrderSpotCheck extends Api{
                         ->where('y.子订单编号', '=', $order);
 
                     $data = $query->select();
+
                     // 构建主要数据 (data) 和列表数据 (list)
                     $dataEntry = [];
                     $list = [];
+                    $headers = [];  // 存放尺码表头
 
                     foreach ($data as $item) {
-                        // 主要数据部分,变成数组格式
-                        $dataEntry[] = [
-                            '订单编号' => $item['订单编号'],
+                        // 初始化尺码与数量映射数组
+                        $cmScslMapping = [];
+
+                        for ($i = 1; $i <= 10; $i++) {
+                            // 获取尺码 (cm) 和对应的生产数量 (scsl)
+                            $cmValue = $item['cm' . $i];
+                            $scslValue = $item['scsl' . $i];
+
+                            // 仅当 cm 有效时,才映射生产数量
+                            if (!is_null($cmValue) && $cmValue !== 0) {
+                                // 将 scsl 值加入到 cm 键下,默认当数量为0或者null时用空字符串代替
+                                $cmScslMapping[$cmValue] = ($scslValue === 0 || is_null($scslValue)) ? '' : $scslValue;
+
+                                // 将尺码加入 headers 数组中(去重)
+                                if (!in_array($cmValue, $headers)) {
+                                    $headers[] = $cmValue;
+                                }
+                            }
+                        }
+
+                        // 将尺码数据平铺到主要数据中(表格数据)
+                        $orderData = [
+                            '订单编号'   => $item['订单编号'],
                             '子订单编号' => $item['子订单编号'],
-                            '生产款号' => $item['生产款号'],
-                            '款式' => $item['款式'],
-                            '颜色' => $item['颜色'],
-                            'zdtotal' => $item['zdtotal'],
-                            'sctotal' => $item['sctotal'],
-                            '单位' => $item['单位'],
-                            'Sys_id' => $item['Sys_id'],
-                            'Sys_rq' => $item['sc_rq'],
+                            '款号'   => $item['款号'],
+                            '款式'       => $item['款式'],
+                            '颜色'       => $item['颜色'],
+                            'zdtotal'    => $item['zdtotal'],
+                            'sctotal'    => $item['sctotal'],
+                            '单位'       => $item['单位'],
+                            'Sys_id'     => $item['Sys_id'],
+                            'Sys_rq'     => $item['Sys_rq'],
                         ];
 
-                        // 列表部分
+                        // 将尺码映射数据平铺到 $orderData
+                        foreach ($cmScslMapping as $cm => $scsl) {
+                            $orderData[$cm] = $scsl;
+                        }
+
+                        // 将完整的订单数据加入 $dataEntry
+                        $dataEntry[] = $orderData;
+
+                        // list 列表部分
                         $entry = [];
                         for ($i = 1; $i <= 10; $i++) {
                             $entry['cm' . $i] = ($item['cm' . $i] === 0 || is_null($item['cm' . $i])) ? '' : $item['cm' . $i];
@@ -161,31 +192,23 @@ class WorkOrderSpotCheck extends Api{
                         $entry['子订单编号'] = $item['子订单编号'];
                         $entry['UniqId'] = $item['UniqId'];
                         $entry['zdtotal'] = $item['zdtotal'];
+                        $entry['颜色'] = $item['颜色'];
+                        $entry['款式'] = $item['款式'];
+                        $entry['款号'] = $item['款号'];
                         $list[] = $entry;
                     }
-
-                    return ['data' => $dataEntry, 'list' => $list];
-                }
-
-                if (strpos($order, '-') !== false) {
-                    $resultData = getSubOrderData($order);
-
-                    $result = [
-                        'data' => $resultData['data'], // data 是数组格式
-                        'list' => $resultData['list'],
-                        'total' => count($resultData['list']),
-                    ];
-                } else {
+                    $result = ['table' => $dataEntry, 'list' => $list, 'headers' => $headers];
+                }else {
                     // 查询订单编号对应的数据
                     $data = getOrderData($order);
                     $result = [
-                        'data' => $data,
+                        'table' => $data,
                         'list' => '',
                         'total' => count($data),
                     ];
                 }
                 $this->success('请求成功', $result);
-              break;
+                break;
             case '车缝':
                 // 查询流水号
                 function getSerial($order) {
@@ -339,6 +362,7 @@ class WorkOrderSpotCheck extends Api{
                     }
                     $sizeData = getSizeSummary($order);
                     $serial = getSerial($order);
+
                     $this->success('请求成功', [
                         'serial' => $serial['serial'], // 流水号
                         'serial_num' => $serial['serial_num'], // 序号
@@ -365,30 +389,47 @@ class WorkOrderSpotCheck extends Api{
                 }
                 break;
             case '后道':
-                // 验证sys_sbID参数是否存在且非空
+                //判断是否为子订单
                 if (strpos($order, ',') !== false) {
                     if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
-                        $this->error('sys_sbID 参数错误');
+                        $this->error('未获取到机台号');
                     }
-
+                    // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
                     $paramArray = explode(',', $order);
 
-                    //获取车缝生成小票的UniqId
-                    $Uniqid = \db('设备_产量计酬')->field('UniqId')
+                    // 获取车缝生成小票的 UniqId 和 订单编号
+                    $Uniqid = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
-                            '数量' => $paramArray[4]
-                        ])->find();
+                            '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
+                        ])
+                        ->find();
+
+                    // 判断是否成功获取到数据
+                    if ($Uniqid) {
+                        $orderlist = \db('工单_基本资料')
+                            ->where('订单编号', $Uniqid['订单编号'])
+                            ->field('订单编号, 生产款号, 款式')
+                            ->find();
+                        $yinjianlist = \db('工单_印件资料')
+                            ->where('订单编号', $orderlist['订单编号'])
+                            ->field('zdtotal, sctotal,颜色')
+                            ->find();
+                    } else {
+                        echo "未找到对应的 UniqId 和订单编号";
+                    }
 
                     $res = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
                             '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
                             'sczl_jtbh' => $params['sys_sbID'],
                         ])
-                        ->order('sys_rq desc') // 按时间倒序排列,确保最新的记录在最前
+                        ->order('sys_rq desc')//确保最新的记录在最前
                         ->select();
 
                     if (empty($res)) {
@@ -414,15 +455,21 @@ class WorkOrderSpotCheck extends Api{
                         'sys_sbID' => $params['sys_sbID'],//设备编号
                         'ci_num' => $ci_num,//剩余数量
                         'UniqId' => $Uniqid['UniqId'],
-                        'order' => $paramArray[0],//订单编号
+                        'order' => $paramArray[0],//订单编号
                         'zb' => $params['sys_sbID'],//组别
                         'gx' => 4,//默认固定工序
                         'cm' => $paramArray[3],//尺码
                         'sl' => $paramArray[4],//数量
-                        'wb' => $paramArray[5]//尾包
+                        'wb' => $paramArray[5],//尾包
+                        '订单编号' => $orderlist['订单编号'],
+                        '生产款号' => $orderlist['生产款号'],
+                        '款式' => $orderlist['款式'],
+                        'sctotal' => $yinjianlist['sctotal'],
+                        'zdtotal' => $yinjianlist['zdtotal'],
+                        '颜色' => $yinjianlist['颜色'],
                     ];
 
-                    // 查询历史记录,按 sys_rq 时间倒序排序
+                    // 查询历史记录
                     $existingRecords = \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.颜色')
@@ -486,7 +533,63 @@ class WorkOrderSpotCheck extends Api{
                         'records' => $sizeSummary // 返回记录
                     ]);
                 } else {
-                    $this->success('请扫描子订单编号', ['result' => '', 'records' => []]);
+
+                    // 查询数据
+                    $res = \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.订单编号', 'like', '%' . $order . '%') // 模糊查询订单编号
+                        ->where('c.sczl_jtbh', $params['sys_sbID']) // 精确匹配设备编号
+                        ->order('c.sys_rq desc') // 按时间倒序排列
+                        ->select();
+
+                    // 初始化返回数据的结构
+                    $reslist = [];
+                    $sizes = [];
+
+                    // 遍历查询结果,构造需要的结构化数据
+                    foreach ($res as $record) {
+                        $size = $record['尺码']; // 记录的尺码
+                        $quantity = $record['数量']; // 每个记录的数量
+                        $serial = $record['serial']; // 记录的serial
+
+                        // 记录所有不同的尺码,避免重复
+                        if (!in_array($size, $sizes)) {
+                            $sizes[] = $size;
+                        }
+
+                        // 构造每条记录的详细信息
+                        $reslist[] = [
+                            'UniqId' => $record['UniqId'],
+                            '订单编号' => $record['订单编号'],
+                            '子订单编号' => $record['子订单编号'],
+                            '上报数量' => $record['s_num'],
+                            '次品数量' => $record['数量'] - $record['ci_num'],
+                            '生产款号' => $record['款号'],
+                            '尺码' => $record['尺码'],
+                            '工序编号' => $record['工序编号'],
+                            '工序名称' => $record['工序名称'],
+                            '数量' => $quantity, // 每条记录的数量
+                            '尾包' => $record['尾包'] == 1 ? '是' : '否', // 尾包为1表示"是",否则"否"
+                            '颜色' => $record['颜色'],
+                            '组别' => $record['sczl_jtbh'],
+                            'serial' => $serial,
+                            'sys_rq' => $record['sys_rq'], // 上报日期
+                        ];
+                    }
+
+                    // 按 sys_rq (时间) 或 UniqId 排序(按实际需求选)
+                    usort($reslist, function ($a, $b) {
+                        return strtotime($b['sys_rq']) - strtotime($a['sys_rq']);
+                    });
+
+                    // 返回结构化的查询结果
+                    $this->success('请求成功', [
+                        'result' => $res, // 原始查询结果
+                        'headers' => $sizes, // 尺码表头
+                        'records' => $reslist // 处理后的记录列表
+                    ]);
                 }
                 break;
             case '大烫':
@@ -494,24 +597,42 @@ class WorkOrderSpotCheck extends Api{
                     if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
                         $this->error('sys_sbID 参数错误');
                     }
-
+                    //将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
                     $paramArray = explode(',', $order);
-                    //获取车缝生成小票的UniqId
-                    $Uniqid = \db('设备_产量计酬')->field('UniqId')
+
+                    // 获取车缝生成小票的 UniqId 和 订单编号
+                    $Uniqid = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
-                            '数量' => $paramArray[4]
-                        ])->find();
+                            '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
+                        ])
+                        ->find();
+
+                    // 判断是否成功获取到数据
+                    if ($Uniqid) {
+                        $orderlist = \db('工单_基本资料')
+                            ->where('订单编号', $Uniqid['订单编号'])
+                            ->field('订单编号, 生产款号, 款式')
+                            ->find();
+                        $yinjianlist = \db('工单_印件资料')
+                            ->where('订单编号', $orderlist['订单编号'])
+                            ->field('zdtotal, sctotal,颜色')
+                            ->find();
+                    } else {
+                        echo "未找到对应的 UniqId 和订单编号";
+                    }
 
                     $res = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
                             '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
                             'sczl_jtbh' => $params['sys_sbID'],
                         ])
-                        ->order('sys_rq desc') // 按时间倒序排列,确保最新的记录在最前
+                        ->order('sys_rq desc')//确保最新的记录在最前
                         ->select();
 
                     if (empty($res)) {
@@ -542,7 +663,11 @@ class WorkOrderSpotCheck extends Api{
                         'gx' => 4,//默认固定工序
                         'cm' => $paramArray[3],//尺码
                         'sl' => $paramArray[4],//数量
-                        'wb' => $paramArray[5]//尾包
+                        'wb' => $paramArray[5],
+                        '订单编号' => $orderlist['订单编号'],
+                        '生产款号' => $orderlist['生产款号'],
+                        '款式' => $orderlist['款式'],
+                        '颜色' => $orderlist['颜色'],
                     ];
 
                     // 查询历史记录,按 sys_rq 时间倒序排序
@@ -609,7 +734,22 @@ class WorkOrderSpotCheck extends Api{
                         'records' => $sizeSummary // 返回记录
                     ]);
                 } else {
-                    $this->success('请扫描子订单编号', ['result' => '', 'records' => []]);
+                    // 模糊查询 查询历史记录
+                    $res = \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.颜色 as 色系名称')
+                        ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
+                        ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
+                        ->where('c.订单编号', 'like', '%' . $order . '%') // 使用模糊查询
+                        ->where('c.sczl_jtbh', $params['sys_sbID']) // 精确匹配sczl_jtbh
+                        ->order('c.sys_rq desc') // 按时间倒序排列
+                        ->select();
+
+                    $this->success('请求成功', [
+                        'result' => '',
+                        'headers' => '', // 尺码表头
+                        'records' => $res // 返回记录
+                    ]);
                 }
                 // 添加大烫逻辑
                 break;
@@ -618,24 +758,42 @@ class WorkOrderSpotCheck extends Api{
                     if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
                         $this->error('sys_sbID 参数错误');
                     }
-
+                    // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
                     $paramArray = explode(',', $order);
-                    //获取车缝生成小票的UniqId
-                    $Uniqid = \db('设备_产量计酬')->field('UniqId')
+
+                    // 获取车缝生成小票的 UniqId 和 订单编号
+                    $Uniqid = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
-                            '数量' => $paramArray[4]
-                        ])->find();
+                            '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
+                        ])
+                        ->find();
+
+                    // 判断是否成功获取到数据
+                    if ($Uniqid) {
+                        $orderlist = \db('工单_基本资料')
+                            ->where('订单编号', $Uniqid['订单编号'])
+                            ->field('订单编号, 生产款号, 款式')
+                            ->find();
+                        $yinjianlist = \db('工单_印件资料')
+                            ->where('订单编号', $orderlist['订单编号'])
+                            ->field('zdtotal, sctotal,颜色')
+                            ->find();
+                    } else {
+                        echo "未找到对应的 UniqId 和订单编号";
+                    }
 
                     $res = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
                             '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
                             'sczl_jtbh' => $params['sys_sbID'],
                         ])
-                        ->order('sys_rq desc') // 按时间倒序排列,确保最新的记录在最前
+                        ->order('sys_rq desc')//确保最新的记录在最前
                         ->select();
 
                     if (empty($res)) {
@@ -666,7 +824,11 @@ class WorkOrderSpotCheck extends Api{
                         'gx' => 4,//默认固定工序
                         'cm' => $paramArray[3],//尺码
                         'sl' => $paramArray[4],//数量
-                        'wb' => $paramArray[5]//尾包
+                        'wb' => $paramArray[5],
+                        '订单编号' => $orderlist['订单编号'],
+                        '生产款号' => $orderlist['生产款号'],
+                        '款式' => $orderlist['款式'],
+                        '颜色' => $orderlist['颜色'],
                     ];
 
                     // 查询历史记录,按 sys_rq 时间倒序排序
@@ -733,7 +895,22 @@ class WorkOrderSpotCheck extends Api{
                         'records' => $sizeSummary // 返回记录
                     ]);
                 } else {
-                    $this->success('请扫描子订单编号', ['result' => '', 'records' => []]);
+                    // 模糊查询 查询历史记录
+                    $res = \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.颜色 as 色系名称')
+                        ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
+                        ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
+                        ->where('c.订单编号', 'like', '%' . $order . '%') // 使用模糊查询
+                        ->where('c.sczl_jtbh', $params['sys_sbID']) // 精确匹配sczl_jtbh
+                        ->order('c.sys_rq desc') // 按时间倒序排列
+                        ->select();
+
+                    $this->success('请求成功', [
+                        'result' => '',
+                        'headers' => '', // 尺码表头
+                        'records' => $res // 返回记录
+                    ]);
                 }
                 break;
             case '包装':
@@ -741,24 +918,42 @@ class WorkOrderSpotCheck extends Api{
                     if (!isset($params['sys_sbID']) || empty($params['sys_sbID'])) {
                         $this->error('sys_sbID 参数错误');
                     }
-
+                    // 将子订单编号, 机台号, 工序, 尺码, 数量, 尾包, 流水号(包)分割为数组
                     $paramArray = explode(',', $order);
-                    //获取车缝生成小票的UniqId
-                    $Uniqid = \db('设备_产量计酬')->field('UniqId')
+
+                    // 获取车缝生成小票的 UniqId 和 订单编号
+                    $Uniqid = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
-                            '数量' => $paramArray[4]
-                        ])->find();
+                            '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
+                        ])
+                        ->find();
+
+                    // 判断是否成功获取到数据
+                    if ($Uniqid) {
+                        $orderlist = \db('工单_基本资料')
+                            ->where('订单编号', $Uniqid['订单编号'])
+                            ->field('订单编号, 生产款号, 款式')
+                            ->find();
+                        $yinjianlist = \db('工单_印件资料')
+                            ->where('订单编号', $orderlist['订单编号'])
+                            ->field('zdtotal, sctotal')
+                            ->find();
+                    } else {
+                        echo "未找到对应的 UniqId 和订单编号";
+                    }
 
                     $res = \db('设备_产量计酬')
                         ->where([
                             '子订单编号' => $paramArray[0],
                             '尺码' => $paramArray[3],
                             '数量' => $paramArray[4],
+                            'serial' => $paramArray[6],
                             'sczl_jtbh' => $params['sys_sbID'],
                         ])
-                        ->order('sys_rq desc') // 按时间倒序排列,确保最新的记录在最前
+                        ->order('sys_rq desc')//确保最新的记录在最前
                         ->select();
 
                     if (empty($res)) {
@@ -789,7 +984,10 @@ class WorkOrderSpotCheck extends Api{
                         'gx' => 4,//默认固定工序
                         'cm' => $paramArray[3],//尺码
                         'sl' => $paramArray[4],//数量
-                        'wb' => $paramArray[5]//尾包
+                        'wb' => $paramArray[5],
+                        '订单编号' => $orderlist['订单编号'],
+                        '生产款号' => $orderlist['生产款号'],
+                        '款式' => $orderlist['款式'],
                     ];
 
                     // 查询历史记录,按 sys_rq 时间倒序排序
@@ -856,7 +1054,22 @@ class WorkOrderSpotCheck extends Api{
                         'records' => $sizeSummary // 返回记录
                     ]);
                 } else {
-                    $this->success('请扫描子订单编号', ['result' => '', 'records' => []]);
+                    // 模糊查询 查询历史记录
+                    $res = \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.颜色 as 色系名称')
+                        ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left')
+                        ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
+                        ->where('c.订单编号', 'like', '%' . $order . '%') // 使用模糊查询
+                        ->where('c.sczl_jtbh', $params['sys_sbID']) // 精确匹配sczl_jtbh
+                        ->order('c.sys_rq desc') // 按时间倒序排列
+                        ->select();
+
+                    $this->success('请求成功', [
+                        'result' => '',
+                        'headers' => '', // 尺码表头
+                        'records' => $res // 返回记录
+                    ]);
                 }
                 break;
             default:
@@ -870,7 +1083,7 @@ class WorkOrderSpotCheck extends Api{
 
 
     /**
-     * 出库报工
+     * 出库报工日志
      * 确认出库 恢复出库状态
      */
     public function getTab() {
@@ -993,26 +1206,36 @@ class WorkOrderSpotCheck extends Api{
         function setIfNotEmpty($value) {
             return (!empty($value) && $value != 0) ? $value : '';
         }
-        $updateData = [
-            'sc_rq' => date('Y-m-d H:i:s'),
-            'scsl1' => setIfNotEmpty($params['scsl1']),
-            'scsl2' => setIfNotEmpty($params['scsl2']),
-            'scsl3' => setIfNotEmpty($params['scsl3']),
-            'scsl4' => setIfNotEmpty($params['scsl4']),
-            'scsl5' => setIfNotEmpty($params['scsl5']),
-            'scsl6' => setIfNotEmpty($params['scsl6']),
-            'scsl7' => setIfNotEmpty($params['scsl7']),
-            'scsl8' => setIfNotEmpty($params['scsl8']),
-            'scsl9' => setIfNotEmpty($params['scsl9']),
-            'scsl10' => setIfNotEmpty($params['scsl10']),
-            'sctotal' => setIfNotEmpty($params['sctotal']),
-            // 添加其他要更新的字段
-        ];
-        // 更新数据库
-        $updateCount = \db('工单_印件资料')
+        // 先查询当前记录的原始数据
+        $existingData = \db('工单_印件资料')
             ->where('子订单编号', $params['order_id'])
-            ->where('UniqId', $params['UniqId'])
-            ->update($updateData);
+            ->find();
+
+        if ($existingData) {
+            // 计算新的累加值
+            $updateData = [
+                'sc_rq' => date('Y-m-d H:i:s'),
+                'scsl1' => isset($params['scsl1']) && is_numeric($params['scsl1']) ? $existingData['scsl1'] + $params['scsl1'] : $existingData['scsl1'] + 0,
+                'scsl2' => isset($params['scsl2']) && is_numeric($params['scsl2']) ? $existingData['scsl2'] + $params['scsl2'] : $existingData['scsl2'] + 0,
+                'scsl3' => isset($params['scsl3']) && is_numeric($params['scsl3']) ? $existingData['scsl3'] + $params['scsl3'] : $existingData['scsl3'] + 0,
+                'scsl4' => isset($params['scsl4']) && is_numeric($params['scsl4']) ? $existingData['scsl4'] + $params['scsl4'] : $existingData['scsl4'] + 0,
+                'scsl5' => isset($params['scsl5']) && is_numeric($params['scsl5']) ? $existingData['scsl5'] + $params['scsl5'] : $existingData['scsl5'] + 0,
+                'scsl6' => isset($params['scsl6']) && is_numeric($params['scsl6']) ? $existingData['scsl6'] + $params['scsl6'] : $existingData['scsl6'] + 0,
+                'scsl7' => isset($params['scsl7']) && is_numeric($params['scsl7']) ? $existingData['scsl7'] + $params['scsl7'] : $existingData['scsl7'] + 0,
+                'scsl8' => isset($params['scsl8']) && is_numeric($params['scsl8']) ? $existingData['scsl8'] + $params['scsl8'] : $existingData['scsl8'] + 0,
+                'scsl9' => isset($params['scsl9']) && is_numeric($params['scsl9']) ? $existingData['scsl9'] + $params['scsl9'] : $existingData['scsl9'] + 0,
+                'scsl10' => isset($params['scsl10']) && is_numeric($params['scsl10']) ? $existingData['scsl10'] + $params['scsl10'] : $existingData['scsl10'] + 0,
+                'sctotal' => isset($params['sctotal']) && is_numeric($params['sctotal']) ? $existingData['sctotal'] + $params['sctotal'] : $existingData['sctotal'] + 0,
+                // 你可以在这里继续添加其他字段
+            ];
+
+            $updateCount = \db('工单_印件资料')
+                ->where('子订单编号', $params['order_id'])
+                ->where('UniqId', $params['UniqId'])
+                ->update($updateData);
+        } else {
+            echo "没有找到相关记录";
+        }
         // 检查更新结果
         if ($updateCount > 0) {
             $this->success("更新成功");
@@ -1160,8 +1383,9 @@ class WorkOrderSpotCheck extends Api{
         if (empty($params['sys_sbID'])){$this->error('物理地址参数不能为空');}
 
         $data = \db('设备_基本资料')->where('sys_sbID', $params['sys_sbID'])
-            ->field('设备编号 as 机台号,生产工序,工序,rtrim(设备编组) as 组别,组长')
-            ->where('生产工序',$params['code'])->find();
+            ->field('设备编号 as 机台号,生产工序,工序,rtrim(设备编组) as 组别,组长,sys_sbID')
+//            ->where('生产工序',$params['code'])
+            ->find();
         $this->success('请求成功', $data);
     }
 

+ 258 - 266
application/api/controller/WorkOrderVerification.php

@@ -74,110 +74,98 @@ class WorkOrderVerification extends Api
     }
 
     /**
-     * 获取工单核验单侧边栏通过工单编号
-     * @ApiMethod (GET)
+     * 记录报工日志历史记录
      */
     public function getTabByGdbh()
     {
-        //get请求
-        if(!$this->request->isGet()){
-            $this->error('请求方式错误');
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
         }
-        $date = date('Y-m-d',strtotime("-1 year"));
 
-        $rows = db()->table('db_qczl')->alias('d')
-            ->field('d.qczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc')
-            ->join('工单_基本资料 y','y.Gd_gdbh = d.qczl_gdbh','left')
-            ->where('d.sys_rq','>=',$date)
-            ->group('d.qczl_gdbh')
-            ->order('d.qczl_gdbh desc')
-            ->limit(65)
-            ->select();
-        $arr = db()->table('db_qczl')
-            ->field('qczl_gdbh, rtrim(sys_id) as sys_id, COUNT(*) as count')
-            ->where('qczl_gdbh','>=',$rows[count($rows)-1]['qczl_gdbh'])
-            ->group('qczl_gdbh, sys_id')
-            ->select();
-        foreach($rows as $key=>$value){
-            $rows[$key]['sys'] = [];
-            foreach($arr as $k=>$v){
-                if($value['qczl_gdbh'] == $v['qczl_gdbh']){
-                    unset($v['qczl_gdbh']);
-                    array_push($rows[$key]['sys'],$v);
-                    unset($arr[$k]);
-                }
-            }
+        $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('失败');
         }
 
-        $this->success('成功',$rows);
     }
 
     /**
-     * 获取工单核验单列表
+     * 获取报工日志
      * @ApiMethod (GET)
-     * @param string $date 时间
-     * @param string $sys_id 用户
      */
     public function getList()
     {
-        //get请求
+        // 检查是否为 GET 请求
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
-        $req = $this->request->param();
 
-        $page = 1;
-        $limit = 15;
-        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
-        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
-
-        $where = [];
-        if (isset($req['date']) && !empty($req['date'])){
-            $where['sys_rq'] = ['LIKE',$req['date'].'%'];
-        }
-        if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
-        if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
-        if (isset($req['cpmc']) && !empty($req['cpmc'])){
-            //查询工单表
-            $gd = db('工单_基本资料')
-                ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
-                ->column('Gd_gdbh');
-            $where['qczl_gdbh'] = ['in', $gd];
-        }
-        $rows = db()->table('db_qczl')
-            ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp, 
-            fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17, 
-            fp_sl1, fp_sl2, fp_sl3, fp_sl4, fp_sl5, fp_sl6, fp_sl7, fp_sl8, fp_sl9, fp_sl10, fp_sl11, fp_sl12, fp_sl13, fp_sl14, fp_sl15, fp_sl16, fp_sl17, 
-            rtrim(sys_id) as sys_id,UniqId')
-            ->where($where)
-            ->order('UniqId desc')
-            ->page($page,$limit)
-            ->select();
+        // 获取请求参数
+        $param = $this->request->param();
+
+        // 判断订单编号是否包含 '-'
+        if (strpos($param['order'], '-') !== false) {
+            // 如果订单包含 '-',则按子订单编号精确匹配
+            $where['子订单编号'] = $param['order'];
+        } else {
+            // 如果订单不包含 '-',则按订单编号进行模糊匹配
+            $where['订单编号'] = ['like', '%' . $param['order'] . '%'];
+        }
 
-        $total = db()->table('db_qczl')->where($where)->count();
-        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        // 过滤条件中的 code
+        $where['code'] = $param['code'];
 
-        foreach ($rows as $key=>$value){
-            $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
+        // 查询数据库
+        $rows = db()->table('设备_报工记录')
+            ->where($where)
+            ->order('子订单编号 desc')
+            ->select();
 
-            for ($i=1;$i<=17;$i++){
-                if ($value['fp_sl'.$i]==0){
-                    $rows[$key]['sl_lb'.$i] = '';
-                }else{
-                    $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
+        // 提取 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];
+                    }
                 }
-                unset($rows[$key]['fp_sl'.$i]);
-                unset($rows[$key]['fp_lb'.$i]);
             }
+
+            // 去重,避免重复值
+            $headers = array_unique($headers);
+
+            // 按照数值升序排序
+            sort($headers);
         }
 
+
+        // 构建返回的数据结构
         $data = [
-            'total'          => $total,
-            'rows'          => $rows,
+            'table'   => $rows,
+            'headers' => $headers,
+            'total'   => count($rows),
         ];
-        $this->success('成功',$data);
+
+        // 返回成功响应
+        $this->success('成功', $data);
     }
 
+
     /**
      * 获取工单核验单信息
      * @ApiMethod (GET)
@@ -206,103 +194,210 @@ class WorkOrderVerification extends Api
         $this->success('成功',$rows);
     }
     /**
-     * 获取单个工单核检单信息
-     * @ApiMethod GET
+     * 生产产量进度月报表(Excel)
      * @params string UniqId
      */
-    public function getOneWorkOrder(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
+    public function getOneWorkOrder() {
+        // 确认请求为 GET 请求
+        if (!$this->request->isGet()) {
+            $this->error('请求方式错误');
         }
-        $params = Request::instance()->param();
-        if (!isset($params['UniqId']) || empty($params['UniqId'])){
-            $this->error('参数错误');
+
+        // 获取请求参数
+        $param = $this->request->param();
+
+        // 获取当前月份和上个月的月份
+        $currentMonth = date('Y-m', strtotime($param['riqi']));  // 当前月份
+        $previousMonth = date('Y-m', strtotime('-1 month', strtotime($param['riqi'])));  // 上个月
+
+        // 查询当前月份的数据
+        $where['上报时间'] = ['like', $currentMonth . '%'];
+        $rows = db()->table('设备_报工记录')
+            ->field('款式,款号,订单编号,组别,客户编号,code as 工序,上报数量,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间')
+            ->where($where)
+            ->select();
+
+        // 查询上个月的数据
+        $wherePrevious['上报时间'] = ['like', $previousMonth . '%'];
+        $rowsPrevious = db()->table('设备_报工记录')
+            ->field('款式,款号,订单编号,组别,客户编号,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间')
+            ->where($wherePrevious)
+            ->select();
+
+        // 初始化结果数组
+        $result = [];
+
+        // 处理当前月份的数据
+        foreach ($rows as $row) {
+            // 使用“款式”、“款号”、“订单编号”、“组别”作为唯一标识
+            $key = $row['款式'] . '_' . $row['款号'] . '_' . $row['订单编号'] . '_' . $row['组别'];
+
+            // 如果结果集中不存在该条目,则初始化
+            if (!isset($result[$key])) {
+                $result[$key] = [
+                    '款式' => $row['款式'],
+                    '款号' => $row['款号'],
+                    '订单编号' => $row['订单编号'],
+                    '组别' => $row['组别'],
+                    '客户编号' => $row['客户编号'],
+                    '工序' => $row['工序'],
+                    '裁剪数' => $row['裁剪数'] ?? 0,
+                    '制单数' => $row['制单数'] ?? 0,
+                    '上报数量' => 0,  // 初始化上报数量累计
+                ];
+
+                // 初始化每日数据
+                for ($day = 1; $day <= 31; $day++) {
+                    $result[$key][$day . '号'] = 0;
+                }
+            }
+
+            // 按天累计每日数据
+            $day = (int)date('d', strtotime($row['上报时间']));
+
+            // 检查 scsl1 到 scsl10 是否都是空
+            $allScslEmpty = true;
+            for ($i = 1; $i <= 10; $i++) {
+                $keyScsl = 'scsl' . $i;
+                if (!empty($row[$keyScsl])) {
+                    $allScslEmpty = false;
+                    break;
+                }
+            }
+
+            // 如果 scsl1-scsl10 全部为空,则累加上报数量
+            if ($allScslEmpty) {
+                $result[$key][$day . '号'] += (int)$row['上报数量'];
+            } else {
+                // 如果有 scsl1-scsl10 的数据,则按原来的逻辑累加
+                for ($i = 1; $i <= 10; $i++) {
+                    $keyScsl = 'scsl' . $i;
+                    $result[$key][$day . '号'] += !empty($row[$keyScsl]) ? (int)$row[$keyScsl] : 0;
+                }
+            }
+
+            // 累计“上报数量”(非裁剪和制单)
+            $result[$key]['上报数量'] += (int)$row['上报数量'];
         }
-        $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
-        qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
-        fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,trim(fp_lb14) as fp_lb14,trim(fp_lb15) as fp_lb15,trim(fp_lb16) as fp_lb16,trim(fp_lb17) as fp_lb17,
-        fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,fp_sl14,fp_sl15,fp_sl16,fp_sl17,
-        fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
-        fp_bz1,fp_bz2,fp_bz3,fp_bz4,fp_bz5,fp_bz6,fp_bz7,fp_bz8,fp_bz9,fp_bz10,fp_bz11,fp_bz12,fp_bz13,
-        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13,
-        sys_id,rtrim(sys_rq) as sys_rq,UniqId';
-        $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
-        $list['fp_name1'] = '';
-        if (!empty($list['fp_bh1'])){
-            $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name2'] = '';
-        if (!empty($list['fp_bh2'])){
-            $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name3'] = '';
-        if (!empty($list['fp_bh3'])){
-            $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name4'] = '';
-        if (!empty($list['fp_bh4'])){
-            $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name5'] = '';
-        if (!empty($list['fp_bh5'])){
-            $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name6'] = '';
-        if (!empty($list['fp_bh6'])){
-            $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name7'] = '';
-        if (!empty($list['fp_bh7'])){
-            $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name8'] = '';
-        if (!empty($list['fp_bh8'])){
-            $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name9'] = '';
-        if (!empty($list['fp_bh9'])){
-            $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name10'] = '';
-        if (!empty($list['fp_bh10'])){
-            $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name11'] = '';
-        if (!empty($list['fp_bh11'])){
-            $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name12'] = '';
-        if (!empty($list['fp_bh12'])){
-            $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
-        }
-        $list['fp_name13'] = '';
-        if (!empty($list['fp_bh13'])){
-            $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
-        }
-        $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
-        $list['total_liucheng'] = $max['sczl_num'];
-        $this->success('请求成功',$list);
+
+        // 计算本月累计数据
+        foreach ($result as &$item) {
+            $item['本月累计'] = 0;  // 初始化本月累计
+            $item['上个月累计'] = 0;  // 初始化上个月累计
+
+            // 累计本月每天的数据
+            for ($day = 1; $day <= 31; $day++) {
+                $item['本月累计'] += $item[$day . '号'];
+                // 如果当天数据为 0,则显示为空字符串
+                if ($item[$day . '号'] === 0) {
+                    $item[$day . '号'] = '';
+                }
+            }
+
+            // 注意:上个月的每日统计数据不需要处理,仅保留本月的累计。
+        }
+
+        // 将结果转换为索引数组
+        $result = array_values($result);
+
+        // 返回结果
+        $this->success('成功', $result);
     }
+
+//    public function getOneWorkOrder() {
+//        // 确认请求为 GET 请求
+//        if (!$this->request->isGet()) {
+//            $this->error('请求方式错误');
+//        }
+//
+//        // 获取请求参数
+//        $param = $this->request->param();
+//
+//        // 获取当前月份和上个月的月份
+//        $currentMonth = date('Y-m', strtotime($param['riqi']));  // 当前月份
+//        $previousMonth = date('Y-m', strtotime('-1 month', strtotime($param['riqi'])));  // 上个月
+//
+//        // 查询当前月份的数据
+//        $where['上报时间'] = ['like', $currentMonth . '%'];
+//        $rows = db()->table('设备_报工记录')
+//            ->field('款式,款号,订单编号,组别,客户编号,code as 工序,上报数量,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间')
+//            ->where($where)
+//            ->select();
+//
+//        // 查询上个月的数据
+//        $wherePrevious['上报时间'] = ['like', $previousMonth . '%'];
+//        $rowsPrevious = db()->table('设备_报工记录')
+//            ->field('款式,款号,订单编号,组别,客户编号,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间')
+//            ->where($wherePrevious)
+//            ->select();
+//
+//        // 初始化结果数组
+//        $result = [];
+//
+//        // 处理当前月份的数据
+//        foreach ($rows as $row) {
+//            // 使用“款式”、“款号”、“订单编号”、“组别”作为唯一标识
+//            $key = $row['款式'] . '_' . $row['款号'] . '_' . $row['订单编号'] . '_' . $row['组别'];
+//
+//            // 如果结果集中已经存在该条目,则进行累加
+//            if (!isset($result[$key])) {
+//                // 初始化一个新的条目
+//                $result[$key] = [
+//                    '款式' => $row['款式'],
+//                    '款号' => $row['款号'],
+//                    '订单编号' => $row['订单编号'],
+//                    '组别' => $row['组别'],
+//                    '客户编号' => $row['客户编号'],
+//                    '工序' => $row['工序'],
+//                    '裁剪数' => $row['裁剪数'] ?? 0,
+//                    '制单数' => $row['制单数'] ?? 0,
+//                ];
+//
+//                // 初始化每日数据
+//                for ($day = 1; $day <= 31; $day++) {
+//                    $result[$key][$day . '号'] = 0;
+//                }
+//            }
+//
+//            // 按天累计数据
+//            $day = (int)date('d', strtotime($row['上报时间']));
+//            for ($i = 1; $i <= 10; $i++) {
+//                $keyScsl = 'scsl' . $i;
+//                $result[$key][$day . '号'] += !empty($row[$keyScsl]) ? (int)$row[$keyScsl] : 0;
+//            }
+//        }
+//
+//
+//
+//        // 计算本月和上个月的累计
+//        foreach ($result as &$item) {
+//            $item['本月累计'] = 0;
+//            $item['上个月累计'] = 0;
+//
+//            // 本月累计
+//            for ($day = 1; $day <= 31; $day++) {
+//                $item['本月累计'] += $item[$day . '号'];
+//                // 如果当日数据为0,则替换为空字符串
+//                if ($item[$day . '号'] === 0) {
+//                    $item[$day . '号'] = '';
+//                }
+//            }
+//
+//            // 上个月累计 (不需要再统计上个月的数据,只保留本月的每日统计)
+//        }
+//
+//        // 将结果转换为索引数组
+//        $result = array_values($result);
+//
+//        $this->success('成功', $result);
+//    }
     /**
      * 获取工单基本信息
      * @ApiMethod GET
      * @params string order
      */
     public function getOrderInfo(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        if (!isset($params['order']) || empty($params['order'])){
-            $this->error('参数错误');
-        }
-        $list = db('工单_基本资料')->alias('a')
-            ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
-            ->where('a.Gd_gdbh',$params['order'])
-            ->where('a.行号',1)
-            ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
-            ->select();
-        $this->success('请求成功',$list);
+
     }
     /**
      * 获取印件名称及工序
@@ -311,29 +406,7 @@ class WorkOrderVerification extends Api
      * @params string yj_no
      */
     public function getYjInfo(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        if (!isset($params['order']) || empty($params['order'])){
-            $this->error('参数错误');
-        }
-        if (!isset($params['yj_no']) || empty($params['yj_no'])){
-            $this->error('参数错误');
-        }
-        $where['Yj_Gdbh'] = $params['order'];
-        $where['yj_Yjno'] = $params['yj_no'];
-        $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
-        $option['Gy0_gdbh'] = $params['order'];
-        $option['Gy0_yjno'] = $params['yj_no'];
-        $option['Gy0_gxmc|Add_gxmc'] = ['like','%'.'核检'.'%'];
-//        $option['Gy0_site'] = '印后车间';
-//        $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
-        $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
-        $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
-        $list['gx_data'] = $gxList;
-        $list['max_num'] = $max;
-        $this->success('请求成功',$list);
+
 
     }
     /**
@@ -342,41 +415,7 @@ class WorkOrderVerification extends Api
      * @params string search
      */
     public function getWastInfo(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        $where['分类'] = '废品分类';
-        if (!empty($params['search'])){
-            $where['名称'] = array('like','%'.$params['search'].'%');
-        }
 
-        $data = db('erp_常用字典')->where($where)->column('名称');
-        // 分割字符串并合并相同项
-        $resultArray = [];
-        foreach ($data as $item) {
-            $parts = explode('_', $item);
-            // 使用第一个部分作为一级键,第二个部分作为二级键
-            $firstKey = $parts[0];
-            $secondKey = $parts[1];
-            $thirdValue = $parts[2];
-
-            $resultArray[$firstKey][$secondKey][] = $thirdValue;
-        }
-        // 对废品分类下的数组进行升序排序
-        if (isset($resultArray['data']['废品分类'])) {
-            foreach ($resultArray['data']['废品分类'] as &$category) {
-                // 判断是关联数组(单凹等)还是索引数组(分切等)
-                if (is_array($category) && !empty($category) && is_array(current($category))) {
-                    foreach ($category as &$subCategory) {
-                        ksort($subCategory);
-                    }
-                } else {
-                    ksort($category);
-                }
-            }
-        }
-        $this->success('请求成功',$resultArray);
     }
     /**
      *获取工序及责任组长
@@ -385,54 +424,7 @@ class WorkOrderVerification extends Api
      * @params string order
      */
     public function getGxAndLeader(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        if (!isset($params['type']) || empty($params['type'])){
-            $this->error('参数错误');
-        }
-        if (!isset($params['order']) || empty($params['order'])){
-            $this->error('参数错误');
-        }
-        if (!isset($params['yjno']) || empty($params['yjno'])){
-            $this->error('参数错误');
-        }
-        $type = trim($params['type']);
-        $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
-        if (empty($waste)){
-            $this->error('未查询到废品分类');
-        }
-        $wasteType = explode('_',substr($waste['名称'],0,-1));
-        $searchArr = explode('-',$wasteType[1]);
-        $where['a.sczl_gdbh'] = $params['order'];
-        $where['a.sczl_yjno'] = $params['yjno'];
-        //模切和凹凸的废品类型相同
-        if ($searchArr[1] === '模切凹凸'){
-            $list = db('设备_产量计酬')->alias('a')
-                ->join('人事_基本资料 b', 'a.sczl_bh1 = b.员工编号', 'left')
-                ->where($where)
-                ->where(function($query) {
-                    $query->where('a.sczl_type', 'like', '%模切%')
-                        ->whereOr('a.sczl_type', 'like', '%凹凸%');
-                })
-                ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
-                ->select();
-        }else{
-            $search = substr($searchArr[1],0,6);
-            $where['a.sczl_type'] = array('like','%'.$search.'%');
-            $list = db('设备_产量计酬')->alias('a')
-                ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
-                ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
-                ->select();
-        }
-        $count = count($list);
-        $list[$count]['sczl_gxmc'] = '99-外发加工';
-        $list[$count]['sczl_bzdh'] = 'A班';
-        $list[$count]['sczl_jtbh'] = '';
-        $list[$count]['sczl_bh1'] = '000000';
-        $list[$count]['name'] = '计时工';
-        $this->success('请求成功',$list);
+
     }
     /**
      * 修改工单核检单

+ 9 - 1
application/common.php

@@ -4,7 +4,7 @@
 
 use think\exception\HttpResponseException;
 use think\Response;
-
+use think\Session;
 if (!function_exists('__')) {
 
     /**
@@ -560,3 +560,11 @@ EOT;
         return $icon;
     }
 }
+
+//连接 Redis
+function redis(){
+    $redis = new \Redis();
+    //    $redis->connect($this->redis_config['host'], $this->redis_config['port'], $this->redis_config['timeout']);
+    $redis->connect('127.0.0.1','6379',16400,'');
+    return $redis;
+}

+ 4 - 0
public/index.php

@@ -18,6 +18,10 @@ if (!is_file(APP_PATH . 'admin/command/Install/install.lock')) {
     header("location:./install.php");
     exit;
 }
+header('Access-Control-Allow-Credentials: true');
+header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
+header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With');
+header('Access-Control-Allow-Origin: *');
 
 // 加载框架引导文件
 require __DIR__ . '/../thinkphp/start.php';