AdminDataController.php
3.0 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
<?php
/**
* 数据统计
* Author : xiaojie
* DateTime: 2018/12/04 13:11
*/
namespace app\portal\controller;
use app\portal\model\StatisticsModel;
use cmf\controller\AdminBaseController;
/**
* Class AdminDataController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'数据统计',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 30,
* 'icon' =>'th',
* 'remark' =>'数据统计'
* )
*/
class AdminDataController extends AdminBaseController
{
/**
* 数据统计
* @adminMenu(
* 'name' => '数据统计',
* 'parent' => 'portal/AdminData/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '数据统计',
* 'param' => ''
* )
*/
public function index()
{
$param = $this->request->param();
$statisticsModel = new StatisticsModel();
$map = $this->search2($param);
$total_num = $statisticsModel->getTotalNum();
$today_num = $statisticsModel->getTodayNum();
$data = $statisticsModel->getBrokenData($map);
$list3 = $statisticsModel->getCakeData($map);
$list1 = empty($data)?'':json_encode($data['list1']);
$list2 = empty($data)?'':json_encode($data['list2']);
$list3 = empty($list3)?'':json_encode($list3);
$this->assign('total_num',$total_num);
$this->assign('today_num',$today_num);
$this->assign('list1',$list1);
$this->assign('list2',$list2);
$this->assign('list3',$list3);
return $this->fetch();
}
/**
* 统计查询
* Author:xieJie
* @param $param 所接收数据
* @return array
*/
public function search2($param)
{
$map['status'] = 1;
if(isset($param['time']) && !empty($param['time'])){
if($param['time'] == 7){
$param['start_time'] = date('Y-m-d H:i',time() - 86400*7);
$param['end_time'] = date('Y-m-d H:i',time());
$this->assign('time',7);
}elseif ($param['time'] == 30){
$param['start_time'] = date('Y-m-d H:i',time() - 86400*30);
$param['end_time'] = date('Y-m-d H:i',time());
$this->assign('time',30);
}else{
return false;
}
}else{
$this->assign('time','');
}
if(isset($param['start_time']) && !empty($param['start_time']) && isset($param['end_time']) && !empty($param['end_time'])){
$start_date = isset($param['start_time'])?strtotime($param['start_time']):'';
$end_date = isset($param['end_time'])?strtotime($param['end_time']):'';
$map['create_time'] = ['between',[$start_date,$end_date]];
$this->assign('start_time',$param['start_time']);
$this->assign('end_time',$param['end_time']);
}
return $map;
}
}