فهرست منبع

机台生产日报表 excel导出 成品入仓 侧边栏 列表 定位 获取详细信息

曹鹤洋 1 سال پیش
والد
کامیت
4d000073db
2فایلهای تغییر یافته به همراه1178 افزوده شده و 38 حذف شده
  1. 738 0
      application/api/controller/FinishedProductWarehousing.php
  2. 440 38
      application/api/controller/MachineProductionReport.php

+ 738 - 0
application/api/controller/FinishedProductWarehousing.php

@@ -0,0 +1,738 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+
+/**
+ * 成品入仓维护接口
+ */
+class FinishedProductWarehousing extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+
+    /**
+     * 侧边栏
+     * @ApiMethod (GET)
+     */
+    public function getTab()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $rows = db()->table('成品入仓')
+            ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
+            ->group('date')
+            ->order('UniqId desc')
+            ->limit(50)
+            ->select();
+
+        $arr = db()->table('成品入仓')
+            ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
+            ->where('sys_rq','>=',$rows[49]['date'])
+            ->group('date, sys_id')
+            ->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]);
+                }
+            }
+            $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
+        }
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 侧边栏
+     * @ApiMethod (GET)
+     */
+    public function getTabByGdbh()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+//        $sql = 'SELECT DISTINCT Gd_客户代号  FROM `工单_基本资料` ORDER BY Gd_客户代号 DESC';
+//        $rows = db()->query($sql);
+        $rows = db()->table('成品入仓')->alias('c')
+            ->field('g.Gd_khdh')
+            ->join('工单_基本资料 g','c.jjcp_gdbh = g.Gd_gdbh')
+//            ->distinct('g.Gd_khdh')
+            ->order('c.Sys_rq desc')
+            ->select();
+halt($rows);
+        $arr = db()->table('成品入仓')
+            ->field('sczl_gdbh,rtrim(sys_id) as sys_id')
+            ->where('sczl_gdbh','>=',$rows[64]['sczl_gdbh'])
+            ->select();
+
+        $brr = [];
+        foreach($arr as $k=>$v){
+            if(array_key_exists($v['sczl_gdbh'],$brr)){
+                if(array_key_exists($v['sys_id'],$brr[$v['sczl_gdbh']])){
+                    $brr[$v['sczl_gdbh']][$v['sys_id']] += 1;
+                }else{
+                    $brr[$v['sczl_gdbh']][$v['sys_id']] = 1;
+                }
+            }else{
+                $brr[$v['sczl_gdbh']][$v['sys_id']] = 1;
+            }
+        }
+
+        foreach($rows as $key=>$value){
+            $rows[$key]['sys'] = $brr[$value['sczl_gdbh']];
+            $rows[$key]['yj_yjmc'] = trim($value['yj_yjmc']);
+        }
+        
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 列表
+     * @ApiMethod (GET)
+     * @param string $date 时间
+     * @param string $sys_id 用户
+     */
+    public function getList()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
+
+        $page = 1;
+        $limit = 15;
+        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
+        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
+
+        if(strpos($req['date'],'-')){
+            $where = ['c.Sys_rq'=>['like','%'.$req['date'].'%']];
+            $option = ['Sys_rq'=>['like','%'.$req['date'].'%']];
+        }else{
+            $where = ['c.sczl_gdbh'=>$req['date']];
+            $option = ['sczl_gdbh'=>$req['date']];
+        }
+        if (isset($req['sys_id']) && !empty($req['sys_id'])){
+            $where['c.Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
+            $option['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
+        }
+
+        //客户编号
+        $rows = db()->table('成品入仓')->alias('c')
+            ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
+            rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
+            c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
+            rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc, 
+            rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
+            rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称, 
+            rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
+            ->where($where)
+            ->where('y.yj_Yjno=c.jjcp_yjno')
+            ->where('g.Gd_cpdh=c.jjcp_cpdh')
+            ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+            ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
+            ->order('c.UniqId desc')
+            ->page($page,$limit)
+            ->select();
+
+        $total = db()->table('成品入仓')->where($option)->count();
+        foreach ($rows as $key=>$value) {
+            $row = db()->table('成品入仓')
+                ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
+                ->where('jjcp_gdbh',$value['jjcp_gdbh'])
+                ->order('Sys_rq desc')
+                ->select();
+            $rows[$key]['jjcp_sls'] = 0;
+            foreach ($row as $k=>$v) {
+                $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
+            }
+            if ($value['订单数量']!=0){
+                $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
+            }else{
+                $rows[$key]['完成率'] = '';
+            }
+            $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
+            $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
+
+            $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
+        }
+
+        $data = [
+            'total'          => $total,
+            'rows'          => $rows,
+        ];
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 定位
+     * @ApiMethod (GET)
+     * @param string $gdbh 工单编号
+     * @param string $cpmc 产品名称
+     * @param string $page 页码
+     * @param string $limit 数量
+     */
+    public function locate()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        $page = 1;
+        $limit = 15;
+        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
+        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
+
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $where = ['c.jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
+            $option = ['jjcp_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']];
+            //客户编号
+            $rows = db()->table('成品入仓')->alias('c')
+                ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
+            rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
+            c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
+            rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc, 
+            rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
+            rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称, 
+            rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
+                ->where($where)
+                ->where('y.yj_Yjno=c.jjcp_yjno')
+                ->where('g.Gd_cpdh=c.jjcp_cpdh')
+                ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+                ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
+                ->order('c.UniqId desc')
+                ->page($page,$limit)
+                ->select();
+            $total = db()->table('成品入仓')->where($option)->count();
+        }else{
+            if (isset($req['cpmc']) && !empty($req['cpmc'])){
+                //查询工单表
+                $gd = db()->table('工单_基本资料')
+                    ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
+                    ->column('Gd_gdbh');
+                $where = ['c.jjcp_gdbh'=>['in', $gd]];
+                $option = ['jjcp_gdbh'=>['in', $gd]];
+                //客户编号
+                $rows = db()->table('成品入仓')->alias('c')
+                    ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
+            rtrim(c.jjcp_num) as jjcp_num, c.jjcp_gdbh, 
+            c.jjcp_yjno, c.jjcp_sl, g.订单数量, rtrim(c.jjcp_dw) as jjcp_dw, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
+            rtrim(c.jjcp_smb) as jjcp_smb, rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc, 
+            rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
+            rtrim(c.客户料号) as 客户料号, rtrim(c.jjcp_desc) as jjcp_desc, g.Gd_khdh, rtrim(g.Gd_khdh) as Gd_khdh, rtrim(g.Gd_客户名称) as Gd_客户名称, 
+            rtrim(c.机型备注) as 机型备注, rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
+                    ->where($where)
+                    ->where('y.yj_Yjno=c.jjcp_yjno')
+                    ->where('g.Gd_cpdh=c.jjcp_cpdh')
+                    ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+                    ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
+                    ->order('c.UniqId desc')
+                    ->page($page,$limit)
+                    ->select();
+                $total = db()->table('成品入仓')->where($option)->count();
+            }else{
+                $this->error('参数错误');
+            }
+        }
+        foreach ($rows as $key=>$value) {
+            $row = db()->table('成品入仓')
+                ->field('LEFT(Sys_rq, 10) as Sys_rq,jjcp_sl')
+                ->where('jjcp_gdbh',$value['jjcp_gdbh'])
+                ->order('Sys_rq desc')
+                ->select();
+            $rows[$key]['jjcp_sls'] = 0;
+            foreach ($row as $k=>$v) {
+                $rows[$key]['jjcp_sls'] += $v['jjcp_sl'];
+            }
+            if ($value['订单数量']!=0){
+                $rows[$key]['完成率'] = number_format($rows[$key]['jjcp_sls']/$value['订单数量']/100,2);
+            }else{
+                $rows[$key]['完成率'] = '';
+            }
+            $rows[$key]['订单数量'] = floatval($value['订单数量']*10000);
+            $rows[$key]['最近入仓日期'] = $row[0]['Sys_rq'];
+
+            $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
+        }
+        $data = [
+            'total'    => $total,
+            'rows'          => $rows,
+        ];
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 获取信息
+     * @ApiMethod (GET)
+     * @param string $UniqId UniqId
+     */
+    public function getInfo()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['UniqId']) && !empty($req['UniqId'])){
+            $UniqId = $req['UniqId'];
+        }else{
+            $this->error('参数错误');
+        }
+        //客户编号
+        $rows = db()->table('成品入仓')->alias('c')
+            ->field('rtrim(c.入仓类型) as 入仓类型, rtrim(c.仓库编号) as 仓库编号, rtrim(c.仓库名称) as 仓库名称, 
+            rtrim(c.jjcp_num) as jjcp_num, 
+            c.jjcp_gdbh, c.jjcp_yjno, rtrim(c.订单编号) as 订单编号, 
+            rtrim(y.yj_Yjdh) as yj_Yjdh, rtrim(y.yj_yjmc) as yj_yjmc, 
+            rtrim(c.jjcp_cpdh) as jjcp_cpdh, rtrim(c.jjcp_cpmc) as jjcp_cpmc, 
+            rtrim(c.客户料号) as 客户料号, 
+            rtrim(c.jjcp_smb) as jjcp_smb, LEFT(c.jjcp_sj, 10) as jjcp_sj, 
+            c.jjcp_sl, rtrim(c.jjcp_dw) as jjcp_dw, 
+            g.订单数量, rtrim(c.机型备注) as 机型备注, rtrim(c.jjcp_desc) as jjcp_desc, 
+            rtrim(c.Sys_id) as Sys_id, c.Sys_rq, c.Mod_rq, c.UniqId')
+            ->where('c.UniqId',$UniqId)
+            ->where('y.yj_Yjno=c.jjcp_yjno')
+            ->where('g.Gd_cpdh=c.jjcp_cpdh')
+            ->join('工单_基本资料 g','g.Gd_gdbh=c.jjcp_gdbh')
+            ->join('工单_印件资料 y','y.Yj_Gdbh=c.jjcp_gdbh')
+            ->find();
+        $rows['jjcp_sls'] = db()->table('成品入仓')
+            ->where('jjcp_gdbh',$rows['jjcp_gdbh'])
+            ->order('Sys_rq desc')
+            ->sum('jjcp_sl');
+        $rows['订单数量'] = floatval($rows['订单数量']*10000);
+
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 查询印件工序及产品名称
+     * @ApiMethod (GET)
+     * @param string $gdbh 工单编号
+     * @param string $gxmc 工序名称
+     */
+    public function getGxMc()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $gdbh = $req['gdbh'];
+        }else{
+            $this->error('参数错误');
+        }
+        $gxmc = ['包装','成品防护'];
+
+        $gxmcs = [];
+        foreach ($gxmc as $k=>$v){
+            array_push($gxmcs,['like','%'.$v.'%']);
+        }
+        array_push($gxmcs,'OR');
+
+        $rows = db()->table('工单_基本资料')->alias('g')
+            ->field('rtrim(g.Gd_cpmc) as Gd_cpmc, c.Gy0_yjno, c.Gy0_gxh, rtrim(c.Gy0_gxmc) as Gy0_gxmc')
+            ->where(['g.Gd_gdbh'=>$gdbh])
+            ->where(['c.Gy0_gxmc'=>$gxmcs])
+            ->join(['产品_印件资料'=>'j'],'g.Gd_cpdh=j.yj_yjdh and g.成品代号=j.yj_cpdh')
+            ->join(['工单_工艺资料'=>'c'],'c.Gy0_gdbh=g.Gd_gdbh and c.Gy0_yjno=j.yj_yjno')
+            ->select();
+
+        foreach ($rows as $key=>$value){
+            $rows[$key]['jyGx'] =  sprintf("%02d", $value['Gy0_yjno']).'-'.$value['Gy0_gxh'];
+        }
+
+        $this->success('成功',$rows);
+    }
+
+
+    /**
+     * 查询员工名称
+     * @ApiMethod (GET)
+     * @param string $sczl_bh 员工编号
+     */
+    public function getYg()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['sczl_bh']) && !empty($req['sczl_bh'])){
+            $sczl_bh = $req['sczl_bh'];
+        }else{
+            $this->error('参数错误');
+        }
+        $rs = db()->table('人事_基本资料')->field('rtrim(员工姓名) as ygxm')->where('员工编号',$sczl_bh)->find();
+        if(!$rs){
+            $this->error('失败');
+        }
+        $this->success('成功',$rs);
+    }
+
+
+    /**
+     * 新增
+     * @ApiMethod (POST)
+     * @param string 'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
+    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
+    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
+    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
+    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
+    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
+    'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
+    'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
+    'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
+    'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
+    'sczl_desc'
+     */
+    public function add()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
+            'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
+            'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
+            'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
+            'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
+            'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
+            'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
+            'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
+            'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
+            'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
+            'sczl_desc'
+        ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                $this->error('参数错误',$value,$key+1);
+            }
+            $data[$value] = $req[$value];
+        }
+        $data['sys_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('成品入仓')->fetchSql(true)->insert($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+
+    }
+
+    /**
+     * 修改
+     * @ApiMethod (POST)
+     * @param string 'UniqId','sczl_rq',
+    'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
+    'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
+    'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
+    'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
+    'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
+    'sczl_clAdd1', 'sczl_clAdd2', 'sczl_clAdd3', 'sczl_clAdd4', 'sczl_clAdd5', 'sczl_clAdd6'
+     */
+    public function edit()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'sys_id','sczl_rq', 'sczl_bh', 'sczl_jsss', 'sczl_冲定额', 'sczl_bzdh',
+            'sczl_gdbh1', 'sczl_gdbh2', 'sczl_gdbh3', 'sczl_gdbh4', 'sczl_gdbh5', 'sczl_gdbh6',
+            'sczl_yjGx1', 'sczl_yjGx2', 'sczl_yjGx3', 'sczl_yjGx4', 'sczl_yjGx5', 'sczl_yjGx6',
+            'sczl_gxmc1', 'sczl_gxmc2', 'sczl_gxmc3', 'sczl_gxmc4', 'sczl_gxmc5', 'sczl_gxmc6',
+            'sczl_cl1', 'sczl_cl2', 'sczl_cl3', 'sczl_cl4', 'sczl_cl5', 'sczl_cl6',
+            'sczl_PgCl1', 'sczl_PgCl2', 'sczl_PgCl3', 'sczl_PgCl4', 'sczl_PgCl5', 'sczl_PgCl6',
+            'sczl_返工产量1', 'sczl_返工产量2', 'sczl_返工产量3', 'sczl_返工产量4', 'sczl_返工产量5', 'sczl_返工产量6',
+            'sczl_计产系数1', 'sczl_计产系数2', 'sczl_计产系数3', 'sczl_计产系数4', 'sczl_计产系数5', 'sczl_计产系数6',
+            'sczl_Jtbh1','sczl_Jtbh2', 'sczl_Jtbh3', 'sczl_Jtbh4', 'sczl_Jtbh5', 'sczl_Jtbh6',
+            'sczl_dedh1', 'sczl_dedh2', 'sczl_dedh3', 'sczl_dedh4', 'sczl_dedh5', 'sczl_dedh6',
+            'sczl_desc'
+        ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                continue;
+            }
+            $data[$value] = $req[$value];
+        }
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+        if (count($data)==0){
+            $this->error('参数错误','',111);
+        }
+        $data['mod_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+    }
+
+    /**
+     * 修改
+     * @ApiMethod (POST)
+     * @param string 'UniqId'
+     */
+    public function del()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $bool = db()->table('成品入仓')->where('UniqId',$req['UniqId'])->delete();
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+
+    }
+
+    /**
+     * 导出到excel
+     * @ApiMethod (POST)
+     * @param string gxmc
+     * @param string start_time
+     * @param string end_time
+     * @param string file_name
+     * @param array fields
+     */
+    public function processExport(){
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'gxmc','start_time', 'end_time', 'file_name'
+        ];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                $this->error('参数错误',$value,$key+1);
+            }
+        }
+        if (!(isset($req['fields']) && count($req['fields'])!=0)){
+            $this->error('参数错误','fields',100);
+        }
+        $field = '';
+        $arr = [
+            'sczl_rq'       =>['日期','LEFT(sczl_rq, 10) as sczl_rq'],
+            'sczl_bh'       =>['员工编号','sczl_bh'],
+            'sczl_name'     =>['员工姓名','sczl_bh'],
+            'sczl_jsss'     =>['计时时数','sczl_jsss'],
+            'sczl_gdbh'     =>['工单编号','sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6'],
+            'sczl_yjmc'     =>['印件名称','sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6'],
+            'sczl_yjGx'     =>['印件工序','rtrim(sczl_yjGx1) as sczl_yjGx1, rtrim(sczl_yjGx2) as sczl_yjGx2, rtrim(sczl_yjGx3) as sczl_yjGx3, rtrim(sczl_yjGx4) as sczl_yjGx4, rtrim(sczl_yjGx5) as sczl_yjGx5, rtrim(sczl_yjGx6) as sczl_yjGx6'],
+            'sczl_gxmc'     =>['工序名称','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'],
+            'sczl_cl'       =>['产量','sczl_cl1, sczl_cl2, sczl_cl3, sczl_cl4, sczl_cl5, sczl_cl6'],
+            'sczl_PgCl'     =>['每箱产量','sczl_PgCl1, sczl_PgCl2, sczl_PgCl3, sczl_PgCl4, sczl_PgCl5, sczl_PgCl6'],
+            'sczl_计产系数'  =>['计产系数','sczl_计产系数1, sczl_计产系数2, sczl_计产系数3, sczl_计产系数4, sczl_计产系数5, sczl_计产系数6'],
+            'sczl_dedh'     =>['定额代号','rtrim(sczl_dedh1) as sczl_dedh1, rtrim(sczl_dedh2) as sczl_dedh2, rtrim(sczl_dedh3) as sczl_dedh3, rtrim(sczl_dedh4) as sczl_dedh4, rtrim(sczl_dedh5) as sczl_dedh5, rtrim(sczl_dedh6) as sczl_dedh6']
+        ];
+        $data[0] = [];
+        foreach ($req['fields'] as $k=>$v){
+            if(array_key_exists($v,$arr)){
+                if ($k==0){
+                    $field .= $arr[$v][1];
+                }else{
+                    $field .= ','.$arr[$v][1];
+                }
+                array_push($data[0],$arr[$v][0]);
+            }
+        }
+
+        //根据条件查询数据
+        $rows = db()->table('成品入仓')
+            ->field($field)
+            ->where('sczl_rq','between',[$req['start_time'],$req['end_time']])
+            ->where(['sczl_gxmc1|sczl_gxmc2|sczl_gxmc3|sczl_gxmc4|sczl_gxmc5|sczl_gxmc6'=>['like','%'.$req['gxmc'].'%']])
+            ->select();
+        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+
+        for ($i = 1; $i <= 6; $i++) {
+            foreach ($rows as $key=>$value){
+                if (trim($value['sczl_gdbh'.$i])=='') continue;
+                if (trim($value['sczl_gxmc'.$i])!=$req['gxmc']) continue;
+                $subArray = [];
+                foreach ($req['fields'] as $k=>$v){
+                    if(array_key_exists($v,$arr)){
+                        if($v=='sczl_rq' || $v=='sczl_jsss' || $v=='sczl_bh'){
+                            if($value[$v]){
+                                array_push($subArray,$value[$v]);
+                            }else{
+                                array_push($subArray,'');
+                            }
+                        }else if($v=='sczl_name'){
+                            $name = array_key_exists($value['sczl_bh'],$rs) ? trim($rs[$value['sczl_bh']]) : '';
+                            if($name){
+                                array_push($subArray,$name);
+                            }else{
+                                array_push($subArray,'');
+                            }
+                        }else if($v=='sczl_yjmc'){
+                            $cpmc = array_key_exists($value['sczl_gdbh'.$i],$gd) ? trim($gd[$value['sczl_gdbh'.$i]]) : '';
+                            if($cpmc){
+                                array_push($subArray,$cpmc);
+                            }else{
+                                array_push($subArray,'');
+                            }
+                        }else{
+                            if($value[$v.$i]){
+                                array_push($subArray,$value[$v.$i]);
+                            }else{
+                                array_push($subArray,'');
+                            }
+                        }
+                    }
+                }
+                array_push($data,$subArray);
+            }
+        }
+
+        $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
+    }
+
+    /**
+     * 工序汇总导出
+     * @ApiMethod (POST)
+     * @param string date
+     * @param string sys_id
+     * @param array fields
+     */
+    public function export(){
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        $where = [];
+        if (isset($req['date']) && !empty($req['date'])){
+            $where['sys_rq'] = ['LIKE',$req['date'].'%'];
+        }else{
+            $this->error('参数错误');
+        }
+        if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
+        if (!(isset($req['fields']) && count($req['fields'])!=0)){
+            $this->error('参数错误','fields',100);
+        }
+
+        $field = '';
+        $arr = [
+            'sczl_bh'       =>['员工编号','sczl_bh'],
+            'sczl_name'     =>['员工姓名','sczl_bh'],
+            'sczl_rq'       =>['生产日期','LEFT(sczl_rq, 10) as sczl_rq'],
+            'sczl_bzdh'     =>['班组','sczl_bzdh'],
+            'sczl_cl'       =>['包装产量','sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl'],
+            'sczl_fgcl'     =>['返工产量','sczl_返工产量1 + sczl_返工产量2 + sczl_返工产量3 + sczl_返工产量4 + sczl_返工产量5 + sczl_返工产量6 as sczl_fgcl'],
+            'sczl_jjcl'     =>['计件产量','sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 + sczl_返工产量1 + sczl_返工产量2 + sczl_返工产量3 + sczl_返工产量4 + sczl_返工产量5 + sczl_返工产量6 as sczl_jjcl'],
+            'sczl_gdbh1'     =>['相关工单','sczl_gdbh1'],
+        ];
+        $data[0] = [];
+        foreach ($req['fields'] as $k=>$v){
+            if(array_key_exists($v,$arr)){
+                if ($k==0){
+                    $field .= $arr[$v][1];
+                }else{
+                    $field .= ','.$arr[$v][1];
+                }
+                array_push($data[0],$arr[$v][0]);
+            }
+        }
+
+        $rows = db()->table('成品入仓')
+            ->field($field)
+            ->where($where)
+            ->select();
+
+        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        foreach ($rows as $key=>$value) {
+            if (isset($value['sczl_cl'])) $value['sczl_cl'] = floatval($value['sczl_cl']);
+            if (isset($value['sczl_fgcl'])) $value['sczl_fgcl'] = floatval($value['sczl_fgcl']);
+            if (isset($value['sczl_jjcl'])) $value['sczl_jjcl'] = floatval($value['sczl_jjcl']);
+            $subArray = [];
+            foreach ($req['fields'] as $k=>$v){
+                if(array_key_exists($v,$arr)){
+                    if($v=='sczl_name'){
+                        $name = array_key_exists($value['sczl_bh'],$rs) ? trim($rs[$value['sczl_bh']]) : '';
+                        if($name){
+                            array_push($subArray,$name);
+                        }else{
+                            array_push($subArray,'');
+                        }
+                    }else{
+                        if($value[$v]){
+                            array_push($subArray,$value[$v]);
+                        }else{
+                            array_push($subArray,'');
+                        }
+                    }
+                }
+            }
+            array_push($data,$subArray);
+        }
+        $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
+    }
+}

