Kaynağa Gözat

生产管理

qiuenguang 1 yıl önce
ebeveyn
işleme
8b4355f346

+ 174 - 4
application/api/controller/Facility.php

@@ -31,6 +31,7 @@ class Facility extends Api
         }
         $data = [];
         $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
+        $date = date('Y-m-d H:i:s',time()-3888000);
         if (empty($department)){
             $this->error('未获取到机台数据');
         }
@@ -39,13 +40,19 @@ class Facility extends Api
                 $machine = Db::table('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
                 foreach ($machine as $kk=>$vv){
                     if ($vv['设备编号'] !== 'ZH01#'){
-                        $date = Db::table('设备_产量计酬')->where('sczl_jtbh',$vv['设备编号'])->distinct(true)->cache(60)->order('UniqId desc')->limit(40)->column('sczl_rq');
+                        $date = Db::table('设备_产量计酬')
+                            ->where('sczl_jtbh',$vv['设备编号'])
+                            ->where('sczl_rq','> time',$date)
+                            ->distinct(true)
+                            ->cache(true)
+                            ->limit(40)
+                            ->order('UniqId desc')
+                            ->column('sczl_rq');
                         $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
                     }
                 }
             }
         }
-
         $this->success('成功',$data);
     }
 
@@ -668,7 +675,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)->field($filed)->select();
+        $list = Db::table('制程检验_记录')->where($where)
+            ->where('UniqId','>',$startId)
+            ->field($filed)
+//            ->fetchSql(true)
+            ->select();
         if (empty($list)){
             $this->error('未找到该工单当前班次巡检记录');
         }
@@ -789,8 +800,16 @@ class Facility extends Api
         $this->success('成功',$list);
     }
 
-    //设备点检->检测记录添加
 
