request->isGet() === false){ $this->error('请求错误'); } $mouth = \db('设备_产量计酬') ->distinct(true) ->field('DATE_FORMAT(sczl_rq, "%Y-%m") AS month') ->order('month desc') ->select(); $sist = \db('设备_基本资料') ->whereNotNull('设备编组') ->group('设备编组') ->column('rtrim(设备编组) as 设备编组'); $data = []; foreach ($mouth as $key=>$value) { $arr = [ 'date'=>date('Ym',strtotime($value['month'])), 'sbbh'=>$sist, ]; array_push($data,$arr); } $this->success('成功',$data); } /** * 月度产量统计上方机台生产数据 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function MachineProduction() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['mouth'])){ $this->error('参数错误'); } $where = []; if(!empty($param['sist'])){ $where['设备编组'] = $param['sist']; } //将参数装换成标准日期格式 $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m'); $machine = \db('设备_基本资料') ->where($where) ->field('设备编号') ->select(); $day = \db('设备_产量计酬') ->distinct(true) ->field('DATE_FORMAT(sczl_rq,"%Y-%m-%d") as day') ->whereRaw("DATE_FORMAT(sczl_rq, '%Y-%m') = '$mouth'") // ->whereTime('sczl_rq',$mouth) // ->group('day') ->order('day') ->select(); $day = array_reduce($day, function($carry, $item) { return array_merge($carry, array_values($item)); }, []); $data = []; $data['head'] = $day; foreach ($machine as $key=>$value){ $data['total'][$key] = \db('设备_产量计酬') ->field('sczl_jtbh,sczl_bzdh,SUM(sczl_cl) as total_cl') ->whereTime('sczl_rq',$mouth) ->where('sczl_jtbh',$value['设备编号']) ->group('sczl_jtbh,sczl_bzdh') ->order('sczl_jtbh') ->select(); foreach ($data['total'][$key] as $k=>$v){ $day_total = db('设备_产量计酬') ->field('DATE(sczl_rq) as day, SUM(sczl_cl) as total_cl') ->whereTime('sczl_rq', $mouth) ->where('sczl_jtbh', $value['设备编号']) ->where('sczl_bzdh', $v['sczl_bzdh']) ->group('sczl_bzdh,day') ->select(); $day_total = array_column($day_total, 'total_cl', 'day'); $data['total'][$key][$k]['day_total'] = $day_total; } } $this->success('成功',$data); } /** * 机台班次生产工单明细 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function MachineProductDetail() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['mouth']) || empty($param['machine']) || empty($param['team'])){ $this->error('参数错误'); } //将参数装换成标准日期格式 $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m'); $team = substr($param['team'],0,1); $list = \db('设备_产量计酬') ->alias('a') ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno') ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh') ->field([ 'a.sczl_gdbh' => '工单编号', 'a.sczl_yjno' => '印件号', 'a.sczl_gxh' => '工序号', 'c.yj_yjmc' => '印件名称', 'd.Gy0_gxmc' => '工序名称', 'DATE(a.sczl_rq)' => '工作日期', 'a.sczl_jtbh' => '机台编号', 'a.sczl_bzdh' => '班组编号', 'SUM(a.sczl_cl)' => '产量', 'a.sczl_ms' => '墨色数' ]) ->whereTime('a.sczl_rq',$mouth) ->where('a.sczl_jtbh',$param['machine']) ->where('a.sczl_bzdh','like',$team.'%') ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh') ->order('工作日期') ->select(); if (!empty($list)){ foreach ($list as $key=>$value){ $list[$key]['印件名称'] = $value['印件号'].'-'.$value['印件名称']; $list[$key]['工序名称'] = $value['工序号'].'-'.$value['工序名称']; unset($list[$key]['印件号'],$list[$key]['工序号']); } } $this->success('成功',$list); } /** * 月度机台运行工时汇总 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function MachineOperation() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['mouth'])){ $this->error('参数错误'); } $where = []; if(!empty($param['sist'])){ $where['设备编组'] = $param['sist']; } //将参数装换成标准日期格式 $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m'); $list = \db('设备_基本资料') ->alias('a') ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh') ->field([ 'a.设备编号' => '设备编号', 'rtrim(a.设备名称)' => '设备名称', 'SUM(b.sczl_cl)' => '产量', 'SUM(b.sczl_设备运行工时)' => '设备运行工时', 'SUM(b.sczl_保养工时)' => '保养工时', 'SUM(b.sczl_打样总工时)' => '打样总工时', 'SUM(b.sczl_打样工时)' => '打样补产工时', 'SUM(b.sczl_装版总工时)' => '装板总工时', 'SUM(b.sczl_装版工时)' => '装板补产工时', 'SUM(b.sczl_异常停机工时)' => '异常停机工时' ]) ->where($where) ->whereTime('b.sczl_rq',$mouth) ->group('a.设备编号') ->order('a.设备编号') ->select(); $total = \db('设备_基本资料') ->alias('a') ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh') ->field([ 'SUM(b.sczl_设备运行工时)' => '设备运行工时', 'SUM(b.sczl_保养工时)' => '保养工时', 'SUM(b.sczl_打样总工时)' => '打样总工时', 'SUM(b.sczl_打样工时)' => '打样补产工时', 'SUM(b.sczl_装版总工时)' => '装板总工时', 'SUM(b.sczl_装版工时)' => '装板补产工时', 'SUM(b.sczl_异常停机工时)' => '异常停机工时' ]) ->where($where) ->whereTime('b.sczl_rq',$mouth) ->find(); $list['total'] = $total; $this->success('成功',$list); } /** * 设备运行工时机台生产工单数据详情 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function MachineOperationProductDetail() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['mouth']) || empty($param['machine'])){ $this->error('参数错误'); } //将参数装换成标准日期格式 $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m'); $list = \db('设备_产量计酬') ->alias('a') ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号') ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno') ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh') ->field([ 'a.sczl_jtbh' => '设备编号', 'rtrim(b.设备名称)' => '设备名称', 'DATE(a.sczl_rq)' => '日期', 'a.sczl_gdbh' => '工单编号', 'a.sczl_yjno' => '印件号', 'a.sczl_gxh' => '工序号', 'c.yj_yjmc' => '印件名称', 'd.Gy0_gxmc' => '工序名称', 'SUM(a.sczl_cl)' => '产量', 'SUM(a.sczl_设备运行工时)' => '设备运行工时', 'SUM(a.sczl_保养工时)' => '保养工时', 'SUM(a.sczl_打样总工时)' => '打样总工时', 'SUM(a.sczl_打样工时)' => '打样补产工时', 'SUM(a.sczl_装版总工时)' => '装板总工时', 'SUM(a.sczl_装版工时)' => '装板补产工时', 'SUM(a.sczl_异常停机工时)' => '异常停机工时', 'a.sczl_ms' => '墨色数' ]) ->whereTime('a.sczl_rq',$mouth) ->where('a.sczl_jtbh',$param['machine']) ->group('a.sczl_rq,a.sczl_gdbh') ->order('a.sczl_rq') ->select(); if (!empty($list)){ foreach ($list as $key=>$value){ $list[$key]['工序名称'] = $value['印件号'].'-'.$value['工序号'].'-'.$value['工序名称']; unset($list[$key]['印件号'],$list[$key]['工序号']); } } $this->success('成功',$list); } }