+ 440 - 38
application/api/controller/MachineProductionReport.php

@@ -198,6 +198,8 @@ class MachineProductionReport extends Api
         }
         $req = $this->request->param();
 
+        if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
+
         $page = 1;
         $limit = 15;
         if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
@@ -225,14 +227,13 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
             ->where($where)
             ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-            ->order('sys_id asc, sczl_num asc')
+            ->order('a.sys_id asc, a.sczl_num asc')
             ->page($page,$limit)
             ->select();
 
         $total1 = db()->table('设备_产量计酬')->where($option)->count();
 
         //来料异常
-        //制程废 次品
         $rows2 = db()->table('db_sczl')->alias('a')
             ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_fp as sczl_zcfp, a.sczl_cp as sczl_zccp, 
@@ -242,7 +243,7 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
             ->where($where)
             ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-            ->order('sys_id asc, sczl_num asc')
+            ->order('a.sys_id asc, a.sczl_num asc')
             ->page($page,$limit)
             ->select();
         $total2 = db()->table('db_sczl')->where($option)->count();
@@ -359,7 +360,7 @@ class MachineProductionReport extends Api
                 'sczl_gdbh'=>[ 'like', '%' . $req['gdbh'] . '%']
             ];
 
-            //拆片联拼系数 拆片条小盒系数 日定额 千件工价 补产标准
+            //拆片联拼系数 拆片条小盒系数
             $rows1 = db()->table('设备_产量计酬')->alias('a')
                 ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数, 
