DrawListController.class.php
2.72 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
<?php
/**
* 【积分抽奖-手机端】获取中奖列表接口
*
* @author: heyuelong
* @date: 2018年3月26日11:18:11
*/
namespace Api\Controller\Activity;
use Common\Common\Constant;
use Common\Service\ActivityService;
use Common\Service\PrizeService;
use Common\Service\RecordService;
use Common\Service\RightService;
class DrawListController extends \Api\Controller\AbstractController
{
/** @var ActivityService */
protected $_activity_service;
/** @var RecordService */
protected $_record_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化活动
$this->_activity_service = new ActivityService();
// 实例化权限表
$this->_record_service = new RecordService();
return true;
}
/**
* @return bool
*/
public function Index_post()
{
$postData = I('post.');
if (empty($postData['ac_id'])) {
// 验证参数
E('_EMPTY_ACTIVITY_ID');
}
// 分页默认值
$postData['page'] = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$postData['limit'] = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
list($start, $perpage) = page_limit($postData['page'], $postData['limit']);
$conds = [
'is_prize' => Constant::HAVE_PRIZE,
'ac_id' => $postData['ac_id'],
'uid' => $this->uid
];
// 获取中奖列表数
$total = $this->_record_service->count_by_conds($conds);
// 获取多个活动详情
$activity = $this->_activity_service->get_by_conds(['ac_id' => $postData['ac_id']]);
// 如果有数据
if (!empty($total)) {
$fields = 'ac_id,lr_id,lp_name,remark,created,cover_id';
$record_list = $this->_record_service->list_by_conds($conds, [$start, $perpage], ['lr_id' => 'DESC'], $fields);
$status = empty($activity) ? 1 : 0;
// 遍历中奖纪录
foreach ($record_list as &$value) {
// 统计是否被删除状态 如果被删除展示0否则展示1
$value['status'] = $status;
// 获取奖品图片地址
$value['img_url'] = imgUrlReal($value['cover_id']);
}
}
$this->_result = [
'info_remark' => $activity['remark'],
'page' => $postData['page'],
'limit' => $postData['limit'],
'total' => isset($total) ? intval($total) : 0,
'list' => isset($record_list) ? $record_list : [],
];
return true;
}
}