| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Request;
- /**
- * 设备运行跟踪
- */
- class Decision extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- //月度产量统计菜单
- public function OutputSstatisticsMenu()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $mouth = \db('设备_产量计酬')
- ->whereTime('sczl_rq', 'month')
- ->field('DATE_FORMAT(sczl_rq, "%Y-%m") AS month')
- ->group('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('Y-m',strtotime($param['mouth']));
- $machine = \db('设备_基本资料')
- ->where($where)
- ->field('设备编号')
- ->select();
- $day = \db('设备_产量计酬')
- ->field('DATE(sczl_rq) as day')
- ->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('Y-m',strtotime($param['mouth']));
- $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('Y-m',strtotime($param['mouth']));
- $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('Y-m',strtotime($param['mouth']));
- $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);
- }
- }
|