@@ -369,14 +370,13 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
                 ->where($where)
                 ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-                ->order('sczl_yjno asc, sczl_gxh asc, sczl_type asc, sczl_rq asc')
+                ->order('a.sczl_yjno asc, a.sczl_gxh asc, a.sczl_type asc, a.sczl_rq asc')
                 ->page($page,$limit)
                 ->select();
 
             $total1 = db()->table('设备_产量计酬')->where($option)->count();
 
-            //来料异常 日定额 千件工价 补产标准
-            //制程废 次品
+            //来料异常
             $rows2 = db()->table('db_sczl')->alias('a')
                 ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_fp as sczl_zcfp, a.sczl_cp as sczl_zccp, 
@@ -386,7 +386,7 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
                 ->where($where)
                 ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-                ->order('sczl_yjno asc, sczl_gxh asc, sczl_type asc, sczl_rq asc')
+                ->order('a.sczl_yjno asc, a.sczl_gxh asc, a.sczl_type asc, a.sczl_rq asc')
                 ->page($page,$limit)
                 ->select();
             $total2 = db()->table('db_sczl')->where($option)->count();
@@ -403,7 +403,7 @@ class MachineProductionReport extends Api
                     'sczl_gdbh'=>['in', $gd]
                 ];
 
-                //拆片联拼系数 拆片条小盒系数 日定额 千件工价 补产标准
+                //拆片联拼系数 拆片条小盒系数
                 $rows1 = db()->table('设备_产量计酬')->alias('a')
                     ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数, 
