<?php

namespace app\index\controller;

use think\Controller;
use think\Db;

class LineEtpGxcw extends Controller {

    public function index() {
        if (empty($_GET['id']))
            die('无效的编码');
        $id = $_GET['id'];
        $edate = date("Y-m-d");
        $sdate = date('Y-m-d', strtotime("$edate -1 month"));
        if (!empty($_GET['stime'])) {
            $sdate = $_GET['stime'];
        }
        if (!empty($_GET['etime'])) {
            $edate = substr($_GET['etime'], 0, 10);
        }
        $this->assign('id', $id);
        $this->assign('edate', $edate);
        $this->assign('sdate', $sdate);
        return $this->fetch('line_etp_gxcw');
    }

    public function getjson() {
        $edate = date("Y-m-d");
        $sdate = date('Y-m-d', strtotime("$edate -1 month"));
        if (empty($_GET['sid']))
            return;
        $sid = $_GET['sid'];
        if (!empty($_GET['stime'])) {
            $sdate = date('Y-m-d', strtotime($_GET['stime']));
        }
        if (!empty($_GET['etime'])) {
            $edate = date('Y-m-d', strtotime($_GET['etime']));
            $edate = date('Y-m-d', strtotime("$edate 1 day"));
        }
        $b = Db::query("select d_time,t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 from data_etp_h where EQMID='{$sid}' and d_time >'{$sdate}' and d_time<'{$edate}'");
        foreach ($b as $k => $v) {
            foreach ($v as $k1 => $v1) {
                if ($k1 != 'd_time') {
                    $b[$k][$k1] = floatval($v1);
                }
            }
        }
        $data = json_encode($b);
        echo $data;
    }

}
