<?php

namespace app\api\controller\inspection;

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

/**
 * 部门管理
 *
 * @icon fa fa-circle-o
 */
class Plan extends Api
{
    
    /**
     * Depart模型对象
     * @var \app\admin\model\inspection\Depart
     */
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\inspection\Plan();
    }
    
    public function getInfo(){
        $authid = $this->auth->id;
        $id = Db::name('inspection_staff')->where('user_id',$authid)->value('id');
        if(!$id){
            $this->error('该用户不是巡检人员');
        }
        $reservoir_id = Db::name('inspection_staff')->where('id',$id)->value('reservoir_id');
        $waterlevel = Db::name('reservoir_rain_water_level')->where('reservoir_id',$reservoir_id)->order('createtime desc')->value('water_level');
        $num = $this->model->where('staff_id',$id)->value('MAX(num)');
        $time = strtotime(date('Y-m-d',time()));
        $count = Db::name('inspection_project')->where('staff_id',$id)->where('createtime','>=',$time)->count();
        $perform = floor($count/$time);
        $data = [
          'waterlevel' => (int)$waterlevel,
          'num' => (int)$num,
          'perform' => (int)$perform
        ];
        $this->success('',$data);
    }
}