Эх сурвалжийг харах

决策支持月度产量统计页面数据

qiuenguang 1 жил өмнө
parent
commit
6913c7713e

+ 151 - 0
application/api/controller/Decision.php

@@ -1 +1,152 @@
 <?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('设备_基本资料')
+            ->field('rtrim(设备编组) as 设备编组')
+            ->whereNotNull('设备编组')
+            ->group('设备编组')
+            ->select();
+        $data = [];
+        foreach ($mouth as $key=>$value) {
+            $time = date('Ym',strtotime($value['month']));
+            $data[$time] = $sist;
+        }
+        $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']) || empty($param['sist'])){
+            $this->error('参数错误');
+        }
+        $mouth = date('Y-m',strtotime($param['mouth']));
+        $machine = \db('设备_基本资料')
+            ->where('设备编组',$param['sist'])
+            ->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);
+    }
+}