Index.php 2.0 KB
<?php

namespace app\inspection\controller;

use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $this->view->assign([
            'project'=> \app\admin\model\inspection\Project::count(),
            'weeek_project'=> \app\admin\model\inspection\Project::whereTime('createtime', 'today')->count(),
            'finish_weeek_project'=> \app\admin\model\inspection\Project::whereTime('createtime', 'week')->where('status',1)->count(),
            'today_project'=> \app\admin\model\inspection\Project::whereTime('createtime', 'week')->count(),
            'today_warning'=> \app\admin\model\inspection\Warning::whereTime('createtime', 'today')->count(),
            'week_warning'=> \app\admin\model\inspection\Warning::whereTime('createtime', 'week')->count(),
            'week_task'=> \app\admin\model\inspection\Task::whereTime('createtime', 'week')->count(),
            'user_count'=> \app\admin\model\inspection\Staff::where('duty', '巡检员')->count(),
            
            ]);
        return $this->view->fetch();
    }
    public function project()
    {
        for($i=6;$i>=1;$i--){
            $k = $i-1;
            ${'predaystart'.$i} = strtotime(date('Y-m-d',strtotime("-$i day")));
            ${'predayend'.$i} = strtotime(date('Y-m-d',strtotime("-$k day")));
            ${'predaycount'.$i} = Db::name('inspection_project')->where('createtime','>=',${'predaystart'.$i})->where('createtime','<',${'predayend'.$i})->count();
            $res['date'][] = date('Y-m-d',strtotime("-$i day"));
            $res['count'][] = ${'predaycount'.$i};
        }
        $today = strtotime(date("Y-m-d",time()));
        $todaylist = Db::name('reservoir_run_work_log')->where('createtime','>=',$today)->count();
        $res['date'][] = date("Y-m-d",time());
        $res['count'][] = $todaylist;
        return json(['code'=>1,'data'=>$res]);
    }
    
  

}