Inspection.php 2.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: yrf
 * Date: 2022/4/3
 * Time: 9:24
 * ResvRaninDate
 * 水库安全运行监测大屏接口
 *
 */

namespace app\api\controller\safeoperation;

use app\common\controller\Api;
use fast\Tree;
use think\Db;
use think\Request;


class Inspection extends Api
{
    protected $id;
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model = null;

    public function _initialize()
    {
        $this->id = $this->request->param('id');
        // var_dump($this->id);die;
        parent::_initialize();
    }

    /**
     * 水库实时坝体位移报告
     * @var
     */
    public function Displacement()
    {
        //位移表模型
        $model = new \app\admin\model\reservoir\dam\Displacement;
        $data = collection($model->where('reservoir_id', $this->id)
            ->field('vertical,horizontal,horizontalY,from_unixtime(createtime,"%m-%d %h:%i") as createtime')
            ->order('createtime desc')
            ->limit(20)
            ->select())->toArray();
        $return_data = [];
        if (!empty($data)) {
            foreach ($data as $k => $v) {
                unset($v['status_text']);
                unset($v['warning_text']);
                $return_data[$k] = array_values($v);
            }
        }
        $this->success('请求成功', $return_data);
    }

    public function Reservoirname()
    {
        $name = Db::name('reservoir_list')->where('id',$this->id)->field('name')->find();
        $this->success('请求成功',$name);
    }

    public function getgnss(){
        $model = new \app\admin\model\reservoir\dam\Displacement;
        $time = $model->where('reservoir_id', $this->id)
            ->field('from_unixtime(createtime,"%Y-%m-%d ") as createtime')
            ->order('createtime desc')
            ->find()['createtime'];
        $x = [];
        $y = [];
        $z = [];
        $xtime = [];
        for ($i = 0; $i < 5; $i++) {
            $time1 = date('Y-m-d',strtotime("$time - $i day"));
            $dataxyz = $model->where('reservoir_id', $this->id)
            ->where('createtime','between time',[$time1,$time])
            ->field('vertical,horizontal,horizontalY,from_unixtime(createtime,"%m-%d %h:%i") as createtime')
            ->order('createtime desc')
            ->find();
            $x[] = $dataxyz['horizontal'];
            $y[] = $dataxyz['horizontalY'];
            $z[] = $dataxyz['vertical'];
            $xtime[] = date('m-d',strtotime("$time - $i day"));
            $time= date('Y-m-d',strtotime("$time - 1 day"));
        }
        $data = [
            'x' => $x,
            'y' => $y,
            'z' => $z,
            'time' => $xtime
            ];
        $this->success('',$data);
    }
}