Browse Source

redis缓存优化

曹鹤洋 1 year ago
parent
commit
4d6263d2a4

+ 83 - 55
application/api/controller/FinishedProductWarehousing.php

@@ -31,17 +31,17 @@ class FinishedProductWarehousing extends Api
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
-        $rows = db()->table('成品入仓')
+        $rows = db('成品入仓')
             ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
             ->group('date')
             ->order('UniqId desc')
             ->limit(50)
             ->select();
 
-        $num = db()->table('成品入仓')
+        $num = db('成品入仓')
             ->where('sys_rq','>=',$rows[49]['date'])
             ->count();
-        $arr = db()->table('成品入仓')
+        $arr = db('成品入仓')
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[49]['date'])
             ->group('date, sys_id')
@@ -73,15 +73,15 @@ class FinishedProductWarehousing extends Api
             $this->error('请求方式错误');
         }
 
-        $num = db()->table('成品入仓')->count();
-        $rows = db()->table('成品入仓')
+        $num = db('成品入仓')->count();
+        $rows = db('成品入仓')
             ->field('jjcp_gdbh, rtrim(jjcp_cpdh) as jjcp_cpdh, LEFT(Sys_rq, 10) as Sys_rq')
             ->order('Sys_rq desc')
             ->limit($num)
             ->select();
 
-        $num = db()->table('工单_基本资料')->count();
-        $arr = db()->table('工单_基本资料')
+        $num = db('工单_基本资料')->count();
+        $arr = db('工单_基本资料')
             ->limit($num)
             ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, CONCAT(rtrim(Gd_khdh), " 【", rtrim(Gd_khmc)) AS kh');
 
@@ -136,7 +136,7 @@ class FinishedProductWarehousing extends Api
         }
 
         //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
             c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
@@ -151,9 +151,9 @@ class FinishedProductWarehousing extends Api
             ->page($page,$limit)
             ->select();
 
-        $total = db()->table('成品入仓')->where($option)->count();
+        $total = db('成品入仓')->where($option)->count();
         foreach ($rows as $key=>$value) {
-            $row = db()->table('成品入仓')
+            $row = db('成品入仓')
                 ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
                 ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
                 ->order('Sys_rq desc')
@@ -205,7 +205,7 @@ class FinishedProductWarehousing extends Api
             $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
             $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
             //客户编号
-            $rows = db()->table('成品入仓')->alias('c')
+            $rows = db('成品入仓')->alias('c')
                 ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
             c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
@@ -221,17 +221,17 @@ class FinishedProductWarehousing extends Api
                 ->order('c.UniqId desc')
                 ->page($page,$limit)
                 ->select();
-            $total = db()->table('成品入仓')->where($option)->count();
+            $total = db('成品入仓')->where($option)->count();
         }else{
             if (isset($req['cpmc']) && !empty($req['cpmc'])){
                 //查询工单表
-                $gd = db()->table('工单_基本资料')
+                $gd = db('工单_基本资料')
                     ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
                     ->column('Gd_gdbh');
                 $where = ['c.jjcp_gdbh'=>['in', $gd]];
                 $option = ['jjcp_gdbh'=>['in', $gd]];
                 //客户编号
-                $rows = db()->table('成品入仓')->alias('c')
+                $rows = db('成品入仓')->alias('c')
                     ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
             c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
@@ -247,13 +247,13 @@ class FinishedProductWarehousing extends Api
                     ->order('c.UniqId desc')
                     ->page($page,$limit)
                     ->select();
-                $total = db()->table('成品入仓')->where($option)->count();
+                $total = db('成品入仓')->where($option)->count();
             }else{
                 $this->error('参数错误');
             }
         }
         foreach ($rows as $key=>$value) {
-            $row = db()->table('成品入仓')
+            $row = db('成品入仓')
                 ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
                 ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
                 ->order('Sys_rq desc')
@@ -297,7 +297,7 @@ class FinishedProductWarehousing extends Api
             $this->error('参数错误');
         }
         //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             rtrim(c.jjcp_num) as jjcp_num, 
             c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号, 
@@ -313,7 +313,7 @@ class FinishedProductWarehousing extends Api
             ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
             ->find();
 
-        $rows['jjcp_sls'] = db()->table('成品入仓')
+        $rows['jjcp_sls'] = db('成品入仓')
             ->where(['jjcp_gdbh'=>$rows['jjcp_gdbh'], 'jjcp_cpdh'=>$rows['jjcp_cpdh']])
             ->sum('jjcp_sl');
 
@@ -336,7 +336,7 @@ class FinishedProductWarehousing extends Api
         if (isset($req['key_word']) && !empty($req['key_word'])){
             $key_word = $req['key_word'];
         }
-        $rs = db()->table('物料_仓库信息')
+        $rs = db('物料_仓库信息')
             ->field('rtrim(编号) as 编号, rtrim(名称) as 名称')
             ->where('编号|名称','like','%'.$key_word.'%')
             ->where('名称','in',['面材仓库','主要产成品'])
@@ -363,7 +363,7 @@ class FinishedProductWarehousing extends Api
             $this->error('参数错误');
         }
 
-        $rows = db()->table('工单_基本资料')->alias('g')
+        $rows = db('工单_基本资料')->alias('g')
             ->field('g.Gd_gdbh, j.yj_yjno, rtrim(g.销售订单号) as 销售订单号, rtrim(j.yj_Yjdh) as yj_Yjdh, rtrim(j.yj_yjmc) as yj_yjmc, rtrim(g.成品代号) as 成品代号, rtrim(g.成品名称) as 成品名称, rtrim(g.客户料号) as 客户料号')
             ->where(['g.Gd_gdbh'=>$gdbh])
             ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
