Przeglądaj źródła

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

曹鹤洋 1 rok temu
rodzic
commit
4f56921328

+ 70 - 63
application/api/controller/Facility.php

@@ -31,17 +31,17 @@ class Facility extends Api
             $this->error('请求错误');
         }
         $data = [];
-        $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
+        $department = \db('设备_基本资料')->distinct(true)->column('使用部门');
         $date = date('Y-m-d H:i:s',time()-3888000);
         if (empty($department)){
             $this->error('未获取到机台数据');
         }
         foreach ($department as $value){
             if (rtrim($value) !== '研发中心'){
-                $machine = Db::table('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
+                $machine = \db('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
                 foreach ($machine as $kk=>$vv){
                     if ($vv['设备编号'] !== 'ZH01#'){
-                        $date = Db::table('设备_产量计酬')
+                        $date = \db('设备_产量计酬')
                             ->where('sczl_jtbh',$vv['设备编号'])
 //                            ->where('sczl_rq','> time',$date)
                             ->distinct(true)
@@ -73,7 +73,7 @@ class Facility extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
-        $machine = input('machine').'#';
+        $machine = input('machine');
         $date = input('date');
         $where = [
             'sczl_jtbh' => $machine,
@@ -87,15 +87,15 @@ class Facility extends Api
         sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
         sczl_rate8,sczl_rate9,sczl_rate10';
         //机台信息
-        $machineDetail = Db::table('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
+        $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
         //工单编号
-        $Gd_gdbh = Db::table('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
+        $Gd_gdbh = \db('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
         //产品名称
-        $productName = Db::table('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->column('Gd_cpmc','Gd_gdbh');
+        $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->column('Gd_cpmc','Gd_gdbh');
         //组员信息
-        $list = Db::table('设备_产量计酬')->where($where)->field($field)->select();
-        $totalA = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
-        $totalB = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
+        $list = \db('设备_产量计酬')->where($where)->field($field)->select();
+        $totalA = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
+        $totalB = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
         if (empty($list)){
             $this->error('未找到机台数据');
         }
@@ -110,7 +110,7 @@ class Facility extends Api
             $list[$key]['日定额'] = $machineDetail['日定额'];
             for ($i=1;$i<11;$i++){
                 if (isset($value['sczl_bh'.$i])){
-                    $name = Db::table('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
+                    $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
                     if (isset($name['name'])){
                         $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
                     }
@@ -144,33 +144,31 @@ class Facility extends Api
         if (empty($machine) || empty($date)){
             $this->error('参数错误');
         }
-//        $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
-//        $startId = $last_id['UniqId']-1000000;
         $where = [
             '设备编号' => $machine,
             '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
             '类别' => ['in',['IPQC检验','机台检验']],
 //            'UniqId' => ['>',$startId],
         ];
-        $begin = Db::table('制程检验_记录')->where($where)->field('UniqId')->find();
-        $end = Db::table('制程检验_记录')->where($where)->order('UniqId desc')->field('UniqId')->find();
+        $begin = \db('制程检验_记录')->where($where)->field('UniqId')->find();
+        $end = \db('制程检验_记录')->where($where)->order('UniqId desc')->field('UniqId')->find();
         $where['UniqId'] = ['between',[$begin['UniqId'],$end['UniqId']+1]];
         //检验项目筛选
-        $itemA = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','A班')->column('rtrim(检验项目)');
-        $itemB = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','B班')->column('rtrim(检验项目)');
+        $itemA = \db('制程检验_记录')->where($where)->distinct(true)->where('班组编号','A班')->column('rtrim(检验项目)');
+        $itemB = \db('制程检验_记录')->where($where)->distinct(true)->where('班组编号','B班')->column('rtrim(检验项目)');
         //检验时间
-        $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
+        $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
         foreach ($InspectionTime as $k=>$v){
             $InspectionTime[$k] = date('H:i',strtotime($v));
         }
         //检测记录详情
         $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
-        $nameDetailA = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','A班')->find();
-        $nameDetailB = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','B班')->find();
+        $nameDetailA = \db('制程检验_记录')->where($where)->field($field)->where('班组编号','A班')->find();
+        $nameDetailB = \db('制程检验_记录')->where($where)->field($field)->where('班组编号','B班')->find();
         $list = $data1 = $data2 = [];
         //A班检测数据
         foreach ($itemA as $key=>$value){
-            $SubmissionTime = Db::table('制程检验_记录')->where($where)
+            $SubmissionTime = \db('制程检验_记录')->where($where)
                 ->where('班组编号','A班')
                 ->where('检验项目',$value)
                 ->where('检验结果','合格')
@@ -190,7 +188,7 @@ class Facility extends Api
         }
         //B班数据详情
         foreach ($itemB as $key=>$value){
-            $SubmissionTime = Db::table('制程检验_记录')->where($where)
+            $SubmissionTime = \db('制程检验_记录')->where($where)
                 ->where('班组编号','B班')
                 ->where('检验项目',$value)
                 ->where('检验结果','合格')
@@ -367,16 +365,16 @@ class Facility extends Api
         if (empty($workOrder)){
             $this->error('参数错误');
         }
-//        $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+//        $lastUniqid = \db('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
 //        $startUniqid = $lastUniqid['UniqId']-100000;
         //右边工艺及完成数量
-        $Process = Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+        $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
 //            ->where('UniqId','>',$startUniqid)
             ->distinct(true)->order('sczl_gxh')
             ->column('sczl_gxh');
         $data = [];
         foreach ($Process as $k=>$v){
-            $res= Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+            $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
 //                ->where('UniqId','>',$startUniqid)
                 ->where('sczl_gxh',$v)
                 ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
@@ -385,7 +383,7 @@ class Facility extends Api
                 $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
             }
             $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
-            $processList['completed'] = Db::table('设备_产量计酬')
+            $processList['completed'] = \db('设备_产量计酬')
                 ->where('sczl_gdbh',$workOrder)
 //                ->where('UniqId','>',$startUniqid)
                 ->where('sczl_gxh',$v)
@@ -423,12 +421,12 @@ class Facility extends Api
         rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
         rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
         rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
-        $team = Db::table('设备_产量计酬')
+        $team = \db('设备_产量计酬')
             ->where('sczl_jtbh',$machine)
             ->field($field)
             ->order('UniqId desc')
             ->find();
-        $list = Db::table('设备_班组资料')->where($where)->field($field)->select();
+        $list = \db('设备_班组资料')->where($where)->field($field)->select();
         $data = [];
         foreach ($list as $k=>$v){
             if ($team == $v){
@@ -440,7 +438,7 @@ class Facility extends Api
             $data[$k]['班组号'] = $v['班组号'];
             for ($i=1;$i<11;$i++){
                 if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
-                    $name = Db::table('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
+                    $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
                     $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
                 }
             }
@@ -471,9 +469,9 @@ class Facility extends Api
         if (empty($machine) || empty($workOrder) || empty($team)){
             $this->error('参数错误');
         }
-//        $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
+//        $lastUniqid = \db('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
 //        $startUniqid = $lastUniqid['UniqId']-100000;
-        $name = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
+        $name = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
         $where = [
 //            'UniqId' => ['>',$startUniqid],
             'sczl_gdbh' => $workOrder,
@@ -486,7 +484,7 @@ class Facility extends Api
         rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
         rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
         rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
-        $list = Db::table('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
+        $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
         if (empty($list)){
             $this->error('未找到生产记录');
         }
@@ -503,7 +501,7 @@ class Facility extends Api
         SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
         SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
         SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
-        $total = Db::table('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
+        $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
         $total[0]['版数'] = count($list);
         $list['total'] = $total[0];
         $this->success('成功',$list);
@@ -531,7 +529,7 @@ class Facility extends Api
         if (empty($machine) || empty($workOrder) || empty($team)){
             $this->error('参数错误');
         }
-//        $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
+//        $last_id = \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
 //        $startId = $last_id['UniqId']-100000;
         $where = [
             '设备编号' => $machine,
@@ -541,19 +539,19 @@ class Facility extends Api
 //            'UniqId' => ['>',$startId],
         ];
         //检验项目筛选
-        $item = Db::table('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
+        $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
         //检验时间
-        $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
+        $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
         foreach ($InspectionTime as $k=>$v){
             $InspectionTime[$k] = date('H:i',strtotime($v));
         }
         //检测记录详情
         $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
-        $nameDetail = Db::table('制程检验_记录')->where($where)->field($field)->find();
+        $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
         $data = [];
         //检测数据
         foreach ($item as $key=>$value){
-            $SubmissionTime = Db::table('制程检验_记录')->where($where)
+            $SubmissionTime = \db('制程检验_记录')->where($where)
                 ->where('检验项目',$value)
                 ->where('检验结果','合格')
                 ->field('rtrim(提交时间) as 提交时间')
@@ -590,7 +588,7 @@ class Facility extends Api
         rtrim(sczl_bh10) as sczl_bh10,rtrim(sczl_rate1) as sczl_rate1,rtrim(sczl_rate2) as sczl_rate2,rtrim(sczl_rate3) as sczl_rate3,rtrim(sczl_rate4) as sczl_rate4,
         rtrim(sczl_rate5) as sczl_rate5,rtrim(sczl_rate6) as sczl_rate6,rtrim(sczl_rate7) as sczl_rate7,rtrim(sczl_rate8) as sczl_rate8,
         rtrim(sczl_rate9) as sczl_rate9,rtrim(sczl_rate10) as sczl_rate10';
-        $TeamList = Db::table('设备_班组资料')->where('UniqId',$data['ID'])->field($field)->find();
+        $TeamList = \db('设备_班组资料')->where('UniqId',$data['ID'])->field($field)->find();
 
     }
 
@@ -605,7 +603,7 @@ class Facility extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
-        $list = Db::table('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
+        $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
         if (empty($list)){
             $this->error('未找到机台编号');
         }
@@ -633,7 +631,7 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $res = Db::table('设备_班组资料')
+        $res = \db('设备_班组资料')
             ->where('UniqId',$param['UniqId'])
             ->delete();
         if ($res !== false){
@@ -676,10 +674,13 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-//        $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
-//        $startId = $last_id['UniqId']-100000;
         $date = date('Y-m-d H:i:s',time());
-        $startTime = date('Y-m-d 08:30:00',time());
+        if (empty($param['start'])){
+            $startTime = date('Y-m-d 08:30:00',time());
+        }else{
+            $startTime = $param['start'];
+        }
+
         if ($date<$startTime){
             $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
         }
@@ -692,13 +693,11 @@ class Facility extends Api
         $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
         rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
         rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
-        $list = Db::table('制程检验_记录')->where($where)
-//            ->where('UniqId','>',$startId)
+        $list = \db('制程检验_记录')->where($where)
             ->field($filed)
-//            ->fetchSql(true)
             ->select();
         if (empty($list)){
-            $this->error('未找到该工单当前班次巡检记录');
+            $this->success('',[]);
         }
         foreach ($list as $key=>$value){
             $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
@@ -753,9 +752,9 @@ class Facility extends Api
             'sys_id' => '',
             'sys_rq' => date('Y-m-d H:i:s',time()),
             'mod_rq' => '',
-            'UniqId' => Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
+            'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
         ];
-        $sql = Db::table('制程检验_记录')->fetchSql(true)->insert($data);
+        $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -779,12 +778,12 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $list = Db::table('设备_点检项目')
+        $list = \db('设备_点检项目')
             ->where('适用机型','LIKE','%;'.$param['machine'].';%')
             ->distinct(true)
             ->column('部件名称','部件编号');
         if (empty($list)){
-            $this->error('未找到检验项目');
+            $this->success('');
         }
         $this->success('成功',$list);
     }
@@ -807,12 +806,12 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $list = Db::table('设备_点检项目')
+        $list = \db('设备_点检项目')
             ->where('部件名称',$param['unitName'])
             ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
             ->select();
         if (empty($list)){
-            $this->error('未找到检测项目');
+            $this->success('未找到检测项目');
         }
         $this->success('成功',$list);
     }
@@ -836,10 +835,15 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $lastId = 10000000;
+        $lastNumber =  \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
+        if ((int)$lastNumber>10000000){
+            $lastId = $lastNumber;
+        }else{
+            $lastId = 10000000;
+        }
         $row = [];
         foreach ($param as $key=>$value){
-            $unitCode = Db::table('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
+            $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
             $row[$key] = [
                 '日期' => date('Y-m-d 00:00:00',time()),
                 '班组编号' => $value['team'],
@@ -858,7 +862,7 @@ class Facility extends Api
             ];
 
         }
-        $sql = Db::table('设备_点检记录')->fetchSql(true)->insertAll($row);
+        $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -889,7 +893,7 @@ class Facility extends Api
                 WHERE a.YB_Cpdh = '{$productCode}'";
         $res = Db::query($sql);
         if (empty($res)){
-            $this->error('未找到该产品印版资料');
+            $this->success('');
         }
         $this->success('成功',$res);
     }
@@ -938,7 +942,7 @@ class Facility extends Api
                 ORDER BY a.`存货编码`";
         $list = Db::query($sql);
         if (empty($list)){
-            $this->error('未找到印版');
+            $this->success('');
         }
         $this->success('成功',$list);
     }
@@ -952,7 +956,7 @@ class Facility extends Api
         }
         $date = date('Y-m-d 00:00:00',time()-3888000);
         $nowTime = date('Y-m-d H:i:s',time());
-        $list = Db::table('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
+        $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
         if (empty($list)){
             $this->error('失败');
         }
@@ -1002,13 +1006,13 @@ class Facility extends Api
         rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
         rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
         rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
-        $list = Db::table('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
+        $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
         if (empty($list)){
             $this->error('未找到该条清场记录');
         }
         $list['日期'] = date('Y-m-d',strtotime($list['日期']));
-        $list['印件名称A'] = Db::table('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
-        $list['印件名称B'] = Db::table('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+        $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+        $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
         $this->success('成功',$list);
     }
 
@@ -1024,7 +1028,10 @@ class Facility extends Api
         }
         $date = date('Y-m-d 00:00:00',time()-3888000);
         $nowTime = date('Y-m-d H:i:s',time());
+        $where = [
+            '日期' =>['between',[$nowTime,$date]],
 
+        ];
     }
 
     //

+ 27 - 21
application/api/controller/Manufacture.php

@@ -49,14 +49,14 @@ class Manufacture extends Api
         rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
         rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
         rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
-        $list = Db::table('工单_基本资料')->where($where)->field($field)->limit(500)->order('Uniqid desc')->select();
+        $list = \db('工单_基本资料')->where($where)->field($field)->limit(500)->order('Uniqid desc')->select();
         if (empty($list)){
             $this->error('失败');
         }
         foreach ($list as $key=>$value){
             $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
             $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
-            $number = Db::table('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
+            $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
             if ($number === 0){
                 $list[$key]['status'] = 0;
             }else{
@@ -91,7 +91,7 @@ class Manufacture extends Api
         $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
         rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
         rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
-        $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
+        $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
         if (empty($list)){
             $this->success('',[]);
         }
@@ -138,7 +138,7 @@ class Manufacture extends Api
         rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
         rtrim(yj_Dw) as  投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
         rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
-        $list = Db::table('工单_印件资料')->where($where)->field($field)->select();
+        $list = \db('工单_印件资料')->where($where)->field($field)->select();
         if (empty($list)){
             $this->error('失败');
         }
@@ -311,16 +311,16 @@ class Manufacture extends Api
             $this->error('请求错误');
         }
         $data = [];
-        $department = Db::table('设备_基本资料')->distinct(true)->cache(true)->column('使用部门');
+        $department = \db('设备_基本资料')->distinct(true)->cache(true)->column('使用部门');
         if (empty($department)){
             $this->error('为获取到机台数据');
         }
         foreach ($department as $value){
             if (rtrim($value) !== '研发中心'){
-                $benchClass = Db::table('设备_基本资料')->where('使用部门',$value)->distinct(true)->cache(true)->column('设备编组');
+                $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->cache(true)->column('设备编组');
                 foreach ($benchClass as $v){
                     if (rtrim($v) !== ''){
-                        $machine = Db::table('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
+                        $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
                         foreach ($machine as $kk=>$vv){
                             $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
                         }
@@ -351,7 +351,7 @@ class Manufacture extends Api
         if (empty($workOrder) || empty($status)){
             $this->error('参数错误');
         }
-        $sql = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
+        $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -381,7 +381,7 @@ class Manufacture extends Api
             'Gy0_gdbh' => $data['workOrder'],
             'Gy0_gxh'  => $data['processCode']
         ];
-        $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
+        $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -417,12 +417,12 @@ class Manufacture extends Api
             'Gy0_yjno' => $data['printCode'],
             'Gy0_gxh'  => $data['processCode']
         ];
-        $lastTime = Db::table('工单_工艺资料')
+        $lastTime = \db('工单_工艺资料')
             ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
             ->field('rtrim(Gy0_sj2) as sj2')
             ->order('Gy0_sj2 desc')
             ->find();
-        $row = Db::table('工单_工艺资料')
+        $row = \db('工单_工艺资料')
             ->where($where)
             ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
             ->find();
@@ -430,7 +430,7 @@ class Manufacture extends Api
             $this->error('未找到该工单工艺资料');
         }
         $endTime = date('Y-m-d H:i:s',strtotime($lastTime['sj2']) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
-        $sql = Db::table('工单_工艺资料')
+        $sql = \db('工单_工艺资料')
             ->where($where)
             ->fetchSql(true)
             ->update(['Gy0_sj1'=>$lastTime['sj2'],'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
@@ -470,18 +470,18 @@ class Manufacture extends Api
             'Gy0_gxh'  => $data['processCode']
         ];
         $machine = $where['Gy0_sbbh'];
-        $endTime = Db::table('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
+        $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
         if (empty($endTime)){
             $this->error('未找到该工序');
         }
         if ($endTime <= '1900-01-01 00:00:00' || $endTime >= '2099-01-01 00:00:00'){
             $this->error('该工单不是制程中工单');
         }
-        $sql = Db::table('工单_工艺资料')
+        $sql = \db('工单_工艺资料')
             ->where($where)
             ->fetchSql(true)
             ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]);
-        $row = Db::table('工单_工艺资料')
+        $row = \db('工单_工艺资料')
             ->where($where)
             ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
             ->find();
@@ -523,7 +523,7 @@ class Manufacture extends Api
         ];
         $workOrder = $where['Gy0_gdbh'];
         $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间,rtrim(UniqId) as UniqId';
-        $list = Db::table('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
+        $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
         if (empty($list)){
             $this->error('未找到该工单工艺资料');
         }
@@ -579,7 +579,7 @@ class Manufacture extends Api
             }else{
                 $endTime = $value['PD_WG'];
             }
-            $sql = Db::table('工单_工艺资料')
+            $sql = \db('工单_工艺资料')
                 ->where('UniqId',$value['UniqId'])
                 ->fetchSql(true)
                 ->update(['PD_WG'=>$endTime]);
@@ -609,7 +609,7 @@ class Manufacture extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
-        $list = Db::table('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
+        $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
         if (empty($list)){
             $this->error('未找到班次数据');
         }
@@ -652,7 +652,7 @@ class Manufacture extends Api
         rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,rtrim(Gy0_班次安排) as 班次安排,rtrim(工序备注) as 排单备注,
         rtrim(Gy0_最早开工时间) as 最早开工时间,rtrim(Gy0_sj1) as 计划开工时间,rtrim(Gy0_sj2) as 计划完工时间,rtrim(Gy0_yjno) as yjno,
         rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_ls) as ls,rtrim(UniqId) as UniqId';
-        $list = Db::table('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
+        $list = \db('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
         if (empty($list)){
             $this->error('未找到该机台制程中产品');
         }
@@ -711,7 +711,7 @@ class Manufacture extends Api
                 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
                 'Gy0_sj2' => date('Y-m-d HY-m-d',strtotime(($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600)),
             ];
-            $sql = Db::table('工单_工艺资料')
+            $sql = \db('工单_工艺资料')
                 ->where('UniqId',$value['UniqId'])
                 ->fetchSql(true)
                 ->update($data);
@@ -727,8 +727,14 @@ class Manufacture extends Api
         }
     }
 
-    //机台显示工单
 
+    /**
+     * 机台工单展示
+     * @ApiMethod ()
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
     public function MachineWorkOrderList()
     {
         if ($this->request->isGet() === false){

+ 67 - 66
application/api/controller/OrderSuperLoss.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use think\Cache;
 use \think\Request;
 use \think\Db;
 /**
@@ -30,52 +31,52 @@ class OrderSuperLoss extends Api
         if (Request::instance()->isGet() == false) {
             $this->error('非法请求');
         }
-        $sql = "SELECT DISTINCT(Gd_gdbh),`年月`,rtrim(`客户编号`) as 客户编号,rtrim(`客户名称`) as 客户名称 FROM `rec_月度废品汇总` 
+        $is_hav_cache = Cache::get('OrderSuperLoss/getTab');
+        if ($is_hav_cache === false){
+            $sql = "SELECT DISTINCT(Gd_gdbh),`年月`,rtrim(`客户编号`) as 客户编号,rtrim(`客户名称`) as 客户名称 FROM `rec_月度废品汇总` 
                 WHERE STR_TO_DATE(`年月`, '%Y%m') >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) order by 年月 desc,客户编号 asc";
-        $data = Db::query($sql);
-
-        $outputArray = [];
-
-        foreach ($data as $item) {
-            $yearMonth = $item['年月'];
-
-            if (!isset($outputArray[$yearMonth])) {
-                // If key doesn't exist in output array, initialize it
-                $outputArray[$yearMonth] = [];
-            }
-
-            // Check if the customer already exists in the current yearMonth array
-            $existingCustomerIndex = null;
-            foreach ($outputArray[$yearMonth] as $index => $customer) {
-                if ($customer['客户编号'] === $item['客户编号']) {
-                    $existingCustomerIndex = $index;
-                    break;
+            $data = Db::query($sql);
+            $outputArray = [];
+            foreach ($data as $item) {
+                $yearMonth = $item['年月'];
+                if (!isset($outputArray[$yearMonth])) {
+                    // If key doesn't exist in output array, initialize it
+                    $outputArray[$yearMonth] = [];
+                }
+                // Check if the customer already exists in the current yearMonth array
+                $existingCustomerIndex = null;
+                foreach ($outputArray[$yearMonth] as $index => $customer) {
+                    if ($customer['客户编号'] === $item['客户编号']) {
+                        $existingCustomerIndex = $index;
+                        break;
+                    }
+                }
+                if ($existingCustomerIndex !== null) {
+                    // If customer exists, increment the total
+                    $outputArray[$yearMonth][$existingCustomerIndex]['total']++;
+                } else {
+                    // If customer doesn't exist, add a new entry
+                    $outputArray[$yearMonth][] = [
+                        '客户名称' => $item['客户名称'],
+                        '客户编号' => $item['客户编号'],
+                        'total' => 1,
+                    ];
                 }
             }
-
-            if ($existingCustomerIndex !== null) {
-                // If customer exists, increment the total
-                $outputArray[$yearMonth][$existingCustomerIndex]['total']++;
-            } else {
-                // If customer doesn't exist, add a new entry
-                $outputArray[$yearMonth][] = [
-                    '客户名称' => $item['客户名称'],
-                    '客户编号' => $item['客户编号'],
-                    'total' => 1,
-                ];
-            }
-        }
-        // 遍历每个年月的数组
-        $list = [];
-        foreach ($outputArray as $yearMonth => $orders) {
-            $totalOrders = 0;
-
-            // 遍历每个订单,累加订单数量
-            foreach ($orders as $order) {
-                $totalOrders += $order['total'];
+            // 遍历每个年月的数组
+            $list = [];
+            foreach ($outputArray as $yearMonth => $orders) {
+                $totalOrders = 0;
+                // 遍历每个订单,累加订单数量
+                foreach ($orders as $order) {
+                    $totalOrders += $order['total'];
+                }
+                // 输出每个年月的订单数量
+                $list[$yearMonth.'-'.$totalOrders] = $orders;
             }
-            // 输出每个年月的订单数量
-            $list[$yearMonth.'-'.$totalOrders] = $orders;
+            Cache::set('OrderSuperLoss/getTab',$list,86400);
+        }else{
+            $list = Cache::get('OrderSuperLoss/getTab');
         }
         $this->success('请求成功',$list);
     }
@@ -146,7 +147,7 @@ class OrderSuperLoss extends Api
                         UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$value['Gd_gdbh']}') AS combined_result";
             $gxh_arr = Db::query($gxh_sql);
             $gxh_values = array_column($gxh_arr, 'sczl_gxh');
-            $gy_data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
+            $gy_data =db('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
             $arr = [];
             $plan_loss = [];//工单计划损耗
             foreach ($gy_data as $k=>$v){
@@ -162,15 +163,15 @@ class OrderSuperLoss extends Api
             $data[$key]['reward_rate'] = '';
             $data[$key]['reward_money'] = '';
             //制程废品
-            $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
+            $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
             $data[$key]['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $value['yj_ls'];//制程废品
             $data[$key]['废品合计'] = $data[$key]['zcfp'] + $value['废品合计'];//废品合计
             $data[$key]['intangible_loss'] = $value['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $data[$key]['废品合计'];//工单无形损
             //材料废
-            $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
+            $waste_l =db('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
             $data[$key]['material_waste'] = $waste_l[0]['废品数量'];
             //零头处理
-            $waste_w =  Db::name('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
+            $waste_w = db('rec_月度废品汇总')->where('Gd_gdbh',$value['Gd_gdbh'])->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
             $data[$key]['minor_processing'] = $waste_w[0]['废品数量'];
             //外发废
             $out_sql = "SELECT 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,
@@ -260,7 +261,7 @@ class OrderSuperLoss extends Api
         }
         $order = $params['order'];
         $field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
-        $data = Db::name('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
+        $data =db('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
         //查出成品数量及日期
         $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' GROUP BY jjcp_gdbh";
         $cp_data = Db::query($cp_sql);
@@ -272,7 +273,7 @@ class OrderSuperLoss extends Api
                         UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}') AS combined_result";
         $gxh_arr = Db::query($gxh_sql);
         $gxh_values = array_column($gxh_arr, 'sczl_gxh');
-        $gy_data = Db::name('工单_工艺资料')
+        $gy_data =db('工单_工艺资料')
             ->alias('a')
             ->field([
                 'a.Gy0_yjno', 'a.Gy0_gxh', 'RTRIM(a.Gy0_gxmc) as Gy0_gxmc','RTRIM(a.Add_gxmc) as Add_gxmc', 'a.Gy0_ls', 'a.Gy0_计划接货数',
@@ -298,22 +299,22 @@ class OrderSuperLoss extends Api
         $real_rate = $cp_data[0]['cp_sl'] / ($data['实际投料'] * 10000) *100;
         $data['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
         //制程废品
-        $zzfp_data = Db::name('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
+        $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
         //联数
-        $ls = Db::name('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
+        $ls =db('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
         //制程废品*ls
         $data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls;
         //废品数量
-        $waste = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->field('SUM(废品数量) as 废品合计')->select();
+        $waste =db('rec_月度废品汇总')->where('Gd_gdbh',$order)->field('SUM(废品数量) as 废品合计')->select();
         //废品合计
         $waste_total = $data['zcfp'] + $waste[0]['废品合计'];
         //工单无形损
         $data['intangible_loss'] = $data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total;
         //材料废
-        $waste_l = Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
+        $waste_l =db('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%L%')->field('SUM(废品数量) as 废品数量')->select();
         $data['material_waste'] = $waste_l[0]['废品数量'];
         //零头处理
-        $waste_w =  Db::name('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
+        $waste_w = db('rec_月度废品汇总')->where('Gd_gdbh',$order)->where('废品类别','like','%M%')->field('SUM(废品数量) as 废品数量')->select();
         $data['minor_processing'] = $waste_w[0]['废品数量'];
         //外发废
         $out_sql = "SELECT 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,
@@ -350,7 +351,7 @@ class OrderSuperLoss extends Api
         $data['waste_out'] = array_sum($list);//外发废
         //质检废
         $data['waste_quality'] =  array_sum($quality);
-        $plan_total = Db::name('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
+        $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
 //        halt($plan_total);
         //按工序打印
         if ($params['type'] == 1){
@@ -412,7 +413,7 @@ class OrderSuperLoss extends Api
         }
         $order = $params['order'];
         $field = 'Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc,Gy0_rate0,Gy0_rate1,损耗系数,无形损承担比例 as loss_one,超节损承担比例 as loss_two,超节损核算单价 as loss_thr,UniqId';
-        $data = Db::name('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
+        $data =db('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
         $this->success('请求成功',$data);
     }
     /**
@@ -434,7 +435,7 @@ class OrderSuperLoss extends Api
             $data['无形损承担比例'] = $value['loss_one'];
             $data['超节损承担比例'] = $value['loss_two'];
             $data['超节损核算单价'] = $value['loss_thr'];
-            $sql = Db::name('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
+            $sql =db('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
             $res = Db::query($sql);
             if ($res !== false){
                 $i++;
@@ -459,7 +460,7 @@ class OrderSuperLoss extends Api
         if (!isset($params['order']) || empty($params['order'])) {
             $this->error('参数错误');
         }
-        $data = Db::name('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
+        $data =db('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
         $this->success('请求成功',$data);
     }
     /**
@@ -483,7 +484,7 @@ class OrderSuperLoss extends Api
         }
         $where['Yj_gdbh'] = $params['order'];
         $where['yj_Yjno'] = $params['yj_yjno'];
-        $res = Db::name('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
+        $res =db('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
         if ($res !== false){
             $this->success('更新成功');
         }else{
@@ -507,7 +508,7 @@ class OrderSuperLoss extends Api
         $search = $params['year'].'.'.$params['month'];
         $field = "a.Gd_gdbh,rtrim(c.yj_yjdh) as yj_yjdh,c.yj_Yjno, c.yj_ks,c.yj_ls,rtrim(c.yj_zzdh) as yj_zzdh,
                   rtrim(b.BOM_物料名称) as BOM_物料名称,rtrim(c.yj_tlgg) as yj_tlgg,rtrim(b.BOM_投料单位) as BOM_投料单位,a.订单数量,c.yj_平张投料, b.BOM_实际用量,a.实际投料,a.投料确认,a.UniqId";
-        $data = Db::name('工单_基本资料')->alias('a')
+        $data =db('工单_基本资料')->alias('a')
             ->join('工单_印件资料 c','a.Gd_gdbh = c.Yj_Gdbh','left')
             ->join('工单_bom资料 b','c.Yj_Gdbh = b.BOM_工单编号 AND c.yj_zzdh = b.BOM_物料编码','left')
             ->where('a.投料确认','like','%'.$search.'%')
@@ -549,9 +550,12 @@ class OrderSuperLoss extends Api
         $i = 0;
         foreach ($params as $key=>$value){
             if (!empty($value['number'])){
-                $info = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
-                $res = Db::name('工单_基本资料')->where('UniqId',$value['UniqId'])->setField('实际投料',$value['number']);
-                $yjRes = Db::name('工单_印件资料')->where('Yj_Gdbh',$info)->setField('yj_实际投料',$value['number']);
+                $info = db('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
+                $res_sql = db('工单_基本资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->setField('实际投料',$value['number']);
+                $res = Db::query($res_sql);
+                $data['yj_实际投料'] = $value['number'];
+                $yj_sql =db('工单_印件资料')->where('Yj_Gdbh',$info)->fetchSql(true)->update($data);
+                $yjRes = Db::query($yj_sql);
                 if (!$res && !$yjRes){
                     $i++;
                 }
@@ -584,10 +588,8 @@ class OrderSuperLoss extends Api
                 LEFT JOIN db_sczl c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
                 WHERE a.Gy0_gdbh = '{$order}' GROUP BY a.Gy0_gxh";
         $data = Db::query($sql);
-//        halt($data);
         //手检数据
-        $handData = Db::name('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
-//        halt($handData);
+        $handData =db('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
         //包装及成品防护数据
         $sql = "SELECT sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,rtrim(sczl_gxmc1) as sczl_gxmc1,rtrim(sczl_gxmc2) as sczl_gxmc2,
                 rtrim(sczl_gxmc3) as sczl_gxmc3,rtrim(sczl_gxmc4) as sczl_gxmc4,rtrim(sczl_gxmc5) as sczl_gxmc5,rtrim(sczl_gxmc6) as sczl_gxmc6,
@@ -625,7 +627,6 @@ class OrderSuperLoss extends Api
             $sumArray[$key] += $product;
         }
         $handGxh = substr($handData[0]['sczl_gxh'],-2);
-//        halt($sumArray['包装']);
         foreach ($data as $key=>$item){
             $data[$key]['折算车头产量'] = round($item['Gy0_计划接货数']/$item['Gy0_ls']);
             $data[$key]['制程废品率'] = '';

+ 6 - 0
application/api/controller/Process.php

@@ -153,12 +153,18 @@ class Process extends Api
             $parentCode = $params['code'];
         }
         $list = db('dic_lzsh')->where('sys_bh',$parentCode)->field('Key_')->find();
+        $uniqId = db('dic_lzsh')->order('UniqId desc')->value('UniqId');
+        $sql = "SELECT MAX(CAST(SUBSTRING(Key_, 1, LENGTH(Key_) - 1) AS UNSIGNED)) AS max_value FROM dic_lzsh";
+        $key = Db::query($sql);
         $data = [];
         $data['sys_bh'] = $params['code'];
         $data['Parent'] = empty($list)? '0_':$list['Key_'];
         $data['sys_mc'] = $params['name'];
         $data['sys_rate0'] = $params['sys_rate0'];
         $data['sys_rate1'] = $params['sys_rate1'];
+        $data['启用状态'] = 1;
+        $data['Key_'] = ($key[0]['max_value']+1).'_';
+        $data['UniqId'] = $uniqId+1;
         if (!empty($params['remark'])){
             $data['适用机型'] = $params['remark'];
         }

+ 86 - 73
application/api/controller/WorkOrder.php

@@ -28,32 +28,44 @@ class WorkOrder extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
-        $where = [
-            '行号' => '1',
-        ];
-        $ClientList = Db::table('erp_客户供应商')->where('类型','客户')->cache(true)->column('简称','编号');
         //获取总计划中数量和总生产中数量
-        $productingAll = Db::table('工单_基本资料')->where('gd_statu','2-生产中')->cache(true)->count();
-        $progressAll = Db::table('工单_基本资料')->where('gd_statu','3-计划中')->cache(true)->count();
+        $productingAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
+        $progressAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
         $data = [
             'productingAll' => $productingAll,
             'progressAll' => $progressAll
         ];
-        //按客户编号查询生产中,计划中数量
-        foreach ($ClientList as $key=>$value){
-            $order = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->cache(true)->count();
-            if ($order !== 0){
-                $productIng = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where($where)->where('gd_statu','2-生产中')->cache(true)->count();
-                $proGress = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where($where)->where('gd_statu','3-计划中')->cache(true)->count();
-                $code = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->field('rtrim(成品代号) as 成品代号')->cache(true)->find();
-                $Detail = [
-                    'Gd_khdh' => substr($code['成品代号'],0,4),
-                    'Gd_khmc' => rtrim($value),
-                    'producting' => $productIng = 0?'':"生产中:".$productIng,
-                    'progress' => $proGress=0?'':'计划中:'.$proGress,
-                ];
-                $menu = $Detail['Gd_khdh'].'【'.$Detail['producting'].$Detail['progress'].'】'.'【'.$Detail['Gd_khmc'].'】';
-                array_push($data,$menu);
+        $sql = "SELECT
+                    SUBSTRING( `成品代号`, 1, 4 ) AS prefix,
+                    rtrim( Gd_khmc ) AS khmc,
+                    RTRIM( `Gd_客户名称` ) AS 客户名称 
+                FROM
+                    `工单_基本资料` 
+                WHERE
+                    `成品代号` <> '' 
+                    AND ( `Gd_客户名称` <> '' OR Gd_khmc <> '' ) 
+                GROUP BY
+                    prefix 
+                ORDER BY
+                    prefix";
+        $list = \db()->query($sql);
+        if (empty($list)){
+            $this->success('',[]);
+        }
+        foreach ($list as $key=>$value){
+            $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',$value['prefix'].'%')->where('gd_statu','2-生产中')->count();
+            $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',$value['prefix'].'%')->where('gd_statu','3-计划中')->count();
+            $string = '';
+            if ($productIng != 0){
+                $string = $string."生产中:".$productIng;
+            }
+            if ($proGress != 0){
+                $string = $string."计划中:".$proGress;
+            }
+            if ($string !== ''){
+                $data[$key] = $value['prefix'].'【'.$string.'】'.($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
+            }else{
+                $data[$key] = $value['prefix'].($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
             }
         }
         $this->success('成功',$data);
@@ -75,12 +87,11 @@ class WorkOrder extends Api
             $this->error('请求错误');
         }
         $search = input('search');
-        $limit = input('limit');
         $clientNumber = input('Gd_khdh');
         $startTime = input('start');
         $endTime = input('end');
-        $workOrder = input('workOrder');
-        $productCode = input('productCode');
+        $page = input('page');
+        $limit = input('limit');
         $where = [];
         if (!empty($clientNumber)){
             $where['成品代号'] = ['like',$clientNumber.'%'];
@@ -97,13 +108,15 @@ class WorkOrder extends Api
         if (!empty($startTime) && !empty($endTime)){
             $where['接单日期'] = ['between',[$startTime,$endTime]];
         }
-        $list = Db::table('工单_基本资料')
+        $total = \db('工单_基本资料')->where($where)->count();
+        $list = \db('工单_基本资料')
             ->where($where)
             ->order('接单日期 desc')
-            ->paginate($limit);
+            ->limit(($page-1)*$limit,$limit)
+            ->select();
         //工单基本资料数据整理
         $data = [];
-        foreach ($list->items() as $key=>$value){
+        foreach ($list as $key=>$value){
             $data[$key] = [
                 '工单编号' => rtrim($value['Gd_gdbh']),
                 '生产分类' => rtrim($value['Gd_生产分类']),
@@ -126,14 +139,14 @@ class WorkOrder extends Api
                 '更新时间' => rtrim($value['Mod_rq']),
                 'Uniqid' => rtrim($value['Uniqid'])
             ];
-            $number = Db::table('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
+            $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
             if ($number === 0){
                 $data[$key]['status'] = '*';
             }else{
                 $data[$key]['status'] = '';
             }
         }
-        $this->success('成功',$data);
+        $this->success('成功',['data'=>$data,'total'=>$total]);
     }
 
     /**
@@ -154,7 +167,7 @@ class WorkOrder extends Api
         if (empty($Gd_gdbh)){
             $this->error('参数错误');
         }
-        $list = Db::table('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
+        $list = \db('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
         $data = [];
         if ($list){
             foreach ($list as $key=>$value){
@@ -211,7 +224,7 @@ class WorkOrder extends Api
         if (empty($Gd_gdbh)){
             $this->error('参数错误');
         }
-        $list = Db::table('工单_工艺资料')
+        $list = \db('工单_工艺资料')
             ->where('Gy0_gdbh',$Gd_gdbh)
             ->select();
         $data = [];
@@ -287,7 +300,7 @@ class WorkOrder extends Api
         }
         $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
         BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
-        $list = Db::table('工单_bom资料')
+        $list = \db('工单_bom资料')
             ->where('BOM_工单编号',$Gd_gdbh)
             ->field($field)
             ->select();
@@ -322,11 +335,11 @@ class WorkOrder extends Api
         rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(开单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
         rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
         rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid';
-        $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
         if (empty($list)){
             $this->error('未找到该工单信息');
         }
-        $printData = Db::table('工单_印件资料')
+        $printData = \db('工单_印件资料')
             ->where('Yj_Gdbh',$workOrder)
             ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料,rtrim(Uniqid) as id')
             ->find();
@@ -384,9 +397,9 @@ class WorkOrder extends Api
             '排产时库存' => isset($param['kc'])?$param['kc']:'',
             '平均合格率' => isset($param['avg'])?$param['avg']:'',
         ];
-        $sql = Db::table('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
+        $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
         $res = Db::query($sql);
-        $printSql = Db::table('工单_印件资料')
+        $printSql = \db('工单_印件资料')
             ->where('Uniqid',$param['printID'])
             ->fetchSql(true)
             ->update(['yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
@@ -421,12 +434,12 @@ class WorkOrder extends Api
         }
         $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
         rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
-        $list = Db::table('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
+        $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
         if (empty($list)){
             $this->error('未找到该产品工序');
         }
         foreach ($list as $key=>$value){
-            $data = Db::table('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
+            $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
             $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
             $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
             if ($value['add_gxmc'] !== ''){
@@ -461,7 +474,7 @@ class WorkOrder extends Api
             $this->error('参数错误');
         }
         $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
-        $Detail = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
+        $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
         if (empty($Detail)){
             $this->error('未找到工单信息');
         }
@@ -495,31 +508,31 @@ class WorkOrder extends Api
             $this->error('参数错误');
         }
         //获取原工单工艺资料
-        $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
-        $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
+        $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
+        $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
         foreach ($oldProcessData as $k=>$v){
             $oldProcessData[$k]['Gy0_gdbh']  = $newWorkOrder;
             $oldProcessData[$k]['Sys_id'] = '';
             $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
         }
-        if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
-            Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
+        if (\db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
+            \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
         }
         //获取原工单印件资料
-        $oldPrintData = Db::table('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->select();
-        $PrintUniqId = Db::table('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
+        $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->select();
+        $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
         foreach ($oldPrintData as $k=>$v){
             $oldPrintData[$k]['Yj_Gdbh']  = $newWorkOrder;
             $oldPrintData[$k]['Sys_id'] = '';
             $oldPrintData[$k]['Uniqid'] = $PrintUniqId['Uniqid'] +$k +1;
         }
-        if (Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->find()){
-            Db::table('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->delete();
+        if (\db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->find()){
+            \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->delete();
         }
         //复制印件、工艺资料
-        $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
+        $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
         $ProcessRes = Db::query($ProcessSQL);
-        $PrintSQL = Db::table('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
+        $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
         $PrintRes = Db::query($PrintSQL);
         if ($ProcessRes !== false && $PrintRes !== false){
             $this->success('成功');
@@ -547,14 +560,14 @@ class WorkOrder extends Api
         if (empty($workOrder)){
             $this->error('参数错误');
         }
-        $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
         if (empty($list)){
             $this->error('未找到工单信息');
         }
         $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
         rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
         rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
-        $process = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($filed)->select();
+        $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($filed)->select();
         if (empty($process)){
             $this->error('未找到该工单工艺资料');
         }
@@ -589,7 +602,7 @@ class WorkOrder extends Api
         if (empty($productCode) || empty($workOrder)){
             $this->error('参数错误');
         }
-        $list = Db::table('工单_基本资料')->where('成品代号',$productCode)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
+        $list = \db('工单_基本资料')->where('成品代号',$productCode)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
         if (empty($list)){
             $this->error('未获取该产品其他工单信息');
         }
@@ -621,19 +634,19 @@ class WorkOrder extends Api
             $this->error('参数错误');
         }
         //获取原工单工艺资料
-        $oldProcessData = Db::table('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
-        $ProsessUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
+        $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->select();
+        $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
         foreach ($oldProcessData as $k=>$v){
             $oldProcessData[$k]['Gy0_gdbh']  = $newWorkOrder;
             $oldProcessData[$k]['Sys_id'] = '';
             $oldProcessData[$k]['Mod_rq'] = date('Y-m-d H:i:s',time());
             $oldProcessData[$k]['UniqId'] = $ProsessUniqId['UniqId'] + $k + 1;
         }
-        if (Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
-            Db::table('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
+        if (\db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->find()){
+            \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->delete();
         }
         //插入工艺资料
-        $ProcessSQL = Db::table('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
+        $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
         $ProcessRes = Db::query($ProcessSQL);
         if ($ProcessRes !== false){
             $this->success('成功');
@@ -662,7 +675,7 @@ class WorkOrder extends Api
         }
         $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
         rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
-        $list = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
         if (empty($list)){
             $this->error('未找到工单');
         }
@@ -691,7 +704,7 @@ class WorkOrder extends Api
         }else{
             $data[0] = $workOrder;
         }
-        $res = Db::table('工单_基本资料')->where('Uniqid','in',$data)->delete();
+        $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
         if ($res !== false){
             $this->success('成功');
         }else{
@@ -725,11 +738,11 @@ class WorkOrder extends Api
         $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
         rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
         rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
-        $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
+        $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
         if (empty($list)){
             $this->error('未找到该工单工艺');
         }
-        $name = Db::table('工单_基本资料')
+        $name = \db('工单_基本资料')
             ->where('Gd_gdbh',$workOrder)
             ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
             ->find();
@@ -789,7 +802,7 @@ class WorkOrder extends Api
             'Gy0_gdbh' => $workOrder,
             'Gy0_gxh' => $processCode
         ];
-        $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
+        $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -820,7 +833,7 @@ class WorkOrder extends Api
         $field = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
         rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
         rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
-        $list = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
+        $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
         if (empty($list)){
             $this->error('未找到该工单工艺资料');
         }
@@ -861,7 +874,7 @@ class WorkOrder extends Api
         $i = 0;
         foreach ($param as $key=>$value){
             if (!empty($value['loss'])){
-                $data = Db::table('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+                $data = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
             }
             $row = [
                 '工价系数' => $value['difficulty']?:'',
@@ -873,7 +886,7 @@ class WorkOrder extends Api
                 'Gy0_Rate0' => $data['rate0'],
                 'Gy0_Rate1' => $data['rate1']
             ];
-            $sql = Db::table('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
+            $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
             $res = Db::query($sql);
             if ($res !== false){
                 $i++;
@@ -930,7 +943,7 @@ class WorkOrder extends Api
             'yj_desc' => isset($param['desc'])?$param['desc']:'',
         ];
         halt($data);
-        $sql = Db::table('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
+        $sql = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
         $res = Db::query($sql);
         if ($res !== false){
             $this->success('成功');
@@ -960,7 +973,7 @@ class WorkOrder extends Api
         if (empty($param) || isset($param['UniqId']) === false){
             $this->error('参数错误');
         }
-        $rate = Db::table('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+        $rate = \db('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
         $data = [
             '重点工序' => isset($param['zdgx'])?$param['zdgx']:'',
             '备选工序' => isset($param['bxgx'])?$param['bxgx']:'',
@@ -972,11 +985,11 @@ class WorkOrder extends Api
             '工价系数' => isset($param['ndxs'])?$param['ndxs']:'',
             'Mod_rq' => date('Y-m-d H:i:s',time()),
         ];
-        $sql = Db::table('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
+        $sql = \db('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
         $res = Db::query($sql);
-        $status = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
+        $status = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
         if ($status['status'] !== '2-生产中'){
-            $statusSql = Db::table('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
+            $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
             Db::query($statusSql);
         }
         if ($res !== false){
@@ -1002,7 +1015,7 @@ class WorkOrder extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $list = Db::table('设备_基本资料')
+        $list = \db('设备_基本资料')
             ->where('存放地点',$param['address'])
             ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
             ->select();
@@ -1125,7 +1138,7 @@ class WorkOrder extends Api
             'BOM_工单编号' => $workOrder,
         ];
         $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
-        $list = Db::table('工单_bom资料')->where($where)->field($filed)->select();
+        $list = \db('工单_bom资料')->where($where)->field($filed)->select();
         if (empty($list)){
             $this->error('未找到物料资料信息');
         }
@@ -1153,7 +1166,7 @@ class WorkOrder extends Api
         $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
         rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
         rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
-        $list = Db::table('工单_工艺资料')
+        $list = \db('工单_工艺资料')
             ->where($where)
             ->field($filed)
             ->select();

+ 91 - 76
application/api/controller/WorkOrderVerification.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use \think\Request;
 use \think\Db;
+use \think\cache;
 /**
  * 工单核验单维护接口
  */
@@ -32,30 +33,37 @@ class WorkOrderVerification extends Api
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
-        $rows = db()->table('db_qczl')
-            ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
-            ->group('date')
-            ->order('UniqId desc')
-            ->limit(30)
-            ->select();
+        $is_have_cache = Cache::get('WorkOrderVerification/getTab');
+        if ($is_have_cache === false){
+            $rows = db()->table('db_qczl')
+                ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
+                ->group('date')
+                ->order('UniqId desc')
+                ->limit(30)
+                ->select();
 
-        $arr = db()->table('db_qczl')
-            ->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();
+            $arr = db()->table('db_qczl')
+                ->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();
 
-        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]);
+            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]);
+                    }
                 }
+                $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
             }
-            $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
+            Cache::set('WorkOrderVerification/getTab',$rows,86400);
+        }else{
+            $rows = Cache::get('WorkOrderVerification/getTab');
         }
+
         $this->success('成功',$rows);
     }
 
@@ -346,7 +354,7 @@ class WorkOrderVerification extends Api
         $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')
+            ->where($where)->cache(true,86400)->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-外发加工';
@@ -656,7 +664,7 @@ class WorkOrderVerification extends Api
         if (!isset($params['end_date']) || empty($params['end_date'])) {
             $this->error('参数错误');
         }
-        $where['qczl_rq'] = array('between time', [$params['start_date'], $params['start_date']]);
+        $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
         $field = '
         rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
         rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
@@ -666,69 +674,76 @@ class WorkOrderVerification extends Api
         rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
         qczl_rq
         ';
-
-        $data = db('db_qczl')
-            ->where($where)
-            ->where(function ($query) {
+        $resultArray = array();
+        $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
+        $is_have_cache = Cache::has($key);
+        if ($is_have_cache === false){
+            $data = db('db_qczl')
+                ->where($where)
+                ->where(function ($query) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
+                    }
+                })
+                ->field($field)->select();
+            $list = [];
+            $j = 0;
+            foreach ($data as $entry) {
                 for ($i = 1; $i <= 13; $i++) {
-                    $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
-                }
-            })
-            ->field($field)->select();
-        $list = [];
-        $j = 0;
-        foreach ($data as $entry) {
-            for ($i = 1; $i <= 13; $i++) {
-                $labelKey = "fp_lb" . $i;
-                $slKey = "fp_sl" . $i;
-                $bhKey = "fp_bh" . $i;
-                $bzKey = "fp_bz" . $i;
-                if (!empty($entry[$labelKey])) {
-                    if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
-                        $list[$j]['fp_lb'] = $entry[$labelKey];
-                        $list[$j]['fp_sl'] = $entry[$slKey];
-                        $list[$j]['fp_bh'] = $entry[$bhKey];
-                        $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
-                        $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
-                        $list[$j]['fp_bz'] = $entry[$bzKey];
-                        $list[$j]['qczl_rq'] = $entry['qczl_rq'];
-                        $j++;
+                    $labelKey = "fp_lb" . $i;
+                    $slKey = "fp_sl" . $i;
+                    $bhKey = "fp_bh" . $i;
+                    $bzKey = "fp_bz" . $i;
+                    if (!empty($entry[$labelKey])) {
+                        if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
+                            $list[$j]['fp_lb'] = $entry[$labelKey];
+                            $list[$j]['fp_sl'] = $entry[$slKey];
+                            $list[$j]['fp_bh'] = $entry[$bhKey];
+                            $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
+                            $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
+                            $list[$j]['fp_bz'] = $entry[$bzKey];
+                            $list[$j]['qczl_rq'] = $entry['qczl_rq'];
+                            $j++;
+                        }
                     }
                 }
             }
-        }
-        $resultArray = array();
-        foreach ($list as $item) {
-            $found = false;
-            foreach ($resultArray as &$resultItem) {
-                if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
-                    $resultItem["fp_sl"] += (int)$item["fp_sl"];
-                    $found = true;
-                    break;
+            foreach ($list as $item) {
+                $found = false;
+                foreach ($resultArray as &$resultItem) {
+                    if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
+                        $resultItem["fp_sl"] += (int)$item["fp_sl"];
+                        $found = true;
+                        break;
+                    }
+                }
+                if (!$found) {
+                    $resultArray[] = $item;
                 }
             }
-            if (!$found) {
-                $resultArray[] = $item;
-            }
-        }
-        // 使用usort进行排序
-        usort($resultArray, function($a, $b) {
-            // First, sort by fp_lb (K01/K02)
-            $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
-            if ($compareLb !== 0) {
-                return $compareLb;
-            }
+            // 使用usort进行排序
+            usort($resultArray, function($a, $b) {
+                // First, sort by fp_lb (K01/K02)
+                $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
+                if ($compareLb !== 0) {
+                    return $compareLb;
+                }
 
-            // If fp_lb is the same, prioritize B班 over A班
-            $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
-            if ($compareBz !== 0) {
-                return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
-            }
+                // If fp_lb is the same, prioritize B班 over A班
+                $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
+                if ($compareBz !== 0) {
+                    return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
+                }
+
+                // If fp_bz is the same, sort by fp_bh
+                $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
+                return $compareBh;
+            });
+            Cache::set($key,$resultArray,86400);
+        }else{
+            $resultArray = Cache::get($key);
+        }
 
-            // If fp_bz is the same, sort by fp_bh
-            $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
-            return $compareBh;
-        });
         $this->success('请求成功',$resultArray);
     }
     /**