RedListController.class.php
2.89 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
<?php
/**
* 【业绩比拼-手机端】红包领取列表详情
* RedListController.class.php
*
* User: daijun
* Date: 2017-11-04
*/
namespace Api\Controller\Red;
use Common\Service\PacketrecordService;
class RedListController extends \Api\Controller\AbstractController
{
public function Index_get()
{
// 获取参数
$params = I('get.');
// 红包记录ID
$rid = intval($params['rid']);
if (empty($this->uid)) {
// 判断是否外部人员
E('_EMPTY_USER_ID');
}
if (empty($rid)) {
// 数据验证
E('_EMPTY_RED_RECORD_ID');
}
// 实例化红包记录表
$record_service = new PacketrecordService();
// 红包记录详情
$detail = $record_service->get_by_conds([
'rid' => $rid, // 红包记录id
'uid' => $this->uid, // 用户uid
'packet_status' => PacketrecordService::PACKET_STATUS_SUCCESS // 红包状态:领取成功
]);
if (empty($detail)) {
// 红包记录不存在
E('_ERR_RED_RECORD_DATA');
}
// 默认值
$page = isset($params['page']) ? intval($params['page']) : PacketrecordService::DEFAULT_PAGE;
$limit = isset($params['limit']) ? intval($params['limit']) : PacketrecordService::DEFAULT_LIMIT;
if (PacketrecordService::RED_PACKET_RAND != $detail['p_type']) {
// 如果不是随机比例红包,直接返回
$this->_result = [
'total' => 0,
'limit' => intval($limit),
'page' => intval($page),
'list' => []
];
return true;
}
// 分页
list($start, $limit) = page_limit($page, $limit);
// 组装查询条件
$conds = [
'ac_id' => $detail['ac_id'],// 同一个活动
'p_type' => $detail['p_type'], // 相同的红包类型
'packet_status' => PacketrecordService::PACKET_STATUS_SUCCESS, // 红包状态:领取成功
];
// 查询当前活动领取成功的红包记录数
$total = $record_service->count_by_conds($conds);
$list = [];
if ($total) {
// 排序:成功领取时间倒序
$order_option = ['receive_time' => 'DESC'];
// 分页
$page_option = [$start, $limit];
// 查询字段
$field = 'rand_money,rid,uid,receive_time';
// 获取列表
$record_list = $record_service->list_by_conds($conds, $page_option, $order_option, $field);
$list = $record_service->format_records_list($record_list);
}
$this->_result = [
'total' => intval($total),
'limit' => intval($limit),
'page' => intval($page),
'list' => $list
];
return true;
}
}