@@ -407,14 +407,14 @@ class FinishedProductWarehousing extends Api
 //            $this->error('参数错误');
 //        }
 
-        $rows = db()->table('工单_基本资料')->alias('g')
+        $rows = db('工单_基本资料')->alias('g')
             ->field('订单数量*10000 as 订单数量, gd_statu')
             ->where(['Gd_gdbh'=>$gdbh, 'Gd_cpdh'=>$cpdh])
             ->find();
 
         if (!$rows) $this->error('未查询到记录');
 
-        $rows['jjcp_sls'] = db()->table('成品入仓')
+        $rows['jjcp_sls'] = db('成品入仓')
             ->where(['jjcp_gdbh'=>$gdbh, 'jjcp_cpdh'=>$cpdh])
             ->sum('jjcp_sl');
 
@@ -458,10 +458,14 @@ class FinishedProductWarehousing extends Api
         }
         $data['Sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db('成品入仓')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('成品入仓')->fetchSql(true)->insert($data);
+            $sql = db('成品入仓')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -517,7 +521,7 @@ class FinishedProductWarehousing extends Api
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $sql = db('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -551,7 +555,7 @@ class FinishedProductWarehousing extends Api
         //开启事务
         db()->startTrans();
         try{
-            $bool = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->delete();
+            $bool = db('成品入仓')->where('UniqId',$req['UniqId'])->delete();
             // 提交事务
             db()->commit();
         } catch (\Exception $e) {
@@ -579,7 +583,7 @@ class FinishedProductWarehousing extends Api
         }
         $req = $this->request->param();
 
-        if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
+        if (!isset($req['date'])) $this->error('参数缺失');
 
         if (!(isset($req['fields']) && count($req['fields'])!=0)){
             $this->error('参数错误','fields',100);
@@ -587,6 +591,8 @@ class FinishedProductWarehousing extends Api
 
         if(strpos($req['date'],'-')){
             $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
+        }else if(empty($req['date'])){
+            $where = [];
         }else{
             $where = ['c.jjcp_gdbh'=>$req['date']];
         }
@@ -626,24 +632,34 @@ class FinishedProductWarehousing extends Api
             }
         }
 
-        //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
-            ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
+        $num = db('成品入仓')->alias('c')
+            ->where($where)
+            ->where('g.Gd_cpdh=c.jjcp_cpdh')
+            ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+            ->count();
+
+        $rows = [];
+        for($i=1;$i<=ceil($num/10000);$i++){
+            $p = $i == ceil($num/10000) ? $num%10000 : 10000;
+            $r = db('成品入仓')->alias('c')
+                ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
             c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
             rtrim(c.jjcp_smb) as jjcp_smb, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
             rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称, 
             rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, LEFT(c.成品编码,4) as 客户编号, rtrim(g.Gd_客户名称) as Gd_客户名称, 
             rtrim(c.机型备注) as 机型备注')
-            ->where($where)
-            ->where('g.Gd_cpdh=c.jjcp_cpdh')
-            ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
-            ->order('c.UniqId desc')
-            ->select();
+                ->where($where)
+                ->where('g.Gd_cpdh=c.jjcp_cpdh')
+                ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+                ->order('c.UniqId desc')
+                ->limit($i,$p)
+                ->select();
+            $rows = array_merge($rows,$r);
+        }
 
         foreach ($rows as $key=>$value) {
-
-            $row = db()->table('成品入仓')
+            $row = db('成品入仓')
                 ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
                 ->where(['jjcp_gdbh'=>$value['jjcp_gdbh'], 'jjcp_cpdh'=>$value['jjcp_cpdh']])
                 ->order('Sys_rq desc')
@@ -726,7 +742,7 @@ class FinishedProductWarehousing extends Api
         }
 
         //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
             c.jjcp_gdbh, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
             c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, c.jjcp_sj, 
@@ -796,7 +812,7 @@ class FinishedProductWarehousing extends Api
             }
         }
 
-        $rows1 = db()->table('成品入仓')->alias('c')
+        $rows1 = db('成品入仓')->alias('c')
             ->field('rtrim(c.入仓类型) as 入仓类型, LEFT(c.成品编码,4) as 客户编号, rtrim(b.客户名称) as 客户名称,
             rtrim(b.产品类别) as 产品类别, c.jjcp_gdbh,
             rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称
@@ -807,7 +823,7 @@ class FinishedProductWarehousing extends Api
             ->group('c.jjcp_gdbh')
             ->select();
 
-        $rows2 = db()->table('成品入仓')
+        $rows2 = db('成品入仓')
             ->field('rtrim(入仓类型) as 入仓类型, rtrim(成品编码) as 客户编号, 
             rtrim(成品编码) as 客户名称, rtrim(成品编码) as 产品类别,
             jjcp_gdbh,rtrim(成品编码) as 成品编码, rtrim(成品名称) as 成品名称
@@ -819,12 +835,12 @@ class FinishedProductWarehousing extends Api
             ->select();
         $rows = array_merge($rows2,$rows1);
 
-        $num = db()->table('工单_基本资料')->count();
-        $arr1 = db()->table('工单_基本资料')->limit($num)
+        $num = db('工单_基本资料')->count();
+        $arr1 = db('工单_基本资料')->limit($num)
             ->column('CONCAT(Gd_gdbh, "-", rtrim(Gd_cpdh)) AS gdcp, 产品单价 as 万张单价');
 
         $brr = array_column($rows,'jjcp_gdbh');
-        $brr = db()->table('成品入仓')
+        $brr = db('成品入仓')
             ->where('jjcp_gdbh', 'in', $brr)
             ->group('jjcp_gdbh')
             ->column('jjcp_gdbh, sum(jjcp_sl)');
@@ -896,7 +912,7 @@ class FinishedProductWarehousing extends Api
         }
 
         //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('LEFT(c.jjcp_sj, 10) as jjcp_sj, c.jjcp_gdbh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
             rtrim(c.jjcp_cpdh) as jjcp_cpdh, g.实际投料')
             ->where($where)
@@ -907,14 +923,14 @@ class FinishedProductWarehousing extends Api
             ->page($page,$limit)
             ->select();
 
-        $total = db()->table('成品入仓')->alias('c')
+        $total = db('成品入仓')->alias('c')
             ->where($where)
             ->where('g.Gd_cpdh=c.jjcp_cpdh')
             ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
             ->group('c.jjcp_gdbh, c.jjcp_cpdh')
             ->count();
 
-        $brr = db()->table('成品入仓')
+        $brr = db('成品入仓')
             ->group('jjcp_gdbh,jjcp_cpdh')
             ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
 
@@ -987,7 +1003,7 @@ class FinishedProductWarehousing extends Api
         ];
 
         //客户编号
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc, rtrim(c.jjcp_cpdh) as jjcp_cpdh, 
             rtrim(c.成品编码) as 成品编码, rtrim(c.成品名称) as 成品名称, sum(jjcp_sl) as jjcp_sls, 
             g.实际投料, LEFT(c.jjcp_sj, 10) as jjcp_sj
