审查视图

app/portal/controller/AdminStatisticsController.php 3.6 KB
董瑞恩 authored
1 2 3 4 5 6 7 8 9 10 11 12
<?php
/**
 * Created by PhpStorm.
 * User: ruidiudiu
 * Date: 2018/11/21
 * Time: 17:20
 */

namespace app\portal\controller;


use cmf\controller\AdminBaseController;
董瑞恩 authored
13 14
use think\Db;
董瑞恩 authored
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * 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(){
董瑞恩 authored
31 32 33 34
        $hospital=$this->request->param('hospital');
        $where=array();

董瑞恩 authored
35
        //医院总体时长统计
董瑞恩 authored
36 37 38 39 40
        $data=Db::name('order')
            ->alias('a')
            ->field('b.hospital,count(*) as num')
            ->join('equipment b','a.eq_name=b.name')
            ->group('b.hospital')
董瑞恩 authored
41 42 43 44
            ->select()->toArray();
        $hospital=array();
        $num=array();
        foreach ($data as $k=>$v){
董瑞恩 authored
45 46
            $hospital[$k]=$v['hospital'];
            $num[$k]=$v['num'];
董瑞恩 authored
47
        }
董瑞恩 authored
48
董瑞恩 authored
49 50
        $this->assign('hospital',json_encode($hospital));
        $this->assign('num',json_encode($num));
董瑞恩 authored
51
董瑞恩 authored
52
        //周统计
董瑞恩 authored
53
        $week=array();
董瑞恩 authored
54 55
        for ($i = 1; $i <= 31; $i++){
            $week[31-$i]=strtotime(date('Ymd',strtotime("-$i monday")));
董瑞恩 authored
56
        }
董瑞恩 authored
57
        $Week_interval=array();
董瑞恩 authored
58
        for ($i = 0; $i<30; $i++){
董瑞恩 authored
59
            $Week_interval[$i]=[$week[$i],$week[$i+1]];
董瑞恩 authored
60
        }
董瑞恩 authored
61
        $Week_statistics=array();
董瑞恩 authored
62
        $Week=array();
董瑞恩 authored
63
        for ($i = 0; $i<30; $i++){
董瑞恩 authored
64 65
            $Week[]=date('Y-m-d',$Week_interval[$i][1]);
            $Week_statistics[]=Db::name('order')->where('start_time','between',$Week_interval[$i])->count();
董瑞恩 authored
66
        }
董瑞恩 authored
67
        $this->assign('week',json_encode($Week));
董瑞恩 authored
68
        $this->assign('weekData',json_encode($Week_statistics));
董瑞恩 authored
69
        //月统计
董瑞恩 authored
70 71
        $month=array();
        for ($i = 0; $i <= 24; $i++){
董瑞恩 authored
72
            $month[24-$i]=strtotime(date('Y-m-1',strtotime("-$i Month")));
董瑞恩 authored
73
        }
董瑞恩 authored
74
        $month_interval=array();
董瑞恩 authored
75
        for ($i = 0; $i<24; $i++){
董瑞恩 authored
76
            $month_interval[$i]=[$month[$i],$month[$i+1]];
董瑞恩 authored
77 78
        }
        $Month_statistics=array();
董瑞恩 authored
79
        $Month=array();
董瑞恩 authored
80
        for ($i = 0; $i<24; $i++){
董瑞恩 authored
81 82
            $Month[]=date('Y-m-d',$month_interval[$i][1]);
            $Month_statistics[]=Db::name('order')->where('start_time','between',$month_interval[$i])->count();
董瑞恩 authored
83
        }
董瑞恩 authored
84
        $this->assign('month',json_encode($Month));
董瑞恩 authored
85 86
        $this->assign('monthData',json_encode($Month_statistics));
董瑞恩 authored
87
        //时间段统计
董瑞恩 authored
88
        $interval=array();
董瑞恩 authored
89
        $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')";
董瑞恩 authored
90
        $interval[0]=Db::query($sql);
董瑞恩 authored
91
        $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'";
董瑞恩 authored
92
        $interval[1]=Db::query($sql);
董瑞恩 authored
93
        $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'";
董瑞恩 authored
94
        $interval[2]=Db::query($sql);
董瑞恩 authored
95
        $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'";
董瑞恩 authored
96
        $interval[3]=Db::query($sql);
董瑞恩 authored
97 98 99
        foreach ($interval as $k=>$v){
            $interval[$k]=$interval[$k][0]['num'];
        }
董瑞恩 authored
100
        $this->assign('interval',json_encode($interval));
董瑞恩 authored
101 102 103 104 105 106 107
        return $this->fetch();
    }




}