+    /**
+     * 设备点检->检测记录添加
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
     public  function InspectionItemAdd()
     {
         if ($this->request->isPost()  === false){
@@ -800,6 +819,157 @@ class Facility extends Api
         if (empty($param)){
             $this->error('参数错误');
         }
+        $data = [
+            'team' => $param['team'],
+            'machine' => $param['machine'],
+            'unitName' => $param['unitName']
+        ];
+        unset($param['team'],$param['machine'],$param['unitName']);
+        $lastId = Db::table('设备_点检记录')->field('rtrim(Uniqid) as id')->order('Uniqid desc')->find();
+        $unitCode = Db::table('设备_点检项目')->where('部件名称',$data['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
+        $row = [];
+        $param = array_values($param);
+        foreach ($param as $key=>$value){
+            $value = explode(';',$value);
+            $row[$key] = [
+                '日期' => date('Y-m-d 00:00:00',time()),
+                '班组编号' => $data['team'],
+                '点检设备' => $data['machine'],
+                '部件编号' => $unitCode['部件编号'],
+                '部件名称' => $data['unitName'],
+                '检验项目' => $value[0],
+                '判定标准' => $value[4],
+                '点检方法' => $value[1],
+                '点检结果' => $value[2],
+                '备注说明' => $value[3],
+                'Sys_id'  =>'',
+                'Sys_rq'  => date('Y-m-d H:i:s',time()),
+                'Mod_rq'  => '',
+                'Uniqid'  => $lastId['id']+$key+1
+            ];
+
+        }
+        $sql = Db::table('设备_点检记录')->fetchSql(true)->insertAll($row);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
 
+
+    /**
+     * 机台印版领用->左侧菜单
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function PrintGetTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $productCode = $param['productCode'];
+        $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
+                JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
+                WHERE a.YB_Cpdh = '{$productCode}'";
+        $res = Db::query($sql);
+        if (empty($res)){
+            $this->error('未找到该产品印版资料');
+        }
+        $this->success('成功',$res);
+    }
+
+    /**
+     * 机台印版领用记录->数据详情
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function PrintDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求失败');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $productCode = $param['productCode'];
+        $code = $param['code'].'%';
+        $workOrder = $param['workOrder'];
+        $sql = "SELECT 
+                RTRIM(a.`存货编码`) as `存货编码`,
+                RTRIM(c.`物料名称`) as `存货名称`,
+                RTRIM(b.`印版名称`) as `印版名称`,
+                RTRIM(b.`供方批号`) as `供方批号`,
+                RTRIM(b.`制造日期`) as `制造日期`,
+                SUM(d.`Yb_印数`) as `印数`,
+                RTRIM(e.`名称`) as `印版类别`,
+                SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
+                RTRIM(f.`Gd_客户名称`) as `客户名称`,
+                RTRIM(a.YB_Cpdh) as `产品编号`,
+                RTRIM(f.Gd_cpmc) as `产品名称`
+                FROM `产品_印版资料` as a 
+                LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
+                JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
+                LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
+                JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
+                JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
+                WHERE a.YB_Cpdh = '{$productCode}' 
+                AND a.`存货编码` LIKE '{$code}'
+                AND f.Gd_gdbh = '{$workOrder}'
+                AND b.`报废日期` = '1900-01-01 00:00:00'
+                GROUP BY b.`供方批号`
+                ORDER BY a.`存货编码`";
+        $list = Db::query($sql);
+        if (empty($list)){
+            $this->error('未找到印版');
+        }
+        $this->success('成功',$list);
+    }
+
+    //换型清场记录->左侧菜单栏
+
+    public function remodelGetTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $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('设备编号');
+        if (empty($list)){
+            $this->error('失败');
+        }
+        $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId FROM `设备_基本资料` as a 
+                LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
+                WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' ORDER BY b.`日期`";
+        $res = Db::query($sql);
+        $data = [];
+        foreach ($list as $key=>$value){
+            $i=0;
+            $data[$value] = [];
+            foreach ($res as $k=>$v){
+                $row = [];
+                if ($value === $v['设备编号']){
+                    $row[$i] = [
+                        '日期' => $v['日期'],
+                        'id' => $v['UniqId']
+                    ];
+                    $i++;
+                    foreach ($row as $vv){
+
+                    }
+                    array_push($data[$value],$row);
+                }
+            }
+        }
+        $this->success('成功',$data);
     }
 }

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

@@ -69,6 +69,12 @@ class Manufacture extends Api
         }
         foreach ($list as $key=>$value){
             $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
+            $number = Db::table('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
+            if ($number === 0){
+                $list[$key]['status'] = 0;
+            }else{
+                $list[$key]['status'] = 1;
+            }
         }
         $this->success('成功',$list);
     }

+ 177 - 4
application/api/controller/WorkOrder.php

@@ -320,7 +320,7 @@ class WorkOrder extends Api
         }
         $printData = Db::table('工单_印件资料')
             ->where('Yj_Gdbh',$workOrder)
-            ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料')
+            ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料,rtrim(Uniqid) as id')
             ->find();
         if (empty($printData)){
             $this->error('未找到该工单印件资料');
@@ -328,6 +328,7 @@ class WorkOrder extends Api
         $list['印件名称'] = $printData['印件名称'];
         $list['印件代号'] = $printData['印件代号'];
         $list['平张投料'] = $printData['平张投料'];
+        $list['印件ID'] = $printData['id'];
         $this->success('成功',$list);
     }
 
@@ -372,10 +373,17 @@ class WorkOrder extends Api
             '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
             '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
             'Gd_desc' => isset($param['desc'])?$param['desc']:'',
+            '排产时库存' => isset($param['kc'])?$param['kc']:'',
+            '平均合格率' => isset($param['avg'])?$param['avg']:'',
         ];
         $sql = Db::table('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
         $res = Db::query($sql);
-        if ($res !== false){
+        $printSql = Db::table('工单_印件资料')
+            ->where('Uniqid',$param['printID'])
+            ->fetchSql(true)
+            ->update(['yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
+        $printRes = Db::query($printSql);
+        if ($res !== false && $printRes !== false){
             $this->success('成功');
         }else{
             $this->error('失败');
@@ -844,7 +852,9 @@ class WorkOrder extends Api
         }
         $i = 0;
         foreach ($param as $key=>$value){
-            $data = Db::table('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+            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();
+            }
             $row = [
                 '工价系数' => $value['difficulty']?:'',
                 'Gy0_shdh' => $value['loss']?:'',
@@ -975,5 +985,168 @@ class WorkOrder extends Api
         }
     }
 
-    //
+    /**
+     * 打印作业通知单
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintJobOrder()
+    {
+        if ($this->request->isPost() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $data = $this->workOrderDetailGet($param['workOrder']);
+        if (empty($data)){
+            $this->error('未找到工单信息');
+        }
+        $materiel = $this->MaterielDetailGet($param['workOrder']);
+        if (empty($materiel)){
+            $this->error('未找到物料信息');
+        }
+        $printDetail = $this->PrintDetailGet($param['workOrder']);
+        if (empty($printDetail)){
+            $this->error('未找到工艺信息');
+        }
+        $number = 0;
+        foreach ($printDetail as $key=>$value){
+            $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
+            $number = $number+$value['允损比例'];
+        }
+        $data['制单'] = $param['PrepareDocument'];
+        $data['审核'] = $param['examine'];
+        $data['目标合格率'] = 100-$number.'%';
+        $data['materiel'] = $materiel;
+        $data['printDetail'] = $printDetail;
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 打印作业通知单->工单及印件资料获取
+     * @param $workOrder
+     * @return mixed
+     */
+    public function workOrderDetailGet($workOrder)
+    {
+        $sql = "SELECT
+                RTRIM( a.Gd_gdbh ) AS 生产批次号,
+                RTRIM( a.销售订单号 ) AS 销售订单号,
+                RTRIM( a.Gd_客户代号 ) AS 客户代号,
+                RTRIM( a.Gd_客户名称 ) AS 客户名称,
+                RTRIM( a.成品代号 ) AS 产品代码,
+                RTRIM( a.成品名称 ) AS 产品名称,
+                RTRIM( a.产品版本号 ) AS 版本号,
+                RTRIM( a.警语版面 ) AS 警语版面,
+                RTRIM( a.码源数量 ) AS 码源数量,
+                RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
+                RTRIM( a.接单日期 ) AS 开单日期,
+                RTRIM( a.交货日期 ) AS 交货日期,
+                RTRIM( a.Gd_desc ) AS 工单说明,
+                RTRIM( a.投料率 ) AS 投料率,
+                RTRIM( a.平均合格率 ) AS 平均合格率,
+                RTRIM( a.投料大箱 ) AS 订货数量,
+                RTRIM( a.排产时库存 ) AS 排产时库存,
+                RTRIM( b.yj_Yjno ) AS 印件,
+                RTRIM( b.yj_Yjdh ) AS 印件代号,
+                RTRIM( b.yj_yjmc ) AS 印件名称,
+                RTRIM( b.yj_平张投料 ) AS 平张投料量,
+                RTRIM( b.yj_zzmc ) AS 纸张名称,
+                RTRIM( b.yj_tlgg ) AS 投料规格,
+                RTRIM( b.yj_ks ) AS 开数,
+                RTRIM( b.yj_ls ) AS 联数,
+                RTRIM( b.yj_desc ) AS 印件备注 
+            FROM
+                `工单_基本资料` AS a
+                JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh 
+            WHERE
+                a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1";
+        $list = Db::query($sql);
+        if (empty($list)){
+            $this->error('未找到订单数据');
+        }
+        $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
+        $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
+        $list[0]['订货数量'] = (int)$list[0]['订货数量'];
+        $list[0]['联数'] = (int)$list[0]['联数'];
+        $list[0]['印件代号及名称']  = $list[0]['印件代号'].' '.$list[0]['印件名称'];
+        $list[0]['投料数量'] = $list[0]['订货数量'];
+        unset($list[0]['印件代号'],$list[0]['印件名称']);
+        return($list[0]);
+    }
+
+    /**打印作业流程单->物料资料获取
+     * @param $workOrder
+     * @return bool|\PDOStatement|string|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MaterielDetailGet($workOrder)
+    {
+        $where = [
+            'BOM_工单编号' => $workOrder,
+        ];
+        $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
+        $list = Db::table('工单_bom资料')->where($where)->field($filed)->select();
+        if (empty($list)){
+            $this->error('未找到物料资料信息');
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
+            $list[$key]['计划用量'] = (float)$value['计划用量'];
+            unset($list[$key]['物料编码'],$list[$key]['物料名称']);
+        }
+        return $list;
+    }
+
+    /**
+     * 打印作业流程单->工艺资料获取
+     * @param $workOrder
+     * @return bool|\PDOStatement|string|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintDetailGet($workOrder)
+    {
+        $where = [
+            'Gy0_gdbh' => $workOrder,
+        ];
+        $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('工单_工艺资料')
+            ->where($where)
+            ->field($filed)
+            ->select();
+        if (empty($list)){
+            $this->error('工单工艺为空');
+        }
+        foreach ($list  as $key=>$value){
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            if ($value['add_gxmc'] !== null){
+
+                $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
+            }else{
+                $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
+            }
+            $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
+            $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
+            $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
+            unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
+        }
+        return $list;
+    }
 }