@@ -1037,7 +1053,19 @@ class FinishedProductWarehousing extends Api
 
         ];
 
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('db_包装产量预报')
+            ->field('sczl_rq,sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,sys_rq,mod_rq,UniqId')
+            ->where('sys_rq','>=','2023-10-25')
+            ->select();
+        $uniqueValues = [];
+        foreach ($rows as $row) {
+            $gdbhArray = array($row['sczl_gdbh1'], $row['sczl_gdbh2'], $row['sczl_gdbh3'], $row['sczl_gdbh4'], $row['sczl_gdbh5'], $row['sczl_gdbh6']);
+            $uniqueValues = array_merge($uniqueValues, array_unique($gdbhArray));
+        }
+
+        $uniqueValues = array_values(array_unique($uniqueValues));
+        halt($uniqueValues);
+        $rows = db('成品入仓')->alias('c')
             ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
             y.yj_成品数量, y.yj_实际投料, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_smb) as jjcp_smb,
             sum(c.jjcp_sl) as jjcp_sls, left(max(c.Sys_rq),10) as Sys_rq')
@@ -1049,18 +1077,18 @@ class FinishedProductWarehousing extends Api
             ->page($page,$limit)
             ->select();
 
-        $total = db()->table('成品入仓')->alias('c')
+        $total = db('成品入仓')->alias('c')
             ->where($where)
             ->where('y.yj_Yjdh=c.jjcp_cpdh')
             ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
             ->group('c.jjcp_gdbh, c.jjcp_cpdh')
             ->count();
-        $brr = db()->table('成品入仓')
+        $brr = db('成品入仓')
             ->group('jjcp_gdbh,jjcp_cpdh')
             ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
 
-        $num = db()->table('db_包装产量预报')->count();
-        $arr1 = db()->table('db_包装产量预报')
+        $num = db('db_包装产量预报')->count();
+        $arr1 = db('db_包装产量预报')
             ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6, 
             substr(sczl_yjGx1,2,1) as sczl_yjGx1, substr(sczl_yjGx2,2,1) as sczl_yjGx2, 
             substr(sczl_yjGx3,2,1) as sczl_yjGx3, substr(sczl_yjGx4,2,1) as sczl_yjGx4, 
@@ -1162,7 +1190,7 @@ class FinishedProductWarehousing extends Api
             'c.jjcp_smb'=>['<>','']
         ];
 
-        $rows = db()->table('成品入仓')->alias('c')
+        $rows = db('成品入仓')->alias('c')
             ->field('c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.jjcp_cpmc) as jjcp_cpmc,
             y.yj_成品数量, y.yj_实际投料, rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_smb) as jjcp_smb,
             sum(c.jjcp_sl) as jjcp_sls, left(max(c.Sys_rq),10) as Sys_rq')
@@ -1173,12 +1201,12 @@ class FinishedProductWarehousing extends Api
             ->group('c.jjcp_gdbh, c.jjcp_cpdh')
             ->select();
 
-        $brr = db()->table('成品入仓')
+        $brr = db('成品入仓')
             ->group('jjcp_gdbh,jjcp_cpdh')
             ->column('CONCAT(jjcp_gdbh, "-", rtrim(jjcp_cpdh)), sum(jjcp_sl)');
 
