Parcourir la source

翌星三四楼接口优化调整

qiuenguang il y a 1 an
Parent
commit
1ca2fe854a

+ 254 - 117
application/api/controller/Facility.php

@@ -30,12 +30,19 @@ class Facility extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
+        $param = $this->request->param();
+        if (isset($param['sort'])){
+            $where['使用部门'] = '智能车间';
+        }else{
+            $where['使用部门'] = ['in',['印刷车间','印后车间']];
+        }
         $data = [];
         $date = date('Y-m-d 00:00:00',time()-3888000);
         $department = \db('设备_基本资料')
             ->distinct(true)
             ->where('使用部门','<>','研发中心')
             ->where('设备编组','<>','')
+            ->where($where)
             ->order('设备编组')
             ->column('rtrim(使用部门) as 使用部门');
         if (empty($department)){
@@ -147,10 +154,16 @@ class Facility extends Api
             if ($value['yjno']<10){
                 $list[$key]['yjno'] = '0'.$value['yjno'];
             }
-            $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
-            $list[$key]['千件工价'] = $row['千件工价'];
-            $list[$key]['日定额'] = $row['日定额'];
-            $list[$key]['补产标准'] = $row['补产标准'];
+            if (empty($value['定额代号'])){
+                $list[$key]['千件工价'] = '';
+                $list[$key]['日定额'] = '';
+                $list[$key]['补产标准'] = '';
+            }else{
+                $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
+                $list[$key]['千件工价'] = $row['千件工价'];
+                $list[$key]['日定额'] = $row['日定额'];
+                $list[$key]['补产标准'] = $row['补产标准'];
+            }
             $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
             $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
             for ($i=1;$i<11;$i++){
@@ -263,25 +276,22 @@ class Facility extends Api
         $machine = $params['machine'];
         $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
         $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
-        if (empty($data['工单编号'])){
-            $this->success('未找到生产订单');
-        }
-        $endTime = \db('工单_工艺资料')
-            ->where('UniqId',$data['任务ID'])
-//            ->where('Gy0_sj1','>','1900-01-01 00:00:00')
-            ->find();
-        if (empty($endTime)){
-            $this->error('未找到');
-        }
         $list = [];
-        if ($endTime['PD_WG'] === '1900-01-01 00:00:00'){
+        if (!empty($data['工单编号'])){
+            $endTime = \db('工单_工艺资料')
+                ->where('UniqId',$data['任务ID'])
+                ->find();
             $list['工单编号'] = $data['工单编号'];
-            $list['印件号'] = $data['印件号'];
-            $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
-            $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
-            $list['产品名称'] = rtrim($name);
-            $list['产品代号'] = rtrim($code);
-            $list['工序名称'] = $data['工序名称'];
+            if (!empty($endTime)){
+                if ($endTime['PD_WG'] === '1900-01-01 00:00:00'){
+                    $list['印件号'] = $data['印件号'];
+                    $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
+                    $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
+                    $list['产品名称'] = rtrim($name);
+                    $list['产品代号'] = rtrim($code);
+                    $list['工序名称'] = $data['工序名称'];
+                }
+            }
         }else{
             $list['工单编号'] = '';
             $list['印件号'] = 0;
@@ -295,20 +305,19 @@ class Facility extends Api
         $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
         rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
         rtrim(sczl_bh10) as bh10")->find();
-        if (empty($class)){
-            $this->success('未找到班组信息');
-        }
         $row = [];
-        for ($i=1;$i<11;$i++) {
-            if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
-                $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
-                $row[$i] = [
-                    '编号' => $class['bh' . $i],
-                    '姓名' => $name['姓名']
-                ];
+        if (!empty($class)){
+            for ($i=1;$i<11;$i++) {
+                if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
+                    $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
+                    $row[$i] = [
+                        '编号' => $class['bh' . $i],
+                        '姓名' => $name['姓名']
+                    ];
+                }
             }
+            $row = array_values($row);
         }
-        $row = array_values($row);
         $list['班组成员'] = $row;
         $list['定额代号'] = $machineCode;
         $this->success('成功',$list);
@@ -369,32 +378,31 @@ class Facility extends Api
             GROUP BY a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh
             ORDER BY a.UniqId desc";
         $orderList = Db::query($sql);
-        if (empty($orderList)){
-            $this->success('未找到排产工单');
-        }
-        $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
-        foreach ($orderList as $key=>$value){
-            $orderList[$key]['status'] = 0;
-            if (!empty($data)){
-                if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
-                    $orderList[$key]['status'] = 1;
+        if (!empty($orderList)){
+            $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
+            foreach ($orderList as $key=>$value){
+                $orderList[$key]['status'] = 0;
+                if (!empty($data)){
+                    if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
+                        $orderList[$key]['status'] = 1;
+                    }
                 }
-            }
 
-            $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
-            $orderList[$key]['印件号'] = $value['yjno'];
-            $orderList[$key]['工序号'] = $value['gxh'];
-            if ($value['yjno']<10){
-                $orderList[$key]['yjno'] = '0'.$value['yjno'];
-            }
-            if ($value['gxh']<10){
-                $orderList[$key]['gxh'] = '0'.$value['gxh'];
+                $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
+                $orderList[$key]['印件号'] = $value['yjno'];
+                $orderList[$key]['工序号'] = $value['gxh'];
+                if ($value['yjno']<10){
+                    $orderList[$key]['yjno'] = '0'.$value['yjno'];
+                }
+                if ($value['gxh']<10){
+                    $orderList[$key]['gxh'] = '0'.$value['gxh'];
+                }
+                $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
+                $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
+                $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$value['已完成']=null?'':(int)$value['已完成'];
+                $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
+                unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
             }
-            $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
-            $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
-            $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$value['已完成']=null?'':(int)$value['已完成'];
-            $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
-            unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
         }
         $this->success('成功',$orderList);
     }
@@ -417,28 +425,27 @@ class Facility extends Api
             $this->error('请求错误');
         }
         $workOrder = input('Gd_gdbh');
-        if (empty($workOrder)){
-            $this->error('参数错误');
-        }
-        //右边工艺及完成数量
-        $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
-            ->distinct(true)->order('sczl_gxh')
-            ->column('sczl_gxh');
         $data = [];
-        foreach ($Process as $k=>$v){
-            $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
-                ->where('sczl_gxh',$v)
-                ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
-                ->find();
-            if ($res['sczl_yjno']<10){
-                $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
+        if (!empty($workOrder)){
+            //右边工艺及完成数量
+            $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+                ->distinct(true)->order('sczl_gxh')
+                ->column('sczl_gxh');
+            foreach ($Process as $k=>$v){
+                $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+                    ->where('sczl_gxh',$v)
+                    ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
+                    ->find();
+                if ($res['sczl_yjno']<10){
+                    $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
+                }
+                $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
+                $processList['completed'] = \db('设备_产量计酬')
+                    ->where('sczl_gdbh',$workOrder)
+                    ->where('sczl_gxh',$v)
+                    ->count();
+                array_push($data,$processList);
             }
-            $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
-            $processList['completed'] = \db('设备_产量计酬')
-                ->where('sczl_gdbh',$workOrder)
-                ->where('sczl_gxh',$v)
-                ->count();
-            array_push($data,$processList);
         }
         $this->success('成功',$data);
     }
@@ -541,34 +548,35 @@ class Facility extends Api
         rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
         rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
         $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
-        if (empty($list)){
-            $this->success('');
-        }
-        foreach ($list as $k=>$v){
-            $name = \db('工单_基本资料')->where('Gd_gdbh',$v['工单编号'])->where('行号',$v['yjno'])->field('rtrim(Gd_cpmc) as productName,rtrim(成品名称) as 成品名称')->find();
-            if ($v['yjno']<10){
-                $list[$k]['yjno'] = '0'.$v['yjno'];
-            }
-            if (!empty($v['拉料'])){
-                $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
-            }
-            if (isset($list[$k]['拉料姓名']) === false){
-                $list[$k]['拉料姓名'] = '';
-            }
-            $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
-            $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
-            $list[$k]['产品名称'] = $name['productName'];
-            if (empty($name['productName'])){
-                $list[$k]['产品名称'] = $name['成品名称'];
+        if (!empty($list)){
+            foreach ($list as $k=>$v){
+                $name = \db('工单_基本资料')->where('Gd_gdbh',$v['工单编号'])->where('行号',$v['yjno'])->field('rtrim(Gd_cpmc) as productName,rtrim(成品名称) as 成品名称')->find();
+                if ($v['yjno']<10){
+                    $list[$k]['yjno'] = '0'.$v['yjno'];
+                }
+                if (!empty($v['拉料'])){
+                    $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
+                }
+                if (isset($list[$k]['拉料姓名']) === false){
+                    $list[$k]['拉料姓名'] = '';
+                }
+                $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
+                $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
+                $list[$k]['产品名称'] = $name['productName'];
+                if (empty($name['productName'])){
+                    $list[$k]['产品名称'] = $name['成品名称'];
+                }
             }
-        }
-        $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
+            $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
         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('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
-        $total[0]['版数'] = count($list);
-        $list['total'] = $total[0];
+            $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
+            $total[0]['版数'] = count($list);
+            $list['total'] = $total[0];
+        }
+
+
         $this->success('成功',$list);
     }
 
@@ -718,7 +726,17 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
-        $res = \db('设备_班组资料')
+        $machine = \db('设备_班组资料')
+            ->where('UniqId',$param['UniqId'])
+            ->value('sczl_jtbh');
+        $teamId = \db('设备_产量采集')
+            ->where('设备编号',$machine)
+            ->order('UniqId desc')
+            ->value('班组ID');
+        if ($teamId === (int)$param['UniqId']){
+            $this->success('无法删除正在生产的班组资料,请先切换班组');
+        }
+         $res = \db('设备_班组资料')
             ->where('UniqId',$param['UniqId'])
             ->delete();
         if ($res !== false){
@@ -1613,18 +1631,14 @@ class Facility extends Api
         $lastData = \db('设备_产量采集')
             ->order('UniqId desc')
             ->find();
-        if (empty($lastData)){
-            $id = 1;
-        }else{
-            $id = $lastData['UniqId']+1;
-        }
+        $id = $lastData['UniqId']+1;
         $data['当前状态'] = $params['status'];
         $data['时间'] = date('Y-m-d H:i:s');
         $data['设备编号'] = $machine;
-        $data['工单编号'] = $params['order'];
-        $data['印件号'] = $params['yjno'];
-        $data['工序号'] = (int)substr($params['gy_name'], 0, 2);
-        $data['工序名称'] = $params['gy_name'];
+        $data['工单编号'] = empty($params['order']) ? '':$params['order'];
+        $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
+        $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
+        $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
         $data['当班产量'] = $params['production_now'];
         $data['累计产量'] = $params['production_all'];
         $data['班组编号'] = $params['sczl_bzdh'];
@@ -1645,10 +1659,14 @@ class Facility extends Api
         } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
             $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
         }
-        $option['Gy0_gdbh'] = $params['order'];
-        $option['Gy0_yjno'] = $params['yjno'];
-        $option['Gy0_gxh'] = $data['工序号'];
-        $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
+        if (!empty($params['order']) && !empty($params['yjno'])){
+            $option['Gy0_gdbh'] = $params['order'];
+            $option['Gy0_yjno'] = $params['yjno'];
+            $option['Gy0_gxh'] = $data['工序号'];
+            $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
+        }else{
+            $data['任务ID'] = '';
+        }
         $data['UniqId'] = $id;
         $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
         $res = Db::query($sql);
@@ -1922,6 +1940,7 @@ class Facility extends Api
         }
         $param['sczl_打样工时'] = $param['sczl_打样总工时'];
         $param['sczl_装版工时'] = $param['sczl_装版总工时'];
+        $param['mod_rq'] = date('Y-m-d H:i:s',time());
         $data = $param;
         unset($data['UniqId']);
         $sql = \db('设备_产量计酬')
@@ -2103,12 +2122,17 @@ class Facility extends Api
             $this->error('请求错误');
         }
         $param = $this->request->param();
-        if (empty($param['machine'])){
+        if (empty($param)){
             $this->error('参数错误');
         }
-        $where = [
-            'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
-        ];
+//        $where = [
+//            'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
+//        ];
+//        if (!empty($param['machine'])){
+//            $where = [
+//                'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
+//            ];
+//        }
         if (!empty($param['search'])){
             $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
         }
@@ -2363,4 +2387,117 @@ class Facility extends Api
         }
     }
 
+    /**
+     * 检品机日产量上报数据修改
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function JpChanliangEdit()
+    {
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (empty($params['UniqId'])){
+            $this->error('参数错误');
+        }
+        $params['mod_rq'] = date('Y-m-d H:i:s');
+        $data = $params;
+        $data['sczl_装版总工时'] = $params['sczl_装版工时'];
+        unset($data['UniqId']);
+        $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
+        $res = \db()->query($sql);
+        if ($res === false){
+            $this->error('修改失败');
+        }else{
+            $this->success('成功');
+        }
+    }
+
+    /**
+     * 检品机日产量上报数据列表
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function JPmachineDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        $date = input('date');
+        $where = [
+            'sczl_jtbh' => $machine,
+            'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
+        ];
+        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
+        rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
+        rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
+        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,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
+        //机台信息
+        $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
+        //组员信息
+        $list = \db('设备_产量计酬')->where($where)->field($field)->select();
+        $totalA = \db('设备_产量计酬')
+            ->where($where)
+            ->where('sczl_bzdh','like','A%')
+            ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
+            ->group('检验类型')
+            ->select();
+        $totalB = \db('设备_产量计酬')
+            ->where($where)
+            ->where('sczl_bzdh','like','B%')
+            ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
+            ->group('检验类型')
+            ->select();
+        if (empty($list)){
+            $this->success('',[]);
+        }
+        foreach ($list as $key=>$value){
+            //产品名称
+            $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
+            if (!empty($productName)){
+                if (!empty($productName['成品名称'])){
+                    $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
+                    $list[$key]['cpmc'] = $productName['成品名称'];
+                }else{
+                    $list[$key]['产品名称'] = $value['工单编号'];
+                    $list[$key]['cpmc'] = '';
+                }
+            }else{
+                $list[$key]['产品名称'] = $value['工单编号'];
+                $list[$key]['cpmc'] = '';
+            }
+            if (empty($value['定额代号'])){
+                $list[$key]['千件工价'] = '';
+                $list[$key]['日定额'] = '';
+                $list[$key]['补产标准'] = '';
+            }else{
+                $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
+                $list[$key]['千件工价'] = $row['千件工价'];
+                $list[$key]['日定额'] = $row['日定额'];
+                $list[$key]['补产标准'] = $row['补产标准'];
+            }
+            $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
+            for ($i=1;$i<11;$i++){
+                if (isset($value['sczl_bh'.$i])){
+                    $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
+                    if (isset($name['name'])){
+                        $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
+                        $list[$key]['sczl_name'.$i] = $name['name'];
+                    }else{
+                        $list[$key]['sczl_name'.$i] = '';
+                    }
+                }
+            }
+        }
+        $list['totalA'] = $totalA;
+        $list['totalB'] = $totalB;
+        $this->success('成功',$list);
+    }
 }

+ 119 - 0
application/api/controller/Index.php

@@ -351,4 +351,123 @@ class Index extends Api
         $res['data']=$result;
         return json($res);
     }
+
+    /**
+     * 班组工作中心负荷
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function bzDbToRedis()
+    {
+        $bzDbToRedis = [];
+        //计算当天时间
+        $sczlTime = date('Y-m-d H:i:s',time());
+        if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
+            $time = date('Y-m-d 00:00:00',time()-86400);
+        }else{
+            $time = date('Y-m-d 00:00:00');
+        }
+        //获取所有机台数据
+        $machineList = db('设备_基本资料')
+            ->where('sys_sbID','<>','')
+            ->where('使用部门','in',['印刷车间','印后车间'])
+            ->field('设备编号')
+            ->select();
+        //循环获取班组、工单、生产数据
+        foreach ($machineList as $key=>$value){
+            //获取正在生产工单信息
+            $workOrder = \db('设备_产量采集')
+                ->where('设备编号',$value['设备编号'])
+                ->field('工单编号,印件号,工序号,工序名称,当前状态')
+                ->order('UniqId desc')
+                ->find();
+            if (!$workOrder) continue;
+            //获取生产信息
+            $list = db('设备_产量计酬')
+                ->alias('a')
+                ->join('工单_基本资料 b','b.Gd_gdbh = a.sczl_gdbh')
+                ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh AND a.sczl_yjno = c.Gy0_yjno AND a.sczl_gxh = c.Gy0_gxh')
+                ->field([
+                    'SUM(a.sczl_cl)' => '已完成产量',
+                    'b.成品名称' => '产品名称',
+                    'c.Gy0_计划接货数' => '计划产量',
+                    'c.Gy0_小时产能' => '小时产能',
+                    'a.sczl_bzdh' => '班组代号'
+                ])
+                ->where([
+                    'a.sczl_jtbh' => $value['设备编号'],
+                    'a.sczl_gdbh' => $workOrder['工单编号'],
+                    'a.sczl_yjno' => $workOrder['印件号'],
+                    'a.sczl_gxh' => $workOrder['工序号'],
+                    'a.sczl_rq' => $time
+                ])
+                ->group('a.sczl_jtbh,a.sczl_bzdh')
+                ->select();
+            if (!$list) continue;
+            foreach ($list as $v){
+                $v['机台号'] = $value['设备编号'];
+                $v['机台状态'] = $workOrder['当前状态'];
+                $v['工单编号'] = $workOrder['工单编号'];
+                $v['印件号'] = $workOrder['印件号'];
+                $v['工序名称'] = $workOrder['工序名称'];
+                array_push($bzDbToRedis,$v);
+            }
+        }
+        $bool = cache('bzDbToRedis',$bzDbToRedis);
+        if($bool===false) $this->error('存入redis失败','','000002');
+        $this->success('同步成功');
+    }
+
+    /**
+     * 获取班组工作负荷数据
+     * @return \think\response\Json
+     */
+    public function getBzByRedis()
+    {
+        $row = cache('bzDbToRedis');
+        $result['columns']=[
+            ['name'=>'机台号','id'=>'jtbh','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'班组','id'=>'bzdh','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'在产工单号','id'=>'gdbh','width'=>'16','textAlign'=>'left'],
+            ['name'=>'工单名称','id'=>'gdmc','width'=>'20','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'印件号','id'=>'yjno','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'工序','id'=>'gx','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'计划产量','id'=>'jhcl','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
+            ['name'=>'已完成产量','id'=>'wccl','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
+            ['name'=>'小时产能','id'=>'xscn','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
+            ['name'=>'机台状态','id'=>'status','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
+        ];
+        if($row){
+            foreach($row as $k=>$v){
+                $result['rows'][$k]['jtbh']=$v['机台号'];
+                $result['rows'][$k]['bzdh']=$v['班组代号'];
+                $result['rows'][$k]['gdbh']=$v['工单编号'];
+                $result['rows'][$k]['gdmc']=$v['产品名称'];
+                $result['rows'][$k]['yjno']=$v['机台号'];
+                $result['rows'][$k]['gx']=$v['工序名称'];
+                $result['rows'][$k]['jhcl'] = $v['计划产量'];
+                $result['rows'][$k]['wccl'] = $v['已完成产量'];
+                $result['rows'][$k]['xscn'] = $v['小时产能'];
+                $result['rows'][$k]['status'] = $v['机台状态'];
+            }
+        }else{
+            $result['rows'][0]['jtbh']='';
+            $result['rows'][0]['bzdh']='';
+            $result['rows'][0]['gdbh']='';
+            $result['rows'][0]['gdmc']='';
+            $result['rows'][0]['yjno']='';
+            $result['rows'][0]['gx']='';
+            $result['rows'][0]['jhcl'] = '';
+            $result['rows'][0]['wccl'] = '';
+            $result['rows'][0]['xscn'] = '';
+            $result['rows'][0]['status'] = '';
+        }
+        $res['status']=0;
+        $res['msg']='';
+        $res['data']=$result;
+        return json($res);
+    }
 }
+

+ 3 - 2
application/api/controller/MachineProductionReport.php

@@ -621,11 +621,11 @@ class MachineProductionReport extends Api
         }
 
         $row = db('工单_印件资料')
-            ->field('rtrim(yj_yjmc) as yj_yjmc')
+            ->field('rtrim(yj_yjmc) as yj_yjmc,yj_ls as sczl_ls')
             ->where(['Yj_Gdbh'=>$gdbh,'yj_Yjno'=>$yjno])
             ->find();
         $gxmc = db('工单_工艺资料')
-        ->field('Gy0_gxh as sczl_gxh, rtrim(Gy0_gxmc) as sczl_type, rtrim(Add_gxmc) as Add_gxmc,Gy0_ls as sczl_ls, Gy0_ms as sczl_ms')
+        ->field('Gy0_gxh as sczl_gxh, rtrim(Gy0_gxmc) as sczl_type, rtrim(Add_gxmc) as Add_gxmc, Gy0_ms as sczl_ms')
         ->where(['Gy0_gdbh'=>$gdbh,'Gy0_yjno'=>$yjno, 'Gy0_gxmc'=>'拆片'])
         ->find();
         if($gxmc['Add_gxmc'] != ''){
@@ -633,6 +633,7 @@ class MachineProductionReport extends Api
         }else{
             $gxmc['sczl_gxmc'] = sprintf("%02d", $gxmc['sczl_gxh']).'-'.$gxmc['sczl_type'];
         }
+        $gxmc['sczl_ls'] = $row['sczl_ls'];
         unset($gxmc['Add_gxmc']);
         $row['gxmc'] = $gxmc;
         if (!$row) $this->error('印件编号不存在, 将恢复默认值, 请仔细确认数据准确性!');

+ 0 - 1
application/api/controller/MachineProductionReportAdd.php

@@ -38,7 +38,6 @@ class MachineProductionReportAdd extends Api
             ->order('UniqId desc')
             ->limit(60)
             ->select();
-
         $arr = db('db_sczladd')
             ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
             ->where('sys_rq','>=',$rows[count($rows)-1]['date'])

+ 7 - 0
application/api/controller/Manufacture.php

@@ -309,11 +309,18 @@ class Manufacture extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
+        $param = $this->request->param();
+        if (isset($param['sort'])){
+            $where['使用部门'] = '智能车间';
+        }else{
+            $where['使用部门'] = ['in',['印刷车间','印后车间']];
+        }
         $data = [];
         $department = \db('设备_基本资料')
             ->distinct(true)
             ->where('使用部门','<>','研发中心')
             ->where('设备编组','<>','')
+            ->where($where)
             ->order('设备编组')
             ->column('使用部门');
         if (empty($department)){

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

@@ -391,36 +391,37 @@ class PackagingCountDocument extends Api
 
         $row = db('dic_lzde')
             ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
-            ->where('sys_mc','包装')
-            ->find();
-        $rows = db('dic_lzde')
-            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
-            ->where('Parent',$row['Key_'])
-            ->order('sys_bh asc')
+            ->where('sys_mc','in',['包装','成品防护'])
             ->select();
-        foreach ($rows as $key=>$value){
-            $bool = db('dic_lzde')
-                ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
-                ->where('Parent',$value['Key_'])
+        foreach ($row as $n=>$m){
+            $rows = db('dic_lzde')
+                ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
+                ->where('Parent',$m['Key_'])
                 ->order('sys_bh asc')
                 ->select();
-            if ($bool){
-                foreach ($bool as $k=>$v){
-                    $bool1 = db('dic_lzde')
-                        ->field('sys_bh, rtrim(sys_mc) as sys_mc')
-                        ->where('Parent',$v['Key_'])
-                        ->order('sys_bh asc')
-                        ->select();
-
-                    if ($bool1){
-                        $bool[$k]['bh_mc'] = $bool1;
+            foreach ($rows as $key=>$value){
+                $bool = db('dic_lzde')
+                    ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
+                    ->where('Parent',$value['Key_'])
+                    ->order('sys_bh asc')
+                    ->select();
+                if ($bool){
+                    foreach ($bool as $k=>$v){
+                        $bool1 = db('dic_lzde')
+                            ->field('sys_bh, rtrim(sys_mc) as sys_mc')
+                            ->where('Parent',$v['Key_'])
+                            ->order('sys_bh asc')
+                            ->select();
+
+                        if ($bool1){
+                            $bool[$k]['bh_mc'] = $bool1;
+                        }
                     }
+                    $rows[$key]['bh_mc'] = $bool;
                 }
-                $rows[$key]['bh_mc'] = $bool;
             }
+            $row[$n]['bh_mc'] = $rows;
         }
-        $row['bh_mc'] = $rows;
-
         $this->success('成功',$row);
     }
     

+ 36 - 7
application/api/controller/Product.php

@@ -6,6 +6,8 @@ use app\common\controller\Api;
 use \think\Request;
 use \think\Db;
 use think\Cache;
+use function fast\e;
+
 /**
  * 产品管理接口
  */
@@ -36,6 +38,7 @@ class Product extends Api
         }
         $params = Request::instance()->param();
         $limit = $params['limit'];
+        $yjno = 10;
         if (!isset($limit)){
             $limit = 15;
         }
@@ -77,14 +80,25 @@ class Product extends Api
             if (!empty($gdRes)){
                 $list[$key]['receiveDate']  = $gdRes[0]['接单日期'];
             }
-            $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
-            $gyRes = Db::query($gy_sql);
+            if (isset($params['sort'])){
+                $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}' AND Gy0_yjno >= '{$yjno}'";
+                $gyRes = Db::query($gy_sql);
+            }else{
+                $gy_sql = "SELECT * FROM `产品_工艺资料` WHERE Gy0_cpdh = '{$code}'";
+                $gyRes = Db::query($gy_sql);
+            }
             $list[$key]['gyData'] = '';
             if (empty($gyRes)){
                 $list[$key]['gyData'] = '缺';
             }
-            $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
-            $yjRes = Db::query($yj_sql);
+            if (isset($params['sort'])){
+                $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}' AND yj_yjno >= '{$yjno}'";
+                $yjRes = Db::query($yj_sql);
+            }else{
+                $yj_sql = "SELECT COUNT(*) as total FROM `产品_印件资料` WHERE `yj_cpdh` = '{$code}'";
+                $yjRes = Db::query($yj_sql);
+            }
+
             $list[$key]['yjData'] = '无';
             if ($yjRes[0]['total'] > 0){
                 $list[$key]['yjData'] = $yjRes[0]['total'];
@@ -109,6 +123,13 @@ class Product extends Api
         if (!isset($code)){
             $this->error('参数不能为空');
         }
+        if (isset($params['sort'])){
+            $PriWhere['yj_yjno'] = ['>=',10];
+            $proWhere['Gy0_yjno'] = ['>=',10];
+        }else{
+            $PriWhere['yj_yjno'] = ['<',10];
+            $proWhere['Gy0_yjno'] = ['<',10];
+        }
         $num = config('product_code_digit');
         //工艺资料
         $option['a.Gy0_cpdh'] = $code;
@@ -117,12 +138,12 @@ class Product extends Api
         a.Sys_rq,a.Mod_rq,b.sys_rate0 as 基础损耗,b.sys_rate1 as 损耗率,a.UniqID';
         $gyRes = db('产品_工艺资料')->alias('a')
             ->join('dic_lzsh b','a.Gy0_shdh = b.sys_bh','left')
-            ->where($option)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
+            ->where($option)->where($proWhere)->field($gy_field)->order('a.Gy0_yjno asc,a.Gy0_gxh asc')->select();
         //印件资料
         $where['yj_cpdh'] = $code;
         $field = 'yj_yjno,rtrim(yj_yjdh) as yj_yjdh,yj_yjmc,rtrim(yj_zzdh) as yj_zzdh,rtrim(yj_zzmc) as yj_zzmc,rtrim(yj_tlgg) as yj_tlgg,
         rtrim(yj_klgg) as yj_klgg,yj_ks,yj_ls,rtrim(yj_desc) as yj_desc,rtrim(sys_id) as sys_id,sys_rq,mod_rq,UniqId';
-        $yjRes = db('产品_印件资料')->where($where)->field($field)->select();
+        $yjRes = db('产品_印件资料')->where($where)->where($PriWhere)->field($field)->select();
         //印版资料
         $filter['a.YB_Cpdh'] = $code;
         $yb_field = 'rtrim(a.YB_方案) as YB_方案,a.YB_Yjno,rtrim(a.存货编码) as 存货编码,a.考核印数,rtrim(a.Sys_id) as Sys_id,a.Mod_rq,rtrim(b.物料名称) as 印版名称,rtrim(c.名称) as 印版类别,a.UniqID';
@@ -735,6 +756,7 @@ class Product extends Api
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
+        $param = $this->request->param();
         $data = \db('erp_常用字典')->where('分类','印刷工艺')->order('编号 asc')->column('名称');
 
         $resultArray = [];
@@ -747,7 +769,13 @@ class Product extends Api
 
             $resultArray[$firstKey][$secondKey][] = $thirdValue;
         }
-        $this->success('请求成功',$resultArray);
+        if (isset($param['sort'])){
+            $result['标准工艺']['智能车间'] = $resultArray['标准工艺']['智能车间'];
+        }else{
+            unset($resultArray['标准工艺']['智能车间']);
+            $result = $resultArray;
+        }
+        $this->success('请求成功',$result);
     }
     /**
      * 3.8工艺资料-新增产品工艺
@@ -944,6 +972,7 @@ class Product extends Api
         if (empty($params) || !isset($params['code'])){
             $this->error('参数不能为空');
         }
+
         $code = $params['code'];
         $where['sys_bh|sys_mc'] = array('like','%'.$code.'%');
         $data = \db('dic_lzsh')

+ 78 - 5
application/api/controller/ReportingWork.php

@@ -41,11 +41,7 @@ class ReportingWork extends Api
 //            ->where('设备编号',$machine)
             ->order('UniqId desc')
             ->find();
-        if ($lastData['UniqId'] < 160000000){
-            $id = 160000000;
-        }else{
-            $id = $lastData['UniqId'] + 1;
-        }
+        $id = $lastData['UniqId'] + 1;
         if (empty($params['order'])){
             unset($lastData['UniqId']);
             $data = $lastData;
@@ -582,4 +578,81 @@ class ReportingWork extends Api
             $this->success('成功');
         }
     }
+
+    /**
+     * 检品机报工
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+
+    public function JpUploade()
+    {
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        $time = date('Y-m-d 00:00:00',time()-86400);
+        $data = $params;
+        $data['sczl_装版总工时'] = $params['sczl_装版工时'];
+        $data['sczl_sj1'] = '1900-01-01 00:00:00';
+        $data['sczl_sj2'] = date('Y-m-d H:i:s',time());
+        if ($data['sczl_sj2']<date('Y-m-d 08:30:00',time()) && $data['sczl_sj2']>date('Y-m-d 00:00:00')){
+            $data['sczl_rq'] = $time;
+        }
+
+        $start_time = \db('设备_产量采集')->where('设备编号',$data['sczl_jtbh'])->order('UniqId desc')->find();
+        if (!empty($start_time)){
+            $data['开工时间'] = $start_time['开工时间'];
+        }else{
+            $data['开工时间'] = '1900-01-01 00:00:00';
+        }
+        $sys_id = \db('设备_基本资料')->where('设备编号',$data['sczl_jtbh'])->value('sys_sbID');
+        $data['sys_id'] = '['.$sys_id.'/'.$data['sczl_jtbh'].']';
+        $UniqId = \db('设备_产量计酬')->order('UniqId desc')->value('UniqId');
+        $data['UniqId'] = $UniqId + 1;
+        $data['sczl_ls'] = 1;
+        $data['sczl_zcfp'] = 0;
+        $data['sczl_zccp'] = 0;
+        $data['sczl_前工序废'] = 0;
+        $data['sczl_来料少数'] = 0;
+        $data['sczl_ms'] = 0;
+        $data['sczl_oil'] = 0;
+        $data['sczl_计产系数'] = 0;
+        $data['sczl_工价系数'] = 0;
+        $data['sczl_保养工时'] = 0;
+        $data['sczl_打样工时'] = 0;
+        $data['sczl_异常停机工时'] = 0;
+        $data['sczl_异常工时1'] = 0;
+        $data['sczl_异常类型1'] = '';
+        $data['sczl_desc'] = '';
+        $data['sczl_wgsj'] = '1900-01-01 00:00:00';
+        $data['码开始行'] = 0;
+        $data['码结束行'] = 0;
+        $data['码包'] = 0;
+        $data['主电表'] = 0;
+        $data['辅电表'] = 0;
+        $data['mod_rq'] = '1900-01-01 00:00:00';
+        $data['sys_rq'] = date('Y-m-d H:i:s');
+        $sql = \db('设备_产量计酬')->fetchSql(true)->insert($data);
+        $res = \db()->query($sql);
+        if ($res === false){
+            $this->error('添加失败');
+        }else{
+            $this->success('成功');
+        }
+    }
+
+    //获取当前日期和时间
+    public function getTime()
+    {
+        $data = [
+            'date' => date('Y-m-d',time()),
+            'hours' => date('Y-m-d H:i:s',time())
+        ];
+        $this->success('成功',$data);
+    }
 }

+ 5 - 5
application/api/controller/StaffSalary.php

@@ -99,7 +99,7 @@ class StaffSalary extends Api
         $where = [];
         $where['a.sczl_rq'] = ['between',[$startDate,$endDate]];
         //查询印刷印后车间的机台,添加搜索条件
-        $jtbhs = db('设备_基本资料')->where('使用部门','in',['印刷车间','印后车间'])->column('设备编号');
+        $jtbhs = db('设备_基本资料')->where('使用部门','in',['印刷车间','印后车间'])->where('sys_sbID','<>','')->column('设备编号');
         $fields = "a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_gxmc as sczl_type,a.sczl_rq,a.sczl_jtbh,a.sczl_工价系数,a.sczl_ms,a.sczl_cl as 班组车头产量,a.sczl_Pgcl,a.sczl_zcfp,
                 a.sczl_装版工时 as 装版工时,a.sczl_保养工时 as 保养工时,a.sczl_打样工时 as 打样工时,a.sczl_异常工时1 as 异常停机工时,a.sczl_设备运行工时 as 车头产量占用机时,
                 a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5,a.sczl_bh6,a.sczl_bh7,a.sczl_bh8,a.sczl_bh9,a.sczl_bh10,
@@ -120,7 +120,7 @@ class StaffSalary extends Api
             $query->join("人事_基本资料 $alias", "$field = {$alias}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
         }
         $query->where($where)->where('a.sczl_jtbh','in',$jtbhs);
-        $list = $query->select();
+        $list = $query->order('a.sczl_rq')->select();
         $UniqId = \db('绩效工资汇总')->field('UniqID')->order('UniqID desc')->find();
         if (empty($UniqId)){
             $UniqId = 1;
@@ -220,7 +220,6 @@ class StaffSalary extends Api
                 }
             }
         }
-//        halt($data);
         /**
          * 拆片工序数据
         */
@@ -508,9 +507,10 @@ class StaffSalary extends Api
             $date = substr($item['sczl_rq'],0,10);
             if (in_array($date,$vacationOneArr) || in_array($date,$vacationTwoArr)){
                 //计件工资
-                $pieceWorkWage = $data[$key]['达标定额']/1000*$item['千件工价']*$item['Rate']*3;
+//                $pieceWorkWage = $data[$key]['达标定额']/1000*$item['千件工价']*$item['Rate']*3;
+                $pieceWorkWage = 0;
                 //加班工资
-                $overTimePay = ($item['核算产量'] - $data[$key]['达标定额']) / 1000 *$item['千件工价'] * $item['Rate'] *1.5*3;
+                $overTimePay = $item['核算产量'] / 1000 *$item['千件工价'] * $item['Rate'] *3;
             }else{
                 //如果出勤天数小于法定天数,按正常计算
                 if (count($days[$day_bh]) <= $params['days']){

+ 169 - 151
application/api/controller/Synchronization.php

@@ -24,7 +24,6 @@ class Synchronization extends Api
         }
         $db3 = Db::connect(config('database.db3'));
         $workOrderList = $db3->name('U8_06工单资料')
-            ->where('工单编号','like','Y%')
             ->where('MES接收时间',null)
             ->where('MES接收状态','0')
             ->where('U8插入类型','<>','关闭')
@@ -34,6 +33,12 @@ class Synchronization extends Api
         }
         $j = $m = $n =0;
         foreach ($workOrderList as $key=>$value){
+            $sort = 0;
+            if (substr($value['工单编号'],0,1) === 'Y'){
+                $sort = 1;
+            }else if (substr($value['工单编号'],-2) === 'JZ' || substr($value['工单编号'],-2) === 'JS'){
+                $sort = 2;
+            }
             $code = substr($value['成品编号'],0,5);
             $client = \db('物料_存货结构')->where('编号',$code)->value('名称');
             //插入产品资料
@@ -60,75 +65,78 @@ class Synchronization extends Api
                 \db()->query($productSql);
             }
             //插入工单资料
-            $data = [
-                'Gd_gdbh' => $value['工单编号'],
-                '行号' => $value['行号'],
-                'Gd_客户代号' => $code,
-                'Gd_客户名称' => $client,
-                'Gd_khdh' => $value['客户编号'],
-                'Gd_khmc' => $value['客户名称'],
-                '客户料号' => $value['客户料号'],
-                '成品代号' => $value['成品编号'],
-                '成品名称' => $value['成品名称'],
-                'Gd_cpdh' => $value['产品编号'],
-                'Gd_cpmc' => $value['产品名称'],
-                '产品版本号' => $value['版本号'],
-                '销售订单号' => $value['销售订单号'],
-                '警语版面' => $value['警语版面'],
-                '码源数量' => substr(str_replace('.','',$value['投料数量']),0,-2),
-                'Gd_desc' => $value['备注'],
-                '接单日期' => $value['接单日期'],
-                '开单日期' => $value['开单日期'],
-                '交货日期' => $value['交货日期'],
-                '订单数量' => $value['订单数量'],
-                '实际投料' => $value['投料数量'],
-                '产品单价' => $value['产品单价'],
-                '计量单位' => '万张',
-                '成本考核_胶印' => 1,
-                '成本考核_凹印' => 1,
-                '成本考核_丝印' => 1,
-                '成本考核_模切' => 1,
-                '成本考核_检验' => 1,
-                'gd_statu' => '3-计划中',
-                'Sys_id' => '[1012/开单员]',
-                'Sys_rq' => date('Y-m-d H:i:s',time()),
-                'Mod_rq' => date('Y-m-d H:i:s',time()),
-                'U8UID' => $value['U8_UID'],
-                'Uniqid' => $value['UniqId']
-            ];
-            $workOrderdata = \db('工单_基本资料')
-                ->where('U8UID',$value['U8_UID'])
-                ->count();
-            if ($workOrderdata === 0){
-                $addSql = \db('工单_基本资料')->fetchSql(true)->insert($data);
-                $result = \db()->query($addSql);
-                if ($result === false){
-                    $m++;
-                }else{
-                    $sqlString = $db3->name('U8_06工单资料')
-                        ->where('UniqId', $value['UniqId'])
-                        ->fetchSql(true)
-                        ->update([
-                            'MES接收时间' => date('Y-m-d H:i:s', time()),
-                            'MES接收状态' => '1'
-                        ]);
-                    $db3->execute($sqlString);
-                }
-            }else{
-                unset($data['Uniqid']);
-                $updateSql = \db('工单_基本资料')->where('U8UID',$value['U8_UID'])->fetchSql(true)->update($data);
-                $updateRes = \db()->query($updateSql);
-                if ($updateRes === false){
-                    $j++;
+            if (substr($value['工单编号'],0,1) === 'Y' || substr($value['工单编号'],-2) === 'JZ' || substr($value['工单编号'],-2) === 'JS'){
+                $data = [
+                    'Gd_gdbh' => $value['工单编号'],
+                    '行号' => $value['行号'],
+                    'Gd_客户代号' => $code,
+                    'Gd_客户名称' => $client,
+                    'Gd_khdh' => $value['客户编号'],
+                    'Gd_khmc' => $value['客户名称'],
+                    '客户料号' => $value['客户料号'],
+                    '成品代号' => $value['成品编号'],
+                    '成品名称' => $value['成品名称'],
+                    'Gd_cpdh' => $value['产品编号'],
+                    'Gd_cpmc' => $value['产品名称'],
+                    '产品版本号' => $value['版本号'],
+                    '销售订单号' => $value['销售订单号'],
+                    '警语版面' => $value['警语版面'],
+                    '码源数量' => substr(str_replace('.','',$value['投料数量']),0,-2),
+                    'Gd_desc' => $value['备注'],
+                    '接单日期' => $value['接单日期'],
+                    '开单日期' => $value['开单日期'],
+                    '交货日期' => $value['交货日期'],
+                    '订单数量' => $value['订单数量'],
+                    '实际投料' => $value['投料数量'],
+                    '产品单价' => $value['产品单价'],
+                    '计量单位' => '万张',
+                    '成本考核_胶印' => 1,
+                    '成本考核_凹印' => 1,
+                    '成本考核_丝印' => 1,
+                    '成本考核_模切' => 1,
+                    '成本考核_检验' => 1,
+                    'gd_statu' => '3-计划中',
+                    'Sys_id' => '[1012/开单员]',
+                    'Sys_rq' => date('Y-m-d H:i:s',time()),
+                    'Mod_rq' => date('Y-m-d H:i:s',time()),
+                    'U8UID' => $value['U8_UID'],
+                    'Uniqid' => $value['UniqId'],
+                    '工单分类' => $sort
+                ];
+                $workOrderdata = \db('工单_基本资料')
+                    ->where('U8UID',$value['U8_UID'])
+                    ->count();
+                if ($workOrderdata === 0){
+                    $addSql = \db('工单_基本资料')->fetchSql(true)->insert($data);
+                    $result = \db()->query($addSql);
+                    if ($result === false){
+                        $m++;
+                    }else{
+                        $sqlString = $db3->name('U8_06工单资料')
+                            ->where('UniqId', $value['UniqId'])
+                            ->fetchSql(true)
+                            ->update([
+                                'MES接收时间' => date('Y-m-d H:i:s', time()),
+                                'MES接收状态' => '1'
+                            ]);
+                        $db3->execute($sqlString);
+                    }
                 }else{
-                    $sqlString = $db3->name('U8_06工单资料')
-                        ->where('UniqId', $value['UniqId'])
-                        ->fetchSql(true)
-                        ->update([
-                            'MES接收时间' => date('Y-m-d H:i:s', time()),
-                            'MES接收状态' => '1'
-                        ]);
-                    $db3->execute($sqlString);
+                    unset($data['Uniqid']);
+                    $updateSql = \db('工单_基本资料')->where('U8UID',$value['U8_UID'])->fetchSql(true)->update($data);
+                    $updateRes = \db()->query($updateSql);
+                    if ($updateRes === false){
+                        $j++;
+                    }else{
+                        $sqlString = $db3->name('U8_06工单资料')
+                            ->where('UniqId', $value['UniqId'])
+                            ->fetchSql(true)
+                            ->update([
+                                'MES接收时间' => date('Y-m-d H:i:s', time()),
+                                'MES接收状态' => '1'
+                            ]);
+                        $db3->execute($sqlString);
+                    }
                 }
             }
         }
@@ -999,86 +1007,96 @@ class Synchronization extends Api
      * @throws \think\exception\DbException
      * @throws \think\exception\PDOException
      */
-    public function ProductionData()
-    {
-        if ($this->request->isGet() === false){
-            $this->error('请求错误');
-        }
-        if(is_dir(ROOT_PATH.'public/'.date('Y-m-d',time())) == null)
-        {
-            mkdir(ROOT_PATH.'public/'.date('Y-m-d',time()),0777,true);
-        }
-        $db5 = \db()->connect(config('database.db5'));
-        $where = [
-            'sczl_rq' => ['>=','2024-04-01 00:00:00']
-        ];
-        $productData = $db5->name('设备_产量计酬')
-            ->where($where)
-            ->select();
-        var_dump($productData);
-        //获取机台信息
-        $machineData = \db('设备_基本资料')
-            ->where('mn_设备编号','<>','')
-            ->field('rtrim(设备编号) as 设备编号,rtrim(mn_设备编号) as 美浓设备编号')
-            ->select();
-        //获取员工资料
-        $employeeData = \db('人事_基本资料')
-            ->where('mn_员工编号','<>','')
-            ->field('rtrim(mn_员工编号) as 美浓员工编号')
-            ->select();
-        $employee = array_column($employeeData,'美浓员工编号');
-        //循环判断机台、员工编号
-        $j = 0;
-        $data = [];
-        foreach ($productData as $key=>$value){
-            //判断机台编号
-            foreach ($machineData as $v){
-                if ($value['sczl_jtbh'] === $v['美浓设备编号']){
-                    $productData[$key]['sczl_jtbh'] = $v['设备编号'];
-                    array_push($data,$productData[$key]);
-                }
-            }
-        }
-        if (empty($data)){
-            $this->error('未找到新的生产数据');
-        }
-        foreach ($data as $key=>$value){
-            $name = [];
-            //判断员工编号,如果不存在写入日志文件
-            for($i=1;$i<=10;$i++){
-                if (in_array($data[$key]['sczl_bh'.$i],$employee)){
-                    $data[$key]['sczl_bh'.$i] = \db('人事_基本资料')
-                        ->where('mn_员工编号',$data[$key]['sczl_bh'.$i])
-                        ->value('员工编号');
-                }else{
-                    array_push($name,$value['sczl_bh'.$i]);
-                    $data[$key]['sczl_bh'.$i] = '';
-                }
-
-            }
-            $name = array_unique($name);
-            $filename = ROOT_PATH.'public/'.date('Y-m-d',time()).'/'.$value['sczl_jtbh'].'日志文件.txt';
-            $handle = fopen($filename, 'w');
-            foreach ($name as $v){
-                fwrite($handle, $v);
-            }
-            fclose($handle);
-            //修改工单编号
-            if (preg_match("/[A-Za-z]/",$value['sczl_gdbh'])){
-                $workcode = $value['sczl_gdbh'];
-            }else{
-                $workcode = 'Y'.$value['sczl_gdbh'];
-            }
-            $data[$key]['sczl_gdbh'] = $workcode;
-        }
-        //插入设备产量计酬数据
-        \db('设备_产量计酬')->delete(true);
-        $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('同步成功');
-        }else{
-            $this->error('同步失败');
-        }
-    }
+//    public function ProductionData()
+//    {
+//        if ($this->request->isGet() === false){
+//            $this->error('请求错误');
+//        }
+//        if(is_dir(ROOT_PATH.'public/'.date('Y-m-d',time())) == null)
+//        {
+//            mkdir(ROOT_PATH.'public/'.date('Y-m-d',time()),0777,true);
+//        }
+//        $machineList = \db('设备_基本资料')
+//            ->where('mn_设备编号','<>','')
+//            ->where('sys_sbID','<>','')
+//            ->field('mn_设备编号')
+//            ->select();
+//        $machine = [];
+//        foreach ($machineList as $value){
+//            array_push($machine,$value['mn_设备编号']);
+//        }
+//        $db5 = \db()->connect(config('database.db5'));
+//        $where = [
+//            'sczl_rq' => ['>=','2024-05-01 00:00:00']
+//        ];
+//        $productData = $db5->name('设备_产量计酬')
+//            ->where($where)
+//            ->where('sczl_jtbh','in',$machine)
+//            ->select();
+//        //获取机台信息
+//        $machineData = \db('设备_基本资料')
+//            ->where('mn_设备编号','<>','')
+//            ->where('sys_sbID','<>','')
+//            ->field('rtrim(设备编号) as 设备编号,rtrim(mn_设备编号) as 美浓设备编号')
+//            ->select();
+//        //获取员工资料
+//        $employeeData = \db('人事_基本资料')
+//            ->where('mn_员工编号','<>','')
+//            ->field('rtrim(mn_员工编号) as 美浓员工编号')
+//            ->select();
+//        $employee = array_column($employeeData,'美浓员工编号');
+//        //循环判断机台、员工编号
+//        $j = 0;
+//        $data = [];
+//        foreach ($productData as $key=>$value){
+////            判断机台编号
+//            foreach ($machineData as $v){
+//                if ($value['sczl_jtbh'] === $v['美浓设备编号']){
+//                    $productData[$key]['sczl_jtbh'] = $v['美浓设备编号'];
+//                    array_push($data,$productData[$key]);
+//                }
+//            }
+//        }
+//        if (empty($data)){
+//            $this->error('未找到新的生产数据');
+//        }
+//        foreach ($data as $key=>$value){
+//            $name = [];
+//            //判断员工编号,如果不存在写入日志文件
+//            for($i=1;$i<=10;$i++){
+//                if (in_array($data[$key]['sczl_bh'.$i],$employee)){
+//                    $data[$key]['sczl_bh'.$i] = \db('人事_基本资料')
+//                        ->where('mn_员工编号',$data[$key]['sczl_bh'.$i])
+//                        ->value('员工编号');
+//                }else{
+//                    array_push($name,$value['sczl_bh'.$i]);
+//                    $data[$key]['sczl_bh'.$i] = '';
+//                }
+//
+//            }
+//            $name = array_unique($name);
+//            $filename = ROOT_PATH.'public/'.date('Y-m-d',time()).'/'.$value['sczl_jtbh'].'日志文件.txt';
+//            $handle = fopen($filename, 'w');
+//            foreach ($name as $v){
+//                fwrite($handle, $v);
+//            }
+//            fclose($handle);
+//            //修改工单编号
+////            if (preg_match("/[A-Za-z]/",$value['sczl_gdbh'])){
+////                $workcode = $value['sczl_gdbh'];
+////            }else{
+////                $workcode = 'Y'.$value['sczl_gdbh'];
+////            }
+////            $data[$key]['sczl_gdbh'] = $workcode;
+//        }
+//        //插入设备产量计酬数据
+//        \db('设备_产量计酬')->delete(true);
+//        $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
+//        $res = \db()->query($sql);
+//        if ($res !== false){
+//            $this->success('同步成功');
+//        }else{
+//            $this->error('同步失败');
+//        }
+//    }
 }

+ 81 - 29
application/api/controller/WorkOrder.php

@@ -30,34 +30,35 @@ class WorkOrder extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
+        $param = $this->request->param();
+        if (isset($param['sort'])){
+            $where['工单分类'] = 2;
+        }else{
+            $where['工单分类'] = 1;
+        }
+        $where['行号'] = ['in',['1','10']];
         //获取总计划中数量和总生产中数量
-        $productingAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
-        $progressAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
+        $productingAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
+        $progressAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
         $data = [
             'productingAll' => $productingAll,
             'progressAll' => $progressAll,
-            '印刷工单' => [],
-            '糊盒工单' => []
+            '客户编号' => []
         ];
-        $sql = "SELECT DISTINCT
-                    (客户编号),rtrim(客户名称 ) as 客户名称
-                FROM
-                    `产品_基本资料` 
-                WHERE 
-                    客户编号 <> ''
-                GROUP BY
-                    客户编号
-                order by 
-                    客户编号";
-        $list = \db()->query($sql);
+        $list = \db('产品_基本资料')
+            ->where('客户编号','<>','')
+            ->field('客户编号,客户名称')
+            ->group('客户编号,客户名称')
+            ->order('客户编号')
+            ->select();
         if (empty($list)){
             $this->success('',[]);
         }
         foreach ($list as $key=>$value){
             $value['客户编号'] = rtrim($value['客户编号']);
             //这条sql查出来的数据可能不对,试一下以下sql
-            $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
-            $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
+            $productIng = \db('工单_基本资料')->where($where)->where('Gd_cpdh','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
+            $proGress = \db('工单_基本资料')->where($where)->where('Gd_cpdh','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
             $string = '';
             if ($productIng != 0){
                 $string = $string."生产中:".$productIng;
@@ -67,11 +68,12 @@ class WorkOrder extends Api
             }
             if ($string !== ''){
                 $name = $value['客户编号'].'【'.$string.'】'.$value['客户名称'];
-                if (strpos($value['客户编号'],'J') !== false){
-                    array_push($data['糊盒工单'],$name);
-                }else{
-                    array_push($data['印刷工单'],$name);
-                }
+//                if (strpos($value['客户编号'],'J') !== false){
+//                    array_push($data['糊盒工单'],$name);
+//                }else{
+//                    array_push($data['印刷工单'],$name);
+//                }
+                array_push($data['客户编号'],$name);
             }
 //            else{
 //                $name = $value['客户编号'].$value['客户名称'];
@@ -106,6 +108,12 @@ class WorkOrder extends Api
         $endTime = input('end');
         $page = input('page');
         $limit = input('limit');
+        $param = $this->request->param();
+        if (isset($param['sort'])){
+            $sort = 2;
+        }else{
+            $sort = 1;
+        }
         $where = [];
         if (!empty($clientNumber)){
             if ($clientNumber === 'Y1401'){
@@ -114,6 +122,11 @@ class WorkOrder extends Api
                 $where['成品代号'] = ['like',$clientNumber.'%'];
             }
         }
+        if (substr($clientNumber,0,1) === 'Y'){
+            $where['工单分类'] = 1;
+        }elseif (substr($clientNumber,0,1) === 'J'){
+            $where['工单分类'] = 2;
+        }
         if (!empty($workOrder)){
             $where['Gd_gdbh'] = $workOrder;
         }
@@ -126,12 +139,14 @@ class WorkOrder extends Api
         if (!empty($startTime) && !empty($endTime)){
             $where['接单日期'] = ['between',[$startTime,$endTime]];
         }
-        $where['行号'] = 1;
-        $total = \db('工单_基本资料')->where($where)->count();
+        $where['工单分类'] = $sort;
+//        $where['行号'] = ['in',['1','10']];
+        $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
         $list = \db('工单_基本资料')
             ->where($where)
             ->order('Gd_statu desc')
             ->limit(($page-1)*$limit,$limit)
+            ->group('Gd_gdbh')
             ->select();
         //工单基本资料数据整理
         $data = [];
@@ -184,13 +199,20 @@ class WorkOrder extends Api
             $this->error('请求错误');
         }
         $Gd_gdbh = input('Gd_gdbh');
+        $param = $this->request->param();
         if (empty($Gd_gdbh)){
             $this->error('参数错误');
         }
+        if (isset($param['sort'])){
+            $where['yj_Yjno'] = ['>=','10'];
+        }else{
+            $where['yj_Yjno'] = ['<','10'];
+        }
         $data = [];
         //印件资料
         $printList = \db('工单_印件资料')
             ->where('Yj_Gdbh',$Gd_gdbh)
+            ->where($where)
             ->select();
         if (!empty($printList)){
             foreach ($printList as $key=>$value){
@@ -229,8 +251,14 @@ class WorkOrder extends Api
         }
 
         //工艺资料
+        if (isset($param['sort'])){
+            $Prowhere['Gy0_yjno'] = ['>=','10'];
+        }else{
+            $Prowhere['Gy0_yjno'] = ['<','10'];
+        }
         $processList = \db('工单_工艺资料')
             ->where('Gy0_gdbh',$Gd_gdbh)
+            ->where($Prowhere)
             ->order('Gy0_yjno,Gy0_gxh')
             ->select();
         if (!empty($processList)){
@@ -1231,6 +1259,7 @@ class WorkOrder extends Api
                 RTRIM( a.交货日期 ) AS 交货日期,
                 RTRIM( a.Gd_desc ) AS 工单说明,
                 RTRIM( a.投料率 ) AS 投料率,
+                RTRIM( a.订单数量 ) AS 订单数量,
                 RTRIM( a.平均合格率 ) AS 平均合格率,
                 RTRIM( a.投料大箱 ) AS 订货数量,
                 RTRIM( a.排产时库存 ) AS 排产时库存,
@@ -1254,10 +1283,16 @@ class WorkOrder extends Api
         }
         $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
         $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
-        $list[0]['订货数量'] = (int)$list[0]['订货数量'];
+        if (strpos($list[0]['产品名称'],'条') !== false){
+            $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
+            $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
+        }else{
+            $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
+            $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
+        }
         $list[0]['联数'] = (int)$list[0]['联数'];
         $list[0]['印件代号及名称']  = $list[0]['印件代号'].' '.$list[0]['印件名称'];
-        $list[0]['投料数量'] = $list[0]['订货数量'];
+//        $list[0]['投料数量'] = $list[0]['订货数量'];
         unset($list[0]['印件代号'],$list[0]['印件名称']);
         return($list[0]);
     }
@@ -1386,6 +1421,12 @@ class WorkOrder extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
+        if (isset($param['sort'])){
+            $sort = 2;
+            unset($param['sort']);
+        }else{
+            $sort = 1;
+        }
         $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
         //插入产品资料
         $productData = \db('产品_基本资料')
@@ -1417,9 +1458,6 @@ class WorkOrder extends Api
             $productDetail['客户料号'] = '';
         }
         $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
-        if ($lastId<1000000000){
-            $lastId = 1000000000;
-        }
         $data = [
             'Gd_lx' =>$param['zdgd'],
             'Gd_生产分类' =>$param['sclx'],
@@ -1497,6 +1535,7 @@ class WorkOrder extends Api
             'U8UID' => '',
             'Uniqid' => $lastId+1,
             '工序加工费' => 0,
+            '工单分类' => $sort,
         ];
         $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
         $res = \db()->query($sql);
@@ -2092,10 +2131,18 @@ class WorkOrder extends Api
         if (Request::instance()->isPost() === false){
             $this->error('请求错误');
         }
+
         $param = Request::instance()->post();
         if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
             $this->error('参数错误');
         }
+        if (isset($param)){
+            $priWhere['yj_yjno'] = ['>=',10];
+            $proWhere['Gy0_yjno'] = ['>=',10];
+        }else{
+            $priWhere['yj_yjno'] = ['<',10];
+            $proWhere['Gy0_yjno'] = ['<',10];
+        }
         $list = \db('工单_基本资料')
             ->where('Gd_gdbh',$param['workorder'])
             ->where('成品代号',$param['productCode'])
@@ -2104,6 +2151,7 @@ class WorkOrder extends Api
         //引用印件资料
         $PrintList = \db('产品_印件资料')
             ->where('yj_cpdh',$param['productCode'])
+            ->where($priWhere)
             ->select();
         if (empty($PrintList)){
             $this->error('未找到印件资料');
@@ -2145,6 +2193,7 @@ class WorkOrder extends Api
         ];
         $ProcessList = \db('产品_工艺资料')
             ->where($processWhere)
+            ->where($proWhere)
             ->order('Gy0_yjno,Gy0_gxh')
             ->select();
         if (empty($ProcessList)){
@@ -2157,6 +2206,9 @@ class WorkOrder extends Api
                 $rate['rate1'] = 0;
             }else{
                 $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+                if (empty($rate)){
+                    $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
+                }
             }
             //设置默认机台
             $machineList = \db('设备_基本资料')

+ 5 - 5
application/api/controller/WorkOrderVerification.php

@@ -294,7 +294,7 @@ class WorkOrderVerification extends Api
             ->where('a.Gd_gdbh',$params['order'])
             ->where('a.行号',1)
             ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
-            ->find();
+            ->select();
         $this->success('请求成功',$list);
     }
     /**
@@ -338,11 +338,11 @@ class WorkOrderVerification extends Api
             $this->error('非法请求');
         }
         $params = Request::instance()->param();
-        if (!isset($params['search']) || empty($params['search'])){
-            $this->error('参数错误');
-        }
         $where['分类'] = '废品分类';
-        $where['名称'] = array('like','%'.$params['search'].'%');
+        if (!empty($params['search'])){
+            $where['名称'] = array('like','%'.$params['search'].'%');
+        }
+
         $data = db('erp_常用字典')->where($where)->column('名称');
         // 分割字符串并合并相同项
         $resultArray = [];