AdminStatisticsController.php
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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(){
$param=$this->request->param();
$where='';
$where1=[];
if (!empty($param['hospital'])){
$where="hospital='".$param['hospital']."' AND";
$where1['hospital']=$param['hospital'];
}
//医院总体时长统计
$data=Db::name('order')
->alias('a')
->field('b.hospital,count(*) as num')
->join('equipment b','a.eq_name=b.name')
->group('b.hospital')
->select()->toArray();
$hospital=array();
$num=array();
foreach ($data as $k=>$v){
$hospital[$k]=$v['hospital'];
$num[$k]=$v['num'];
}
$this->assign('hospitalJson',json_encode($hospital));
$this->assign('num',json_encode($num));
//周统计
$week=array();
for ($i = 1; $i <= 31; $i++){
$week[31-$i]=strtotime(date('Ymd',strtotime("-$i monday")));
}
$Week_interval=array();
for ($i = 0; $i<30; $i++){
$Week_interval[$i]=[$week[$i],$week[$i+1]];
}
$Week_statistics=array();
$Week=array();
for ($i = 0; $i<30; $i++){
$Week[]=date('Y-m-d',$Week_interval[$i][1]);
$Week_statistics[]=Db::name('order')->where('start_time','between',$Week_interval[$i])->count();
}
$this->assign('week',json_encode($Week));
$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_interval=array();
for ($i = 0; $i<24; $i++){
$month_interval[$i]=[$month[$i],$month[$i+1]];
}
$Month_statistics=array();
$Month_money=array();
$Month=array();
for ($i = 0; $i<24; $i++){
$Month[]=date('Y-m-d',$month_interval[$i][1]);
$Month_statistics[]=Db::name('order')->where('start_time','between',$month_interval[$i])->count();
$Month_money[]=Db::name('order')
->alias('o')
->join('equipment e','o.eq_name=e.name')
->where($where1)
->where('o.start_time','between',$month_interval[$i])
->where('o.state',3)
->sum('o.price');
}
$this->assign('month',json_encode($Month));
$this->assign('monthData',json_encode($Month_statistics));
$this->assign('monthMoney',json_encode($Month_money));
//时间段统计
$interval=array();
$sql="SELECT sleep_equipment.hospital,count(*) as num FROM sleep_order INNER JOIN sleep_equipment ON sleep_order.eq_name=sleep_equipment.name where (".$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 sleep_equipment.hospital,count(*) as num FROM sleep_order INNER JOIN sleep_equipment ON sleep_order.eq_name=sleep_equipment.name where (".$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 sleep_equipment.hospital,count(*) as num FROM sleep_order INNER JOIN sleep_equipment ON sleep_order.eq_name=sleep_equipment.name where (".$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 sleep_equipment.hospital,count(*) as num FROM sleep_order INNER JOIN sleep_equipment ON sleep_order.eq_name=sleep_equipment.name where ".$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));
$this->assign('hospital', isset($param['hospital']) ? $param['hospital'] : '');
return $this->fetch();
}
}