ListController.class.php
2.1 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
<?php
/**
*【积分抽奖-后台】活动列表接口
* User: daijun
* Date: 2018/3/23
* Time: 下午3:42
*/
namespace Apicp\Controller\Activity;
use Common\Common\Constant;
use Common\Service\ActivityService;
class ListController extends \Apicp\Controller\AbstractController
{
public function Index_post()
{
// 获取参数
$params = I('post.');
// 默认值
$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 = ['last_time' => 'desc'];
$activity_serv = new ActivityService();
// 列表总数
$total = $activity_serv->count_by_where($params);
$list = [];
if ($total > 0) {
// 定义查询字段
$fields = 'ac_id,title,start_time,end_time,already_num,won_num,join_people,activity_status,last_time';
// 查询列表数据
$list = $activity_serv->list_by_where($params, $page_option, $order_option, $fields);
// 循环格式化数据
foreach ($list as &$v) {
$v['ac_id'] = intval($v['ac_id']);
$v['already_num'] = intval($v['already_num']);
$v['won_num'] = intval($v['won_num']);
$v['join_people'] = intval($v['join_people']);
// 转换活动状态
$v['activity_status'] = $activity_serv->activity_status($v['activity_status'], $v['start_time'], $v['end_time']);
// 获取链接
$v['link'] = 'Lottery/Frontend/Index/Index/Index/ac_id/' . $v['ac_id'];
}
unset($v);
}
// 组装返回数据
$this->_result = [
'total' => intval($total),
'limit' => intval($limit),
'page' => intval($page),
'list' => $list
];
return true;
}
}