@@ -413,14 +413,13 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
                     ->where($where)
                     ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-                    ->order('sczl_yjno asc, sczl_gxh asc, sczl_type asc, sczl_rq asc')
+                    ->order('a.sczl_yjno asc, a.sczl_gxh asc, a.sczl_type asc, a.sczl_rq asc')
                     ->page($page,$limit)
                     ->select();
 
                 $total1 = db()->table('设备_产量计酬')->where($option)->count();
 
-                //来料异常 日定额 千件工价 补产标准
-                //制程废 次品
+                //来料异常
                 $rows2 = db()->table('db_sczl')->alias('a')
                     ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
             a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_fp as sczl_zcfp, a.sczl_cp as sczl_zccp, 
@@ -430,7 +429,7 @@ class MachineProductionReport extends Api
             rtrim(a.sys_id) as sys_id, a.sys_rq, a.mod_rq, a.UniqId')
                     ->where($where)
                     ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
-                    ->order('sczl_yjno asc, sczl_gxh asc, sczl_type asc, sczl_rq asc')
+                    ->order('a.sczl_yjno asc, a.sczl_gxh asc, a.sczl_type asc, a.sczl_rq asc')
                     ->page($page,$limit)
                     ->select();
                 $total2 = db()->table('db_sczl')->where($option)->count();
