RedListController.class.php
3.71 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
<?php
/**
* 【销售活动-后台】后台活动红包记录列表
*
* author xtong
*/
namespace Apicp\Controller\Red;
use Com\PackageValidate;
use Common\Common\User;
use Common\Service\ActivityService;
use Common\Service\PacketrecordService;
class RedListController extends \Apicp\Controller\AbstractController
{
/**
* 接收参数
* ac_id int 必填 活动ID
*
* @return bool
*/
public function Index_post()
{
// 验证规则
$rules = [
'ac_id' => 'require',
];
$msg = [
'ac_id.require' => L('_EMPTY_ACTIVITY_ID'),
];
// 验证数据
$validate = new PackageValidate($rules, $msg, array_keys($rules));
$postData = $validate->postData;
$params = I('post.');
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : PacketrecordService::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : PacketrecordService::DEFAULT_LIMIT;
// 分页
list($start, $limit) = page_limit($page, $limit);
// 按照发布时间排序
$order_option = ['give_time' => 'DESC'];
// 查询红包记录(有红包的活动不允许删除)
$record_conds = [
'ac_id' => $postData['ac_id'],
];
// 初始化表
$activity_s = new ActivityService();
// 活动获取
$activity_info = $activity_s->get($postData['ac_id']);
if (empty($activity_info)) {
E('_ERR_ACTIVITY_NOT_FOUND');
}
// 如果搜索用户名
if (!empty($params['username'])) {
// 通过用户名获取用户UID
$uids = $activity_s->get_username_uid($params['username']);
$record_conds['uid'] = $uids;
} else {
$record_conds['uid <> ?'] = '';
}
$packetrecord_s = new PacketrecordService();
$total = $packetrecord_s->count_by_conds($record_conds);
if (!empty($total)) {
$record_list = $packetrecord_s->list_by_conds($record_conds, [$start, $limit], $order_option);
}
$list = $this->format_record_list($record_list);
$this->_result = [
'stop_pay_time' => $activity_info['stop_pay_time'],
'page' => $page,
'limit' => $limit,
'total' => $total,
'list' => $list
];
return true;
}
/**
* 格式化红包记录列表
*
* @param $record_list $array
*
* @return array
*/
protected function format_record_list($record_list)
{
$list = [];
if (!empty($record_list)) {
$uids = array_column($record_list, 'uid');
$user_s = new User();
$user_list = $user_s->listByUid($uids);
foreach ($record_list as $record_k => $record_v) {
$telephone = $user_list[$record_v['uid']]['memMobile'];
$list[$record_k] = [
'rid' => $record_v['rid'],
'wtlPlatformOrderNo' => $record_v['order_sn'],
'name' => $record_v['username'],
'telephone' => $telephone ? $telephone : '',
'red_total_money' => sprintf("%.2f", $record_v['rand_money'] / 100),
'red_type' => $record_v['p_type'],
'send_uname' => $record_v['send_uname'],
'send_phone' => $record_v['send_phone'],
'packet_status' => $record_v['packet_status'],
'give_time' => $record_v['give_time'],
'receive_time' => $record_v['receive_time']
];
}
}
return $list;
}
}