ListController.class.php
2.68 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
<?php
/**
*【积分抽奖-后台】中奖列表接口
* User: daijun
* Date: 2018/3/23
* Time: 下午3:42
*/
namespace Apicp\Controller\Prize;
use Common\Common\Constant;
use Common\Service\RecordService;
class ListController extends \Apicp\Controller\AbstractController
{
public function Index_post()
{
// 获取参数
$params = I('post.');
if (empty($params['ac_id'])) {
// 活动ID不能为空
E('_EMPTY_ACTIVITY_ID');
}
if (!isset($params['type']) || !in_array($params['type'], [Constant::HAVE_PRIZE, Constant::NO_PRIZE])) {
// 如果type为空或者不是特定的数值【未中奖,已中奖】
E('_ERR_RECORDS_TYPE');
}
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : Constant::DEFAULT_PAGE;
$limit = !empty($params['limit']) ? intval($params['limit']) : Constant::DEFAULT_LIMIT;
// 分页
list($start, $limit) = page_limit($page, $limit);
$page_option = [$start, $limit];
// 时间倒序
$order_option = ['lr_id' => 'DESC'];
$record_serv = new RecordService();
// 组织查询条件
$where = $record_serv->get_where($params);
// 列表总数
$total = $record_serv->count_by_conds($where);
$list = [];
if ($total > 0) {
// 定义查询字段
$fields = 'lr_id,lp_id,lp_name,is_prize,username,dp_name,mobile,role,job,remark,created';
// 查询列表数据
$list = $record_serv->list_by_conds($where, $page_option, $order_option, $fields);
}
if ($params['type'] == Constant::HAVE_PRIZE) {
// 已中奖情况下需要查询未中奖总数
$total_no_prize = $record_serv->count_by_conds(['is_prize' => Constant::NO_PRIZE, 'ac_id' => $params['ac_id']]);
$total_prize = $total;
} else {
// 未中奖情况下
foreach ($list as &$prize) {
// 循环格式化中奖信息为'谢谢参与'
$prize['lp_name'] = '谢谢参与';
}
// 未中奖情况下需要查询已中奖总数
$total_prize = $record_serv->count_by_conds(['is_prize' => Constant::HAVE_PRIZE, 'ac_id' => $params['ac_id']]);
$total_no_prize = $total;
}
// 组装返回数据
$this->_result = [
'total' => intval($total),
'total_prize' => $total_prize,
'total_no_prize' => $total_no_prize,
'limit' => intval($limit),
'page' => intval($page),
'list' => $list
];
return true;
}
}