MemberExcListController.class.php
5.04 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Created by IntelliJ IDEA.
* 兑奖列表
* User: gaoyaqiu
* Date: 2016-12-09
*/
namespace Apicp\Controller\Mall;
use Common\Common\Attach;
use Common\Model\ConvertModel;
use Common\Service\ConvertService;
use Common\Common\Department;
use Common\Common\User;
use VcySDK\Adminer;
use VcySDK\Service;
class MemberExcListController extends AbstractController
{
protected $_require_login = false;
public function before_action($action = '')
{
// 开启自动获取
$this->autoGetData = true;
$this->field = [
'uid' => [
'require' => true,
'verify' => 'strval',
'cn' => '人员ID',
],
'convert_status' => [
'require' => false,
'verify' => 'intval',
'cn' => '兑换状态',
'area' => [ConvertModel::CONVERT_STATUS_ING, ConvertModel::CONVERT_STATUS_AGREE, ConvertModel::CONVERT_STATUS_DEFUSE, ConvertModel::CONVERT_STATUS_CANCEL],
],
'startTime' => [
'require' => false,
'verify' => 'intval',
'cn' => '申请开始时间',
],
'endTime' => [
'require' => false,
'verify' => 'intval',
'cn' => '申请结束时间',
],
'page' => [
'require' => false,
'default' => 1,
'verify' => 'intval',
],
'limit' => [
'require' => false,
'default' => 15,
'verify' => 'intval',
],
];
return parent::before_action($action);
}
public function Index()
{
// 分页参数
list($start, $perpage, $this->_result['page']) = $this->getPageOption('page', 'limit');
$convertServ = new ConvertService();
// 获取兑换列表
$this->data['uids'] = $this->data['uid'];
unset($this->data['uid']);
$this->_result['list'] = $convertServ->getPrizeConvertPageList($this->data, [$start, $perpage], ['created' => 'DESC']);
// 总数
$countConds = [
'uid' => $this->data['uids'],
];
if (!empty($this->data['startTime'])) {
$countConds['created<?'] = $this->data['startTime'];
}
if (!empty($this->data['startTime'])) {
$countConds['created>?'] = $this->data['endTime'];
}
if (!empty($this->data['convert_status'])) {
$countConds['convert_status'] = $this->data['convert_status'];
}
$this->_result['total'] = $convertServ->count_by_conds($countConds);
// 处理返回数据
$this->dealResult();
return true;
}
/**
* 处理返回数据
* @return bool
*/
protected function dealResult()
{
// 获取需要查询操作时间的兑换记录
$operatorArr = [];
$uidArr = [];
foreach ($this->_result['list'] as &$item) {
// 获取管理员信息的情况
if (in_array($item['convert_status'], [ConvertModel::CONVERT_STATUS_AGREE, ConvertModel::CONVERT_STATUS_DEFUSE])) {
$operatorArr[] = $item['operator'];
// 获取人员信息的情况
} elseif (in_array($item['convert_status'], [ConvertModel::CONVERT_STATUS_CANCEL])) {
$uidArr[] = $item['uid'];
}
unset($item['applicant_phone'], $item['number']);
}
// 获取操作人员信息
$this->getOperatorInfo($operatorArr);
// 获取人员信息
$this->getUidInfo($uidArr);
return true;
}
/**
* 获取操作人员信息
* @param $operatorArr
* @return bool
*/
protected function getOperatorInfo($operatorArr)
{
if (empty($operatorArr)) {
return true;
}
// 获取操作人ID
$adminer = new Adminer(Service::instance());
foreach ($operatorArr as $eaId) {
$operatorList[] = $adminer->fetch(['eaId' => $eaId]);
}
// 合并操作人员信息
$operatorList = array_combine_by_key($operatorList, 'eaId');
foreach ($this->_result['list'] as &$item) {
if (!empty($item['operator'])) {
$item['operatorName'] = $operatorList[$item['operator']]['eaRealname'];
$item['eaMobile'] = $operatorList[$item['operator']]['eaMobile'];
}
}
return true;
}
/**
* 获取人员信息
* @param $uidArr
* @return bool
*/
protected function getUidInfo($uidArr)
{
if (empty($uidArr)) {
return true;
}
$user = new User();
$userList = $user->listByUid($uidArr);
foreach ($this->_result['list'] as &$item) {
if (in_array($item['convert_status'], [ConvertModel::CONVERT_STATUS_CANCEL])) {
$item['operatorName'] = $userList[$item['uid']]['memUsername'];
}
}
return true;
}
}