@@ -556,7 +555,7 @@ class MachineProductionReport extends Api
             a.sczl_rate6, a.sczl_rate7, a.sczl_rate8, a.sczl_rate9, a.sczl_rate10
             ')
             ->where('a.UniqId', $UniqId)
-            ->where('a.sczl_yjno = y.yj_yjno')
+            ->where('a.sczl_yjno = y.yj_Yjno')
             ->join(['工单_基本资料'=>'j'],'a.sczl_gdbh = j.Gd_gdbh')
             ->join(['工单_印件资料'=>'y'],'a.sczl_gdbh = y.Yj_Gdbh')
             ->find();
@@ -573,45 +572,448 @@ class MachineProductionReport extends Api
     }
 
     /**
-     * 获取机台生产日报表信息
+     * 获取工单名称
      * @ApiMethod (GET)
-     * @param string $UniqId UniqId
+     * @param string $gdbh 工单编号
      */
-    public function add()
+    public function getGdmc()
     {
         //get请求
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
         $req = $this->request->param();
-        if (isset($req['UniqId']) && !empty($req['UniqId'])){
-            $UniqId = $req['UniqId'];
+
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $gdbh = $req['gdbh'];
         }else{
             $this->error('参数错误');
         }
 
-        $rows = db()->table('db_sczl')->alias('a')
-            ->field('a.sczl_gdbh, rtrim(j.Gd_cpmc) as Gd_cpmc, 
-            a.sczl_yjno, rtrim(y.yj_yjmc) as yj_yjmc, 
-            rtrim(a.sczl_gxmc) as sczl_gxmc, a.sczl_gxh, rtrim(a.sczl_type) as sczl_type, 
-            LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, a.sczl_bzdh, 
-            a.sczl_ms, a.sczl_ls, a.sczl_cl, a.sczl_fp as sczl_zcfp, 
-            a.sczl_装版总工时, a.sczl_装版工时, a.sczl_保养工时, a.sczl_异常停机工时, 
-            a.sczl_打样总工时, a.sczl_打样工时, a.sczl_设备运行工时, 
-            a.拆片联拼系数, a.拆片条小盒系数, 
-            a.sczl_dedh, a.sczl_工价系数, a.sczl_计产系数, 
-            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, 
-            d.日定额, d.千件工价, d.补产标准
-            ')
-            ->where('a.UniqId', $UniqId)
-            ->where('a.sczl_yjno = y.yj_yjno')
-            ->join(['dic_lzde'=>'d'],'a.sczl_dedh = d.sys_bh')
-            ->join(['工单_基本资料'=>'j'],'a.sczl_gdbh = j.Gd_gdbh')
-            ->join(['工单_印件资料'=>'y'],'a.sczl_gdbh = y.Yj_Gdbh')
+        $row = db('工单_基本资料')
+            ->field('rtrim(Gd_cpmc) as Gd_cpmc')
+            ->where('Gd_gdbh',$gdbh)
             ->find();
 
+        if (!$row) $this->error('失败');
+        $this->success('成功',$row);
+    }
 
+    /**
+     * 获取印件名称
+     * @ApiMethod (GET)
+     * @param string $gdbh 工单编号
+     * @param string $yjno 印件号
+     */
+    public function getYjmc()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $gdbh = $req['gdbh'];
+        }else{
+            $this->error('参数错误');
+        }
+        if (isset($req['yjno']) && !empty($req['yjno'])){
+            $yjno = $req['yjno'];
+        }else{
+            $this->error('参数错误');
+        }
+
+        $row = db('工单_印件资料')
+            ->field('rtrim(yj_yjmc) as yj_yjmc')
+            ->where(['Yj_Gdbh'=>$gdbh,'yj_Yjno'=>$yjno])
+            ->find();
+
+        if (!$row) $this->error('失败');
+        $this->success('成功',$row);
+    }
+
+    /**
+     * 获取工序
+     * @ApiMethod (GET)
+     * @param string $gdbh 工单编号
+     * @param string $yjno 印件号
+     * @param string $keyword 关键词
+     */
+    public function getGx()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $gdbh = $req['gdbh'];
+        }else{
+            $this->error('参数错误');
+        }
+        if (isset($req['yjno']) && !empty($req['yjno'])){
+            $yjno = $req['yjno'];
+        }else{
+            $this->error('参数错误');
+        }
+        if (isset($req['keyword']) && !empty($req['keyword'])){
+            $keyword = $req['keyword'];
+        }else{
+            $keyword = '';
+        }
+
+        $rows = 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')
+            ->where(['Gy0_gdbh'=>$gdbh,'Gy0_yjno'=>$yjno])
+            ->where('Gy0_gxh|Gy0_gxmc|Add_gxmc','like','%'.$keyword.'%')
+            ->select();
+        foreach ($rows as $key=>$value) {
+            if($value['Add_gxmc'] != ''){
+                $rows[$key]['sczl_gxmc'] = sprintf("%02d", $value['sczl_gxh']).'-'.$value['Add_gxmc'];
+            }else{
+                $rows[$key]['sczl_gxmc'] = sprintf("%02d", $value['sczl_gxh']).'-'.$value['sczl_type'];
+            }
+            unset($rows[$key]['Add_gxmc']);
+        }
+        if (!$rows) $this->error('失败');
         $this->success('成功',$rows);
     }