-        $num = db()->table('db_包装产量预报')->count();
-        $arr1 = db()->table('db_包装产量预报')
+        $num = db('db_包装产量预报')->count();
+        $arr1 = db('db_包装产量预报')
             ->field('sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6, 
             substr(sczl_yjGx1,2,1) as sczl_yjGx1, substr(sczl_yjGx2,2,1) as sczl_yjGx2, 
             substr(sczl_yjGx3,2,1) as sczl_yjGx3, substr(sczl_yjGx4,2,1) as sczl_yjGx4, 

+ 112 - 56
application/api/controller/Inspect.php

@@ -30,25 +30,34 @@ class Inspect extends Api
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
-        $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq  FROM `db_手工检验` ORDER BY sys_rq DESC LIMIT 30 ';
-        $list = Db::query($sql);
 
-        foreach ($list as $key => $value){
-            $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
-            $dataCount = db()->table('db_手工检验')->where('sys_rq','between time',$where)->field('rtrim(sys_id) as sys_id')->order('sys_id asc')->select();
-            $list[$key]['count'] = count($dataCount);
-            // 提取 sys_id 列成新数组
-            $sysIds = array_column($dataCount, 'sys_id');
-            //统计每个不同的 sys_id 的数量
-            $counts = array_count_values($sysIds);
-            $i = 0;
-            foreach ($counts as $k=>$v){
-                $list[$key]['sys'][$i]['sys_id'] = $k;
-                $list[$key]['sys'][$i]['count'] = $v;
-                $i++;
+        $rows = db('db_手工检验')
+            ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
+            ->group('date')
+            ->order('UniqId desc')
+            ->limit(30)
+            ->select();
+        $num = db('db_手工检验')
+            ->where('sys_rq','>=',$rows[29]['date'])
+            ->count();
+        $arr = db('db_手工检验')
+            ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
+            ->where('sys_rq','>=',$rows[29]['date'])
+            ->group('date, sys_id')
+            ->limit($num)
+            ->select();
+        foreach($rows as $key=>$value){
+            $rows[$key]['sys'] = [];
+            foreach($arr as $k=>$v){
+                if($value['date'] == $v['date']){
+                    unset($v['date']);
+                    array_push($rows[$key]['sys'],$v);
+                    unset($arr[$k]);
+                }
             }
         }
-        $this->success('请求成功',$list);
+
+        $this->success('请求成功',$rows);
     }
 
     /**
@@ -61,10 +70,16 @@ class Inspect extends Api
             $this->error('非法请求');
         }
         $sql = 'SELECT DISTINCT sczl_gdbh  FROM `db_手工检验` ORDER BY sczl_gdbh DESC LIMIT 65 ';
-        $list = Db::query($sql);
+        $list = db()->query($sql);
+//        $rows = db('db_手工检验')
+//            ->field('sczl_gdbh')
+//            ->group('sczl_gdbh')
+//            ->order('sczl_gdbh desc')
+//            ->limit(65)
+//            ->select();
 
         foreach ($list as $key => $value){
-            $dataCount = db()->table('db_手工检验')->alias('d')
+            $dataCount = db('db_手工检验')->alias('d')
                 ->where('sczl_gdbh',$value['sczl_gdbh'])
                 ->where('SUBSTR(d.sczl_yjgx,1,2) = g.yj_Yjno')
                 ->field('rtrim(d.sys_id) as sys_id, rtrim(g.yj_yjmc) as yj_yjmc')
@@ -123,7 +138,7 @@ class Inspect extends Api
 
         $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
         rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
-        $list = db()->table('db_手工检验')->alias('a')
+        $list = db('db_手工检验')->alias('a')
             ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
             ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
             ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
@@ -131,7 +146,7 @@ class Inspect extends Api
             ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
             ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
 
-        $count = db()->table('db_手工检验')->where($option)->count();
+        $count = db('db_手工检验')->where($option)->count();
 
         $data['data'] = $list;
         $data['total'] = $count;
@@ -149,10 +164,10 @@ class Inspect extends Api
             $this->error('非法请求');
         }
         $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq  FROM `db_机器检验` ORDER BY sys_rq DESC LIMIT 30 ';
-        $list = Db::query($sql);
+        $list = db()->query($sql);
         foreach ($list as $key => $value){
             $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
-            $dataCount = db()->table('db_机器检验')->where('sys_rq','between time',$where)->field('rtrim(sys_id) as sys_id')->order('sys_id asc')->select();
+            $dataCount = db('db_机器检验')->where('sys_rq','between time',$where)->field('rtrim(sys_id) as sys_id')->order('sys_id asc')->select();
             $list[$key]['count'] = count($dataCount);
             // 提取 sys_id 列成新数组
             $sysIds = array_column($dataCount, 'sys_id');
@@ -168,6 +183,39 @@ class Inspect extends Api
         $this->success('请求成功',$list);
     }
 
+    /**
+     * 获取机器检验左侧菜单栏
+     *
+     * @ApiMethod GET
+    */
+    public function getMachineCountByGdbh(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $sql = 'SELECT DISTINCT sczl_gdbh  FROM `db_机器检验` ORDER BY sczl_gdbh DESC LIMIT 65 ';
+        $list = Db::query($sql);
+        foreach ($list as $key => $value){
+            $dataCount = Db::name('db_机器检验')->alias('d')
+                ->where('sczl_gdbh',$value['sczl_gdbh'])
+                ->field('rtrim(d.sys_id) as sys_id, rtrim(g.Gd_cpmc) as Gd_cpmc')
+                ->join(['工单_基本资料'=>'g'],'d.sczl_gdbh=g.Gd_gdbh')
+                ->order('sys_id asc')
+                ->select();
+            $list[$key]['cpmc'] = $dataCount[0]['Gd_cpmc'];
+            // 提取 sys_id 列成新数组
+            $sysIds = array_column($dataCount, 'sys_id');
+            //统计每个不同的 sys_id 的数量
+            $counts = array_count_values($sysIds);
+            $i = 0;
+            foreach ($counts as $k=>$v){
+                $list[$key]['sys'][$i]['sys_id'] = $k;
+                $list[$key]['sys'][$i]['count'] = $v;
+                $i++;
+            }
+        }
+        $this->success('请求成功',$list);
+    }
+
     /**
      * 获取某个日期机器单据
      *
@@ -203,7 +251,7 @@ class Inspect extends Api
         a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
         a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
         rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
-        $list = db()->table('db_机器检验')->alias('a')
+        $list = db('db_机器检验')->alias('a')
             ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
             ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
             ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -213,7 +261,7 @@ class Inspect extends Api
             ->where($where)
             ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
             ->field($field)->page($page,$limit)->order('a.UniqId desc')->select();
-        $count = db()->table('db_机器检验')->where($option)->count();
+        $count = db('db_机器检验')->where($option)->count();
 
         $data['data'] = $list;
         $data['total'] = $count;
@@ -248,7 +296,7 @@ class Inspect extends Api
 
             $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
         rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
-            $rows = db()->table('db_手工检验')->alias('a')
+            $rows = db('db_手工检验')->alias('a')
                 ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
                 ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
                 ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
@@ -257,11 +305,11 @@ class Inspect extends Api
                 ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
 
             $option['sczl_gdbh'] = [ 'like', '%' . $req['gdbh'] . '%'];
-            $total = db()->table('db_手工检验')->where($option)->count();
+            $total = db('db_手工检验')->where($option)->count();
         }else{
             if (isset($req['cpmc']) && !empty($req['cpmc'])){
                 //查询工单表
-                $gd = db()->table('工单_基本资料')
+                $gd = db('工单_基本资料')
                     ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
                     ->column('Gd_gdbh');
                 $where = [
@@ -269,7 +317,7 @@ class Inspect extends Api
                 ];
                 $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
         rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
-                $rows = db()->table('db_手工检验')->alias('a')
+                $rows = db('db_手工检验')->alias('a')
                     ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
                     ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
                     ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
@@ -278,7 +326,7 @@ class Inspect extends Api
                     ->field($field)->page($page,$limit)->order('a.sczl_rq,a.UniqId asc')->select();
 
                 $option['sczl_gdbh'] = ['in', $gd];
-                $total = db()->table('db_手工检验')->where($option)->count();
+                $total = db('db_手工检验')->where($option)->count();
             }else{
                 $this->error('参数错误');
             }
@@ -321,7 +369,7 @@ class Inspect extends Api
         a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
         a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
         rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
-            $rows = db()->table('db_机器检验')->alias('a')
+            $rows = db('db_机器检验')->alias('a')
                 ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
                 ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
                 ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -333,12 +381,12 @@ class Inspect extends Api
                 ->field($field)->page($page,$limit)->order('a.sczl_rq asc,a.UniqId desc')->select();
             $option['sczl_单据类型'] = '初检单';
             $option['sczl_gdbh'] = [ 'like', '%' . $req['gdbh'] . '%'];
-            $total = db()->table('db_机器检验')->where($option)->count();
+            $total = db('db_机器检验')->where($option)->count();
 
         }else{
             if (isset($req['cpmc']) && !empty($req['cpmc'])){
                 //查询工单表
-                $gd = db()->table('工单_基本资料')
+                $gd = db('工单_基本资料')
                     ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
                     ->column('Gd_gdbh');
                 $where = [
@@ -349,7 +397,7 @@ class Inspect extends Api
         a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,rtrim(a.sczl_检验类别) as sczl_检验类别,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,
         a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,
         rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
-                $rows = db()->table('db_机器检验')->alias('a')
+                $rows = db('db_机器检验')->alias('a')
                     ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
                     ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
                     ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -361,7 +409,7 @@ class Inspect extends Api
                     ->field($field)->page($page,$limit)->order('a.sczl_rq asc,a.UniqId desc')->select();
                 $option['sczl_单据类型'] = '初检单';
                 $option['sczl_gdbh'] = ['in', $gd];
-                $total = db()->table('db_机器检验')->where($option)->count();
+                $total = db('db_机器检验')->where($option)->count();
             }else{
                 $this->error('参数错误');
             }
@@ -411,7 +459,7 @@ class Inspect extends Api
         a.sczl_cl7,a.sczl_cl8,a.sczl_cl9,a.sczl_cl10,a.sczl_cl11,a.sczl_cl12,
         a.sczl_fp1,a.sczl_fp2,a.sczl_fp3,a.sczl_fp4,a.sczl_fp5,a.sczl_fp6,
         a.sczl_fp7,a.sczl_fp8,a.sczl_fp9,a.sczl_fp10,a.sczl_fp11,a.sczl_fp12';
-        $rows = db()->table('db_手工检验')->alias('a')
+        $rows = db('db_手工检验')->alias('a')
             ->join('人事_基本资料 c0','a.sczl_bh0 = c0.员工编号','left')
             ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
             ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -466,7 +514,7 @@ class Inspect extends Api
         rtrim(c5.员工姓名) as sczl_bh5_name,rtrim(c6.员工姓名) as sczl_bh6_name,
         rtrim(c7.员工姓名) as sczl_bh7_name,rtrim(c8.员工姓名) as sczl_bh8_name,
         rtrim(d.yj_yjmc) as yj_yjmc';
-        $rows = db()->table('db_机器检验')->alias('a')
+        $rows = db('db_机器检验')->alias('a')
             ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
             ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
             ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -510,7 +558,7 @@ class Inspect extends Api
         }
         array_push($gxmcs,'OR');
 
-        $rows = db()->table('工单_基本资料')->alias('g')
+        $rows = db('工单_基本资料')->alias('g')
             ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
             ->where(['g.Gd_gdbh'=>$gdbh])
             ->where(['c.Gy0_gxmc'=>$gxmcs])
@@ -551,7 +599,7 @@ class Inspect extends Api
         }
         array_push($gxmcs,'OR');
 
-        $rows = db()->table('工单_基本资料')->alias('g')
+        $rows = db('工单_基本资料')->alias('g')
             ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
             ->where(['g.Gd_gdbh'=>$gdbh])
             ->where(['c.Gy0_gxmc'=>$gxmcs])
@@ -577,11 +625,11 @@ class Inspect extends Api
             $this->error('请求方式错误');
         }
 
-        $row = db()->table('dic_lzde')
+        $row = db('dic_lzde')
             ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
             ->where('sys_mc','初检(手工)')
             ->find();
-        $rows = db()->table('dic_lzde')
+        $rows = db('dic_lzde')
             ->field('sys_bh, rtrim(sys_mc) as sys_mc')
 //            ->where('Parent',$row['Key_'])
             ->where('sys_bh','like',$row['sys_bh'].'%')
@@ -608,11 +656,11 @@ class Inspect extends Api
 //        }else{
 //            $this->error('参数错误');
 //        }
-        $row = db()->table('dic_lzde')
+        $row = db('dic_lzde')
             ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
             ->where('适用机型','JP01#')
             ->find();
-        $rows = db()->table('dic_lzde')
+        $rows = db('dic_lzde')
             ->field('sys_bh, rtrim(sys_mc) as sys_mc')
 //            ->where('Parent',$row['Key_'])
             ->where('sys_bh','like',$row['sys_bh'].'%')
@@ -647,7 +695,7 @@ class Inspect extends Api
             case '废品板':
                 $field = '人工检_废检 as num';
         }
-        $rows = db()->table('工单_工艺资料')
+        $rows = db('工单_工艺资料')
             ->field($field)
             ->where(['Gy0_gdbh'=>$gdbh, 'Gy0_yjno'=>$yjno, 'Gy0_gxh'=>$gxh])
             ->find();
@@ -678,7 +726,7 @@ class Inspect extends Api
             case '废品板':
                 $field = '机检_废检 as num';
         }
-        $rows = db()->table('工单_工艺资料')
+        $rows = db('工单_工艺资料')
             ->field($field)
             ->where(['Gy0_gdbh'=>$gdbh, 'Gy0_yjno'=>$yjno, 'Gy0_gxh'=>$gxh])
             ->find();
@@ -702,11 +750,11 @@ class Inspect extends Api
         }else{
             $this->error('参数错误');
         }
-//        $row = db()->table('dic_lzde')
+//        $row = db('dic_lzde')
 //            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
 //            ->where('sys_mc',$sys_mc)
 //            ->find();
-        $rows = db()->table('dic_lzde')->alias('d')
+        $rows = db('dic_lzde')->alias('d')
             ->field('rtrim(s.设备编号) as jtbh, rtrim(s.设备名称) as jtmc')
 //            ->where('Parent',$row['Key_'])
             ->where('d.适用机型','like','JP%')
@@ -751,10 +799,14 @@ class Inspect extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db('db_手工检验')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_手工检验')->fetchSql(true)->insert($data);
+            $sql = db('db_手工检验')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -802,10 +854,14 @@ class Inspect extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db('db_机器检验')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_机器检验')->fetchSql(true)->insert($data);
+            $sql = db('db_机器检验')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -861,7 +917,7 @@ class Inspect extends Api
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_手工检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $sql = db('db_手工检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -913,7 +969,7 @@ class Inspect extends Api
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_机器检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $sql = db('db_机器检验')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -947,7 +1003,7 @@ class Inspect extends Api
         //开启事务
         db()->startTrans();
         try{
-            $bool = db()->table('db_手工检验')->where('UniqId',$req['UniqId'])->delete();
+            $bool = db('db_手工检验')->where('UniqId',$req['UniqId'])->delete();
 
             // 提交事务
             db()->commit();
@@ -982,7 +1038,7 @@ class Inspect extends Api
         //开启事务
         db()->startTrans();
         try{
-            $bool = db()->table('db_机器检验')->where('UniqId',$req['UniqId'])->delete();
+            $bool = db('db_机器检验')->where('UniqId',$req['UniqId'])->delete();
 
             // 提交事务
             db()->commit();
@@ -1053,7 +1109,7 @@ class Inspect extends Api
             }
         }
 
-        $rows = db()->table('db_手工检验')->alias('a')
+        $rows = db('db_手工检验')->alias('a')
             ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
             ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
             ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
@@ -1140,7 +1196,7 @@ class Inspect extends Api
             }
         }
 
-        $rows = db()->table('db_机器检验')->alias('a')
+        $rows = db('db_机器检验')->alias('a')
             ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
             ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
             ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
@@ -1214,7 +1270,7 @@ class Inspect extends Api
             }
         }
 
-        $rows = db()->table('db_手工检验')->alias('a')
+        $rows = db('db_手工检验')->alias('a')
             ->field($field)
             ->where($where)
             ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_Yjno')
@@ -1289,7 +1345,7 @@ class Inspect extends Api
             }
         }
 
-        $rows = db()->table('db_手工检验')
+        $rows = db('db_手工检验')
             ->field('sczl_gdbh,'.$field)
             ->where('sczl_rq',['>=',$req['start_time']],['<=',$req['end_time']],'and')
             ->where('qczl_Num|qczl_NumDesc1|qczl_NumDesc2|qczl_NumDesc3|qczl_NumDesc4|qczl_NumDesc5|qczl_NumDesc6|qczl_NumDesc7|qczl_NumDesc8','<>',0)

+ 16 - 33
application/api/controller/MachineProductionReport.php

@@ -32,25 +32,25 @@ class MachineProductionReport extends Api
             $this->error('请求方式错误');
         }
 
-        $rows = db()->table('设备_产量计酬')
+        $rows = db()->table('设备_产量计酬')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
             ->group('date')
             ->order('UniqId desc')
             ->limit(30)
             ->select();
-        $rows1 = db()->table('db_sczl')
+        $rows1 = db()->table('db_sczl')->cache(true,300)
             ->group('date')
             ->order('UniqId desc')
             ->limit(40)
             ->column('LEFT(sys_rq, 10) as date, COUNT(*) as counts');
 
-        $arr2 = db()->table('设备_产量计酬')
+        $arr2 = db()->table('设备_产量计酬')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[29]['date'])
             ->group('date, sys_id')
             ->select();
 
-        $arr1 = db()->table('db_sczl')
+        $arr1 = db()->table('db_sczl')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[29]['date'])
             ->group('date, sys_id')
@@ -86,27 +86,6 @@ class MachineProductionReport extends Api
                     }else{
                         $result[$date][$sysId] = 0;
                     }
-//                }else if (substr($sysId,5,1)=='/'){
-//                    $num = substr($sysId,1,4);
-//                    $i = $flag = 0;
-//                    foreach ($result[$date] as $k => $v) {
-//                        if (substr($k, 4, 1) === "/") {
-//                            dump(substr($k, 1, 4));
-//                            dump($k);
-//                            dump($result[$date][$i+1]);
-//                            if (substr($k, 1, 4)<$num && substr($result[$date][$i+1], 1, 4)>$num){
-//                                $flag = $i;
-//                                break;
-//                            }
-//                        }
-//                        $i++;
-//                    }
-//                    dump($flag);
-//                    if (isset($result[$date])){
-//                        $result[$date] = array_merge([$sysId=>0],$result[$date]);
-//                    }else{
-//                        $result[$date][$sysId] = 0;
-//                    }
                 }else{
                     $result[$date][$sysId] = 0;
                 }
@@ -151,13 +130,13 @@ class MachineProductionReport extends Api
             WHERE t1.sczl_yjno = t2.yj_Yjno
             ORDER BY t1.`sczl_gdbh` DESC
             LIMIT 65';
-        $rows = db()->query($sql);
+        $rows = db()->cache(true,300)->query($sql);
 
-        $arr1 = db()->table('设备_产量计酬')
+        $arr1 = db()->table('设备_产量计酬')->cache(true,300)
             ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
             ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
             ->select();
-        $arr2 = db()->table('db_sczl')
+        $arr2 = db()->table('db_sczl')->cache(true,300)
             ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
             ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
             ->select();
@@ -228,7 +207,7 @@ class MachineProductionReport extends Api
             ->where($where)
             ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
             ->order('a.sys_id asc, a.sczl_num asc')
-            ->page($page,$limit)
+//            ->page($page,$limit)
             ->select();
 
         $total1 = db()->table('设备_产量计酬')->where($option)->count();
@@ -244,7 +223,7 @@ class MachineProductionReport extends Api
             ->where($where)
             ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
             ->order('a.sys_id asc, a.sczl_num asc')
-            ->page($page,$limit)
+//            ->page($page,$limit)
             ->select();
         $total2 = db()->table('db_sczl')->where($option)->count();
 
@@ -361,7 +340,7 @@ class MachineProductionReport extends Api
             ];
 
             //拆片联拼系数 拆片条小盒系数
-            $rows1 = db()->table('设备_产量计酬')->alias('a')
+            $rows1 = db()->table('设备_产量计酬')->alias('a')->cache(true)
                 ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数, 
             a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
@@ -404,7 +383,7 @@ class MachineProductionReport extends Api
                 ];
 
                 //拆片联拼系数 拆片条小盒系数
-                $rows1 = db()->table('设备_产量计酬')->alias('a')
+                $rows1 = db()->table('设备_产量计酬')->alias('a')->cache(true)
                     ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数, 
             a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
@@ -760,6 +739,10 @@ class MachineProductionReport extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db()->table('db_sczl')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
@@ -937,7 +920,7 @@ class MachineProductionReport extends Api
         }
 
         //拆片联拼系数 拆片条小盒系数
-        $rows1 = db()->table('设备_产量计酬')->alias('a')
+        $rows1 = db()->table('设备_产量计酬')->alias('a')->cache(true)
             ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数 as sczl_来料异常, 
             a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 

+ 15 - 11
application/api/controller/MachineProductionReportAdd.php

@@ -32,14 +32,14 @@ class MachineProductionReportAdd extends Api
             $this->error('请求方式错误');
         }
 
-        $rows = db()->table('db_sczladd')
+        $rows = db('db_sczladd')
             ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
             ->group('date')
             ->order('UniqId desc')
             ->limit(60)
             ->select();
 
-        $arr = db()->table('db_sczladd')
+        $arr = db('db_sczladd')
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[59]['date'])
             ->group('date, sys_id')
@@ -89,7 +89,7 @@ class MachineProductionReportAdd extends Api
 
         //来料异常 日定额 千件工价 补产标准
         //制程废 次品
-        $rows = db()->table('db_sczladd')
+        $rows = db('db_sczladd')
             ->field('LEFT(sczl_rq, 10) as sczl_rq, sczl_jtbh, 
             sczl_bzdh, CAST(sczl_设备运行工时 AS SIGNED) as sczl_设备运行工时, sczl_desc, 
             rtrim(sys_id) as sys_id, sys_rq, mod_rq, UniqId')
@@ -97,9 +97,9 @@ class MachineProductionReportAdd extends Api
             ->order('UniqId desc')
             ->page($page,$limit)
             ->select();
-        $total = db()->table('db_sczladd')->where($where)->count();
+        $total = db('db_sczladd')->where($where)->count();
 
-        $sb = db()->table('设备_基本资料')->column('设备编号, 设备名称');
+        $sb = db('设备_基本资料')->column('设备编号, 设备名称');
         foreach ($rows as $key=>$value){
             $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
             $rows[$key]['sczl_sbmc'] = trim($sb[$value['sczl_jtbh']]);
@@ -131,7 +131,7 @@ class MachineProductionReportAdd extends Api
             $this->error('参数错误');
         }
 
-        $rows = db()->table('db_sczladd')->alias('d')
+        $rows = db('db_sczladd')->alias('d')
             ->field('LEFT(d.sczl_rq, 10) as sczl_rq, d.sczl_jtbh, rtrim(g.设备名称) as 设备名称, d.sczl_bzdh, d.sczl_设备运行工时, d.sczl_desc')
             ->join('设备_基本资料 g', 'd.sczl_jtbh=g.设备编号')
             ->where('d.UniqId',$UniqId)
@@ -156,7 +156,7 @@ class MachineProductionReportAdd extends Api
         }else{
             $this->error('参数错误');
         }
-        $rows = db()->table('设备_基本资料')
+        $rows = db('设备_基本资料')
             ->field('rtrim(使用部门) as 使用部门, rtrim(设备编号) as jtbh, rtrim(设备名称) as 设备名称')
             ->where('设备编号|设备名称','like','%'.$sys_mc.'%')
             ->order('设备编号 asc')
@@ -201,10 +201,14 @@ class MachineProductionReportAdd extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db('db_sczladd')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_sczladd')->fetchSql(true)->insert($data);
+            $sql = db('db_sczladd')->fetchSql(true)->insert($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -251,7 +255,7 @@ class MachineProductionReportAdd extends Api
         //开启事务
         db()->startTrans();
         try{
-            $sql = db()->table('db_sczladd')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $sql = db('db_sczladd')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
@@ -285,7 +289,7 @@ class MachineProductionReportAdd extends Api
         //开启事务
         db()->startTrans();
         try{
-            $bool = db()->table('db_sczladd')->where('UniqId',$req['UniqId'])->delete();
+            $bool = db('db_sczladd')->where('UniqId',$req['UniqId'])->delete();
 
             // 提交事务
             db()->commit();
@@ -352,7 +356,7 @@ class MachineProductionReportAdd extends Api
             }
         }
 
-        $rows = db()->table('db_sczladd')->alias('a')
+        $rows = db('db_sczladd')->alias('a')
             ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号','left')
             ->field($field)
             ->where($where)

+ 24 - 27
application/api/controller/PackagingCountDocument.php

@@ -33,14 +33,14 @@ class PackagingCountDocument extends Api
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
-        $rows = db()->table('db_包装计件')
+        $rows = db()->table('db_包装计件')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
             ->group('date')
             ->order('UniqId desc')
             ->limit(30)
             ->select();
 
-        $arr = db()->table('db_包装计件')
+        $arr = db()->table('db_包装计件')->cache(true,300)
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
             ->where('sys_rq','>=',$rows[29]['date'])
             ->group('date, sys_id')
@@ -297,17 +297,7 @@ class PackagingCountDocument extends Api
     /**
      * 新增
      * @ApiMethod (POST)
-     * @param string 'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
-    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
-    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
-    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
-    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
-    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
-    'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
-    'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
-    'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
-    'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
-    'sczl_desc'
+     * @param string 'sys_id'
      */
     public function add()
     {
@@ -337,6 +327,10 @@ class PackagingCountDocument extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db()->table('db_包装计件')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
@@ -359,13 +353,7 @@ class PackagingCountDocument extends Api
     /**
      * 修改
      * @ApiMethod (POST)
-     * @param string 'UniqId','sczl_rq',
-    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
-    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
-    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
-    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
-    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
-    'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
+     * @param string 'UniqId',
      */
     public function edit()
     {
@@ -656,17 +644,26 @@ class PackagingCountDocument extends Api
             }
         }
         $writer = new Xlsx($spreadsheet);
-// 将 Excel 文件转换为二进制数据
-        $excelData = $writer->writeToString();
+        $folderPath = 'uploads/folder';
 
-// 返回 Excel 数据给前端
-        $this->success('成功', $excelData);
+        if (!is_dir($folderPath)) {
+            mkdir($folderPath, 0777, true);
+            $tempPath = $folderPath .'/'. $file_name.'.xlsx';
+        } else {
+            $tempPath = $folderPath .'/'. $file_name.'.xlsx';
+        }
 
-        header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
-        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+//        header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
+//        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+//        $writer->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
+        $writer->save($tempPath);
 
-        $writer->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
+        // 获取完整url
+        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
+        $host = $_SERVER['HTTP_HOST'];
+        $siteUrl = $protocol . '://' . $host .'/'.$tempPath ;
 
+        $this->success('成功', $siteUrl);
     }
 
 }

+ 6 - 14
application/api/controller/PackagingProcessOutput.php

@@ -263,13 +263,7 @@ class PackagingProcessOutput extends Api
      * 新增
      * @ApiMethod (POST)
      * @param string 'sys_id','sczl_rq',
-    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
-    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
-    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
-    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
-    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
-    'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
-     */
+    */
     public function add()
     {
         if(!$this->request->isPost()){
@@ -294,6 +288,10 @@ class PackagingProcessOutput extends Api
         }
         $data['sys_rq'] = date('Y-m-d H:i:s');
 
+        //查询UniqId
+        $UniqId = db()->table('db_包装产量预报')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
         //开启事务
         db()->startTrans();
         try{
@@ -316,13 +314,7 @@ class PackagingProcessOutput extends Api
     /**
      * 修改
      * @ApiMethod (POST)
-     * @param string 'UniqId','sczl_rq',
-    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
-    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
-    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
-    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
-    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
-    'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
+     * @param string 'UniqId',
      */
     public function edit()
     {