Index.php 6.3 KB
<?php

namespace app\notify\controller;

use app\common\controller\Frontend;
use think\Db;
class Index extends Frontend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = '';
    
    public function _initialize()
    {
        parent::_initialize();

        $this->model = new \app\admin\model\reservoir\Messagelog;
    }
    public function index()
    {
        
        $list = $this->model
                ->field('log.*,r.name,u.name as user_name')
                ->alias('log')
                ->join('reservoir_list r','r.id=log.reservoir_id')
                ->join('reservoir_user u','u.reservoir_id=log.reservoir_id')
                ->order('createtime desc')
                ->limit(4)
                ->select();
        
        $this->view->assign([
            'smstodaycount' => $this->gettodaycount('sms'),
            'smsreservoircount'=> $this->reservoircount('sms'),
            'smsallcount' =>$this->getallcount('sms'),
            
            'voicetodaycount' => $this->gettodaycount('voice'),
            'voicereservoircount'=> $this->reservoircount('voice'),
            'voiceallcount' =>$this->getallcount('voice'),
            
            'wechattodaycount' => $this->gettodaycount('wechat'),
            'wechatreservoircount'=> $this->reservoircount('wechat'),
            'wechatallcount' =>$this->getallcount('wechat'),
            
            'apptodaycount' => $this->gettodaycount('app'),
            'appreservoircount'=> $this->reservoircount('app'),
            'apptallcount' =>$this->getallcount('app'),
            
            'dingdingtodaycount' => $this->gettodaycount('dingding'),
            'dingdingreservoircount'=> $this->reservoircount('dingding'),
            'dingdingtallcount' =>$this->getallcount('dingding'),
            
            'warning' => $this->warningcount(),
            
            'xy' => $this->xy(),
            'list' => $list
        ]);   
        return $this->view->fetch();
    }
    public function xy()
    {
           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('reservoir_massge_log')->where('createtime','>=',${'predaystart'.$i})->where('createtime','<',${'predayend'.$i})->count();
            $res['date'][] ='\''.date('m-d',strtotime("-$i day")).'\'';;
            $res['count'][] = ${'predaycount'.$i};
        }
        $today = strtotime(date("Y-m-d",time()));
        $todaylist = Db::name('reservoir_massge_log')->where('createtime','>=',$today)->count();
        $res['date'][] = '\''.date("m-d",time()).'\'';
        $res['count'][] = $todaylist;
        return ['x'=>implode (',',$res['date']),'y'=>implode (',',$res['count'])];
    }
    private function warningcount()
    {
       return  array_sum([
                    Db::name('reservoir_hkws_warning')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_crack')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_displacement')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_invade')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_rainfall')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_settlement')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_waterlevel')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_waterseepage')->whereTime('createtime','d')->count(),
                    Db::name('reservoir_warning_weather')->whereTime('createtime','d')->count()
                ]);
    }
    private function gettodaycount($type)
    {
        return $this->model::whereTime('createtime','d')->where('type',$type)->count();
    }
    private function getallcount($type)
    {
        return $this->model::where('type',$type)->count();
    }
    private function reservoircount($type)
    {
        return $this->model::where('type',$type)->group('reservoir_id')->count();
    }
    public function list()
    {
        
        if($this->request->isPost()){
            $type = $this->request->post('type');
            $page = $this->request->post('page',1);
            $limit = $this->request->post('limit',10);
            $r = $this->request->post('r');
            $sea = $this->request->post('sea');
            $condtion = [];
            if ($r) {
                $condtion['r.id'] = ['=',$r];
            }
            if($sea){
                $condtion['log.id|r.name|log.content']  = ['like','%'.$sea.'%'] ;
            }
            $total = $this->model
                ->field('log.*,r.name')
                ->alias('log')
                ->join('reservoir_list r','r.id=log.reservoir_id')
                ->where('log.type',$type)
                ->where($condtion)
                ->count();
            $list = $this->model
                ->field('log.*,r.name,u.name as user_name')
                ->alias('log')
                ->join('reservoir_list r','r.id=log.reservoir_id')
                ->join('reservoir_user u','u.reservoir_id=log.reservoir_id')
                ->where('log.type',$type)
                ->where($condtion)
                ->page($page,$limit)
                ->select();
            return json(['code'=>1,'data'=>$list,'total'=>$total]);
        }
        $list = Db::name('reservoir_list')->field('id,name')->where('county_id',1)->select();
        $str = '';
        switch ($this->request->get('type')) {
            case 'sms':
                $str='短信';
                break;
            case 'voice':
                $str='语音';
                break;
            
            case 'wechat':
                $str='微信';
                break;
            case 'app':
                $str='app';
                break;
            case 'dingding':
                $str='钉钉';
                break;
            case 'qywechat':
                $str='企业微信';
                break;
            default:
                // code...
                break;
        }
        $this->view->assign('str',$str);
        $this->view->assign('list',$list);
        return $this->view->fetch();
    }
   
    
  
}