ExcListController.class.php
5.66 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
175
176
177
178
179
180
181
<?php
/**
* Created by IntelliJ IDEA.
* 兑奖列表
* User: gaoyaqiu
* Date: 2016-12-09
*/
namespace Apicp\Controller\Mall;
use Common\Common\User;
use Common\Model\ConvertModel;
use Common\Service\ConvertService;
use Common\Service\PrizeService;
use VcySDK\Attach;
use VcySDK\Service;
class ExcListController extends AbstractController
{
public function before_action($action = '')
{
// 开启自动获取
$this->autoGetData = true;
$this->field = [
'ia_id' => [
'require' => false,
'verify' => 'intval',
'cn' => '奖品ID',
],
'name' => [
'require' => false,
'verify' => 'strval',
'cn' => '奖品名称',
],
'memUserName' => [
'require' => false,
'verify' => 'strval',
'cn' => '姓名',
],
'convert_status' => [
'require' => false,
'verify' => 'intval',
'cn' => '兑奖状态',
'area' => [
ConvertModel::CONVERT_STATUS_ING,
ConvertModel::CONVERT_STATUS_AGREE,
ConvertModel::CONVERT_STATUS_DEFUSE,
ConvertModel::CONVERT_STATUS_CANCEL,
],
],
'dep' => [
'require' => false,
'verify' => 'strval',
'cn' => '部门ID',
],
'number' => [
'require' => false,
'verify' => 'strval',
'cn' => '兑换编码',
],
'applicant_phone' => [
'require' => false,
'verify' => 'strval',
'cn' => '手机号',
],
'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();
// 过滤用户
$uidArray = array();
// 根据用户名查询
$memUserName = $this->data['memUserName'];
// 按部门查询
$dpId = $this->data['dep'];
$innserParams = array();
if (!empty($memUserName) || !empty($dpId)) {
$memServ = new User();
$innserParams['dpId'] = $dpId;
$innserParams['memUsername'] = $memUserName;
$userData = $memServ->listByConds($innserParams, 1, 1);
if (!empty($userData) && $userData['total'] > 0) {
$userData = $memServ->listByConds($innserParams, 1, $userData['total']);
$uidArray = array_column($userData['list'], 'memUid');
}
if (empty($uidArray)) {
$this->_result['list'] = array();
$this->_result['total'] = 0;
return true;
}
$this->data['uids'] = $uidArray;
}
// 兑奖列表
$this->_result['list'] = $convertServ->getPrizeConvertPageList($this->data, [$start, $perpage]);
$this->_result['total'] = $convertServ->countPrizeConvert($this->data);
// 处理返回值
$this->dealResult();
return true;
}
/**
* 处理返回值
* @return bool
*/
protected function dealResult()
{
// 所有奖品 ID
$aiIds = array_column($this->_result['list'], 'ia_id');
$prizeList = [];
$attList = [];
if (!empty($aiIds)) {
$prizeServ = new PrizeService();
// 获取奖品
$prizeList = $prizeServ->list_by_pks($aiIds);
$prizeList = array_combine_by_key($prizeList, 'ia_id');
$allAtId = [];
foreach ($prizeList as &$prize) {
$prize['picture'] = explode(',', $prize['picture']);
// 获取所有的奖品图片
$allAtId = array_merge($allAtId, $prize['picture']);
}
// 获取奖品图片地址
if (!empty($allAtId)) {
$attSdk = new Attach(Service::instance());
$attList = $attSdk->listAll(['atIds' => array_unique($allAtId)]);
$attList = array_combine_by_key($attList['list'], 'atId');
}
}
$memServ = new User();
foreach ($this->_result['list'] as &$item) {
// 获取用户
$member = $memServ->getByUid($item['uid']);
if (!empty($member)) {
$item['memUserName'] = $member['memUsername'];
// 获取部门名称
$depName = array_column($member['dpName'], 'dpName');
$item['dpName'] = implode(';', $depName);
}
// 获取奖品图片
$atId = empty($prizeList[$item['ia_id']]['picture'][0]) ? '' : $prizeList[$item['ia_id']]['picture'][0];
$item['picture'] = empty($attList[$atId]['atAttachment']) ? '' : $attList[$atId]['atAttachment'];
}
return true;
}
}