AdminStatisticsController.php 2.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: ruidiudiu
 * Date: 2018/11/21
 * Time: 17:20
 */

namespace app\portal\controller;


use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class AdminStatisticsController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'数据统计',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 1,
 *     'icon'   =>'th',
 *     'remark' =>'数据统计'
 * )
 */
class AdminStatisticsController extends AdminBaseController{

    public function index(){
        //医院总体时长统计
        $hospital=Db::name('equipment')->field('hospital')->group('hospital')->select()->toArray();
        dump($hospital);

        //周统计
        $week=array();
        for ($i = 0; $i <= 15; $i++){
            $week[15-$i]=strtotime(date('Ymd',strtotime("-$i week")));
        }
        $Week=array();
        for ($i = 0; $i<15; $i++){
            $Week[$i]=[$week[$i],$week[$i+1]];
        }
        $Week_statistics=array();
        for ($i = 0; $i<15; $i++){
            $Week_statistics[]=Db::name('order')->where('start_time','between',$Week[$i])->count();
        }
        $this->assign('weekData',json_encode($Week_statistics));
        //月统计
        $month=array();
        for ($i = 0; $i <= 24; $i++){
            $month[24-$i]=strtotime(date('Y-m-1',strtotime("-$i Month")));
        }
        $Month=array();
        for ($i = 0; $i<24; $i++){
            $Month[$i]=[$month[$i],$month[$i+1]];
        }
        $Month_statistics=array();
        for ($i = 0; $i<24; $i++){
            $Month_statistics[]=Db::name('order')->where('start_time','between',$Month[$i])->count();
        }
        $this->assign('monthData',json_encode($Month_statistics));

        //时间段统计
        $interval=array();
        $sql="SELECT count(*) as num FROM  sleep_order where FROM_UNIXTIME(start_time,'%H:%i:%S')>'00:00:00' AND FROM_UNIXTIME(start_time,'%H:%i:%S')<'07:00:00' OR FROM_UNIXTIME(start_time,'%H:%i:%S')>'21:00:00' AND FROM_UNIXTIME(start_time,'%H:%i:%S')<'24:00:00'";
        $interval[0]=Db::query($sql);
        $sql="SELECT count(*) as num FROM  sleep_order where FROM_UNIXTIME(start_time,'%H:%i:%S')>'07:00:00' AND FROM_UNIXTIME(start_time,'%H:%i:%S')<'12:00:00'";
        $interval[1]=Db::query($sql);
        $sql="SELECT count(*) as num FROM  sleep_order where FROM_UNIXTIME(start_time,'%H:%i:%S')>'12:00:00' AND FROM_UNIXTIME(start_time,'%H:%i:%S')<'17:00:00'";
        $interval[2]=Db::query($sql);
        $sql="SELECT count(*) as num FROM  sleep_order where FROM_UNIXTIME(start_time,'%H:%i:%S')>'17:00:00' AND FROM_UNIXTIME(start_time,'%H:%i:%S')<'21:00:00'";
        $interval[3]=Db::query($sql);
        foreach ($interval as $k=>$v){
            $interval[$k]=$interval[$k][0]['num'];
        }
        $this->assign('interval',json_encode($interval));
        return $this->fetch();
    }




}