+
+    /**
+     * 查询定额代号
+     * @ApiMethod (GET)
+     */
+    public function getDedh()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+
+        $row = db()->table('dic_lzde')
+            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
+            ->where('sys_mc','人工作业计件定额')
+            ->find();
+        $rows = db()->table('dic_lzde')
+            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
+            ->where('Parent',$row['Key_'])
+            ->order('sys_bh asc')
+            ->select();
+        foreach ($rows as $key=>$value){
+            $bool = db()->table('dic_lzde')
+                ->field('sys_bh, rtrim(sys_mc) as sys_mc')
+                ->where('Parent',$value['Key_'])
+                ->order('sys_bh asc')
+                ->select();
+            if ($bool){
+                $rows[$key]['bh_mc'] = $bool;
+            }
+        }
+        $row['bh_mc'] = $rows;
+
+        $this->success('成功',$row);
+    }
+
+    /**
+     * 新增
+     * @ApiMethod (POST)
+     * @param string
+     */
+    public function add()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'sys_id','sczl_gdbh','sczl_yjno',
+            'sczl_gxmc','sczl_gxh','sczl_type',
+            'sczl_rq','sczl_jtbh','sczl_bzdh',
+            'sczl_ms','sczl_ls','sczl_cl','sczl_fp',
+            'sczl_装版总工时','sczl_装版工时','sczl_保养工时','sczl_异常停机工时',
+            'sczl_打样总工时','sczl_打样工时','sczl_设备运行工时',
+            '拆片联拼系数','拆片条小盒系数','sczl_dedh','sczl_工价系数','sczl_计产系数',
+            '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'
+        ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!(isset($req[$value]))){
+                $this->error('参数错误',$value,$key+1);
+            }
+            $data[$value] = $req[$value];
+        }
+        $data['sys_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('db_sczl')->fetchSql(true)->insert($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+    }
+
+    /**
+     * 新增
+     * @ApiMethod (POST)
+     * @param string
+     */
+    public function edit()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'UniqId','sczl_gdbh','sczl_yjno',
+            'sczl_gxmc','sczl_gxh','sczl_type',
+            'sczl_rq','sczl_jtbh','sczl_bzdh',
+            'sczl_ms','sczl_ls','sczl_cl','sczl_fp',
+            'sczl_装版总工时','sczl_装版工时','sczl_保养工时','sczl_异常停机工时',
+            'sczl_打样总工时','sczl_打样工时','sczl_设备运行工时',
+            '拆片联拼系数','拆片条小盒系数','sczl_dedh','sczl_工价系数','sczl_计产系数',
+            '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'
+        ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!(isset($req[$value]))){
+                continue;
+            }
+            $data[$value] = $req[$value];
+        }
+        $data['mod_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('db_sczl')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+    }
+
+    /**
+     * 修改
+     * @ApiMethod (POST)
+     * @param string 'UniqId'
+     */
+    public function del()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $bool = db()->table('db_sczl')->where('UniqId',$req['UniqId'])->delete();
+
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+
+    }
+
+    /**
+     * 工序汇总导出
+     * @ApiMethod (GET)
+     * @param string date
+     * @param string sys_id
+     * @param array fields
+     */
+    public function export(){
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        $where = [];
+        if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
+
+        if (!(isset($req['fields']) && count($req['fields'])!=0)){
+            $this->error('参数错误','fields',100);
+        }
+        if(strpos($req['date'],'-')){
+            $where = ['a.sys_rq'=>['like','%'.$req['date'].'%']];
+        }else{
+            $where = ['a.sczl_gdbh'=>$req['date']];
+        }
+        if (isset($req['sys_id']) && !empty($req['sys_id'])){
+            $where['a.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
+        }
+
+        $arr = [
+            'sczl_gdbh'         =>['工单编号'],
+            'Gd_cpmc'           =>['产品名称'],
+            'jyno_gxmc'         =>['印件及工序'],
+            'sczl_rq'           =>['生产日期'],
+            'sczl_jtbh'         =>['机台'],
+            'sczl_bzdh'         =>['班组'],
+            'sczl_num'          =>['流程单'],
+            'sczl_cl'           =>['车头产量'],
+            'sczl_ms'           =>['色度数'],
+            'sczl_zcfp'         =>['制程废'],
+            'sczl_zccp'         =>['次品'],
+            'sczl_来料异常'      =>['来料异常'],
+            'sczl_装版工时'      =>['装版工时'],
+            'sczl_保养工时'      =>['保养工时'],
+            'sczl_打样工时'      =>['打样工时'],
+            'sczl_异常停机工时'   =>['异常停机工时'],
+            'sczl_设备运行工时'   =>['设备运行工时'],
+            'sczl_bh1'          =>['组员编号1'],
+            'sczl_bh1_name'     =>['组员姓名1'],
+            'sczl_bh2'          =>['组员编号2'],
+            'sczl_bh2_name'     =>['组员姓名2'],
+            'sczl_bh3'          =>['组员编号3'],
+            'sczl_bh3_name'     =>['组员姓名3'],
+            'sczl_bh4'          =>['组员编号4'],
+            'sczl_bh4_name'     =>['组员姓名4'],
+            'sczl_bh5'          =>['组员编号5'],
+            'sczl_bh5_name'     =>['组员姓名5'],
+            'sczl_bh6'          =>['组员编号6'],
+            'sczl_bh6_name'     =>['组员姓名6'],
+            '拆片联拼系数'        =>['拆片联拼系数'],
+            '拆片条小盒系数'      =>['拆片条小盒系数'],
+            'sczl_工价系数'      =>['工价系数'],
+            '日定额'             =>['日定额'],
+            '千件工价'           =>['千件工价'],
+            '补产标准'           =>['补产标准'],
+        ];
+        $data[0] = [];
+        foreach ($req['fields'] as $k=>$v){
+            if(array_key_exists($v,$arr)){
+                array_push($data[0],$arr[$v][0]);
+            }
+        }
+
+        //拆片联拼系数 拆片条小盒系数
+        $rows1 = db()->table('设备_产量计酬')->alias('a')
+            ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
+            a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_zcfp, a.sczl_zccp, a.sczl_来料少数 as sczl_来料异常, 
+            a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
+            a.sczl_bh1, a.sczl_bh2, a.sczl_bh3, a.sczl_bh4, a.sczl_bh5, a.sczl_bh6, 
+            a.sczl_工价系数, d.日定额, d.千件工价, d.补产标准 
+            ')
+            ->where($where)
+            ->join(['dic_lzde'=>'d'],'a.sczl_dedh = d.sys_bh')
+            ->order('a.sys_id asc, a.sczl_num asc')
+            ->select();
+
+        $rows2 = db()->table('db_sczl')->alias('a')
+            ->field('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_type, LEFT(a.sczl_rq, 10) as sczl_rq, a.sczl_jtbh, 
+            a.sczl_bzdh, a.sczl_num, a.sczl_cl, a.sczl_ms, a.sczl_fp as sczl_zcfp, a.sczl_cp as sczl_zccp, 
+            a.sczl_装版工时, a.sczl_保养工时, a.sczl_打样工时, a.sczl_异常停机工时, a.sczl_设备运行工时, 
+            a.sczl_bh1, a.sczl_bh2, a.sczl_bh3, a.sczl_bh4, a.sczl_bh5, a.sczl_bh6, 
+            a.拆片联拼系数, a.拆片条小盒系数, a.sczl_工价系数, d.日定额, d.千件工价, d.补产标准
+            ')
+            ->where($where)
+            ->join(['dic_lzde'=>'d'],'a.sczl_dedh=d.sys_bh')
+            ->order('a.sys_id asc, a.sczl_num asc')
+            ->select();
+
+        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
+        foreach ($rows2 as $key=>$value){
+            $subArray = [];
+            foreach ($arr as $k=>$v){
+                if($k=='sczl_来料异常'){
+                    $subArray[$k] = '';
+                }else if($k=='Gd_cpmc'){
+                    if(trim($value['sczl_gdbh']) != '' && array_key_exists($value['sczl_gdbh'],$gd)){
+                        $subArray[$k] = trim($gd[$value['sczl_gdbh']]);
+                    }else{
+                        $subArray[$k] = '';
+                    }
+                }else if($k=='sczl_bh1_name' || $k=='sczl_bh2_name' || $k=='sczl_bh3_name' || $k=='sczl_bh4_name' || $k=='sczl_bh5_name' || $k=='sczl_bh6_name'){
+                    if(trim($value[substr($k,0,8)]) != '' && array_key_exists($value[substr($k,0,8)],$rs)){
+                        $subArray[$k] = trim($rs[$value[substr($k,0,8)]]);
+                    }else{
+                        $subArray[$k] = '';
+                    }
+                }else if($k=='sczl_num' || $k=='sczl_cl' || $k=='sczl_zcfp' || $k=='sczl_zccp' || $k=='sczl_装版工时' || $k=='sczl_保养工时' || $k=='sczl_打样工时' ||
+                    $k=='sczl_异常停机工时' || $k=='sczl_设备运行工时' || $k=='拆片联拼系数' || $k=='拆片条小盒系数' || $k=='sczl_工价系数' || $k=='千件工价'){
+                    $subArray[$k] = $value[$k] == 0 ? '' : floatval($value[$k]);
+                }else if($k=='sczl_ms'){
+                    $subArray[$k] = $value[$k] == 0 ? 1 : floatval($value[$k]);
+                }else if($k=='jyno_gxmc'){
+                    $subArray['jyno_gxmc'] = sprintf("%02d", $value['sczl_yjno']).'-'.sprintf("%02d", $value['sczl_gxh']).'-->'.trim($value['sczl_type']);
+                }else{
+                    $subArray[$k] = $rows2[$key][$k];
+                }
+            }
+            array_push($data,$subArray);
+        }
+        foreach ($rows1 as $key=>$value){
+            $subArray = [];
+            foreach ($arr as $k=>$v){
+                if($k=='拆片联拼系数' || $k=='拆片条小盒系数'){
+                    $subArray[$k] = '';
+                }else if($k=='Gd_cpmc'){
+                    if(trim($value['sczl_gdbh']) != '' && array_key_exists($value['sczl_gdbh'],$gd)){
+                        $subArray[$k] = trim($gd[$value['sczl_gdbh']]);
+                    }else{
+                        $subArray[$k] = '';
+                    }
+                }else if($k=='sczl_bh1_name' || $k=='sczl_bh2_name' || $k=='sczl_bh3_name' || $k=='sczl_bh4_name' || $k=='sczl_bh5_name' || $k=='sczl_bh6_name'){
+                    if(trim($value[substr($k,0,8)]) != '' && array_key_exists($value[substr($k,0,8)],$rs)){
+                        $subArray[$k] = trim($rs[$value[substr($k,0,8)]]);
+                    }else{
+                        $subArray[$k] = '';
+                    }
+                }else if($k=='sczl_num' || $k=='sczl_cl' || $k=='sczl_zcfp' || $k=='sczl_zccp' || $k=='sczl_来料异常' || $k=='sczl_装版工时' ||
+                    $k=='sczl_保养工时' || $k=='sczl_打样工时' || $k=='sczl_异常停机工时' || $k=='sczl_设备运行工时' || $k=='sczl_工价系数' || $k=='千件工价'){
+                    $subArray[$k] = $value[$k] == 0 ? '' : floatval($value[$k]);
+                }else if($k=='sczl_ms'){
+                    $subArray[$k] = $value[$k] == 0 ? 1 : floatval($value[$k]);
+                }else if($k=='jyno_gxmc'){
+                    $subArray['jyno_gxmc'] = sprintf("%02d", $value['sczl_yjno']).'-'.sprintf("%02d", $value['sczl_gxh']).'-->'.trim($value['sczl_type']);
+                }else{
+                    $subArray[$k] = $rows1[$key][$k];
+                }
+            }
+            array_push($data,$subArray);
+        }
+
+        $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
+    }
+
 }