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]); } }