ActiveSignController.class.php
3.98 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
129
130
131
132
133
134
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/10/12
* Time: 19:58
*/
namespace Apicp\Controller\AllData;
use Com\PackageValidate;
use Common\Common\User;
use Common\Common\DataHelper;
use Common\Model\ActiveModel;
use Common\Model\SignModel;
class ActiveSignController extends \Apicp\Controller\AbstractController
{
/**
* ActiveSign
* @author zhonglei
* @desc 活跃人数和签到人数报表接口
*
* @param array dp_ids 部门ID数组
* @param Int starttime:true 开始时间戳
* @param Int endtime:true 结束时间戳
*
* @return array
array(
* 'days' => array( // X轴日期
* '2017.10.1',
* ),
* 'active_wx' => array( // 微信活跃人数数据
* '90',
* ),
* 'active_qywx' => array( // 企业微信活跃人数数据
* '100',
* ),
* 'active_total' => array( // 总活跃人数数据
* '190',
* ),
* )
*/
public function Index_post()
{
// 请求数据
$post_data = I('post.');
// 验证规则
$rules = [
'dp_ids' => 'array',
'starttime' => 'require|integer',
'endtime' => 'require|integer',
];
// 验证请求数据
$validate = new PackageValidate();
$validate->postData = $post_data;
$validate->validateParams($rules);
$dataHelper = &DataHelper::instance();
$starttime = $dataHelper->formatStarttime($post_data['starttime']);
$endtime = $dataHelper->formatEndtime($post_data['endtime']);
$days = $dataHelper->getEachDay($starttime, $endtime);
$active_wx = [];
$active_qywx = [];
$active_total = [];
$conds = [
'created >= ?' => $starttime,
'created <= ?' => $endtime,
];
// 根据部门ID获取用户ID
if (isset($post_data['dp_ids']) && !empty($post_data['dp_ids'])) {
$userServ = &User::instance();
$user_list = $userServ->listAll([
'dpIdList' => $post_data['dp_ids'],
'departmentChildrenFlag' => User::DEPARTMENT_CHILDREN_TRUE
]);
// 未找到任何用户
if (empty($user_list)) {
foreach ($days as $k => $day) {
$days[$k] = rgmdate(strval(rstrtotime($day)), 'Y/m/d');
}
$this->_result = [
'days' => $days,
'active_wx' => $active_wx,
'active_qywx' => $active_qywx,
'active_total' => $active_total
];
return true;
}
$conds['uid'] = array_column($user_list, 'memUid');
}
$activeModel = new ActiveModel();
// 获取所有活跃数据
$active_list = $activeModel->listActiveData($conds);
$active_all_data = array_combine_by_key($active_list, 'active_date');
// 获取微信活跃数据
$conds['source'] = 1; // 微信
$active_list = $activeModel->listActiveData($conds);
$active_wx_data = array_combine_by_key($active_list, 'active_date');
// 获取企业微信活跃数据
$conds['source'] = 2; // 企业微信
$active_list = $activeModel->listActiveData($conds);
$active_qywx_data = array_combine_by_key($active_list, 'active_date');
// 整合数据
foreach ($days as $k => $day) {
$active_wx[] = isset($active_wx_data[$day]) ? $active_wx_data[$day]['total'] : 0;
$active_qywx[] = isset($active_qywx_data[$day]) ? $active_qywx_data[$day]['total'] : 0;
$active_total[] = isset($active_all_data[$day]) ? $active_all_data[$day]['total'] : 0;
$days[$k] = rgmdate(strval(rstrtotime($day)), 'Y/m/d');
}
$this->_result = [
'days' => $days,
'active_wx' => $active_wx,
'active_qywx' => $active_qywx,
'active_total' => $active_total
];
}
}