InfoController.class.php
3.23 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
<?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;
use VcySDK\Integral;
use VcySDK\Service;
class InfoController extends \Api\Controller\AbstractController
{
/** @var ActivityService */
protected $_activity_service;
/** @var RightService */
protected $_right_service;
/** @var PrizeService */
protected $_prize_service;
/** @var RecordService */
protected $_record_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化活动
$this->_activity_service = new ActivityService();
// 实例化权限表
$this->_right_service = new RightService();
// 实例化商品表
$this->_prize_service = new PrizeService();
// 实例抽奖记录表
$this->_record_service = new RecordService();
return true;
}
/**
* @return bool
*/
public function Index_get()
{
$params = I('get.');
// 获取参数
$ac_id = $params['ac_id'] ? intval($params['ac_id']) : 0;
if (empty($ac_id)) {
// 验证参数
E('_EMPTY_ACTIVITY_ID');
}
// 获取活动详细内容
$info = $this->_activity_service->get_by_conds(
[
'ac_id' => $ac_id,
'activity_status > ?' => 0
]
);
if (empty($info)) {
// 数据不存在时抛错
E('_ERR_DATA_NOT_EXIST');
}
// 活动状态
$status = $this->_prize_service->activity_status($info['activity_status'], $info['start_time'], $info['end_time']);
// 获取奖品列表
$prize_list = $this->_prize_service->get_prize_list(['ac_id' => $ac_id], 'lp_id,name,is_prize,cover_id', ['order_num' => 'ASC']);
// 如果不是全公司
if (Constant::IS_ALL_FALSE == $info['is_all']) {
// 获取用户权限ID
$ids = $this->_right_service->getUserRight($this->_login->user);
sort($ids);
// 统计用户是否有权限
$total = $this->_right_service->count_by_conds(['ac_id' => $ac_id, 'obj_id' => $ids]);
// 如果没有权限
if (empty($total)) {
E('_ERR_ACTIVITY_NOT_AUTH');
}
}
// 获取当前用户积分
$sdk = new Integral(Service::instance());
$integral_info = $sdk->detail(['memUid' => $this->uid]);
// 格式化详情数据
$this->_result = [
'status' => $status,
'title' => $info['title'],
'available' => $integral_info['available'],
'integral' => $info['integral'],
'prize_intro' => $info['prize_intro'] ? unserialize($info['prize_intro']) : '',
'rule' => $info['rule'] ? unserialize($info['rule']) : '',
'remark' => $info['remark'],
'list' => $prize_list
];
return true;
}
}