PrizeDetailController.class.php
2.83 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
<?php
/**
* Created by IntelliJ IDEA.
* 奖品详情
* User: zhoutao
* Date: 2016/12/07
* Time: 上午14:27
*/
namespace Api\Controller\Mall;
use Common\Common\Attach;
use Common\Model\ConvertModel;
use Common\Model\PrizeModel;
use Common\Service\ConvertService;
use Common\Service\PrizeService;
class PrizeDetailController extends AbstractController
{
public function before_action($action = '')
{
// 开启自动获取
$this->autoGetData = true;
$this->field = [
'ia_id' => [
'require' => true,
'verify' => 'intval',
'cn' => '奖品ID',
],
];
return parent::before_action($action);
}
public function Index()
{
// 获取奖品数据
$prizeServ = new PrizeService();
$this->_result = $prizeServ->get($this->data['ia_id']);
// 已删除
if (empty($this->_result)) {
E('_ERR_PRIZE_CONVERT_IS_DELETED');
return false;
}
// 已下架
if ($this->_result['on_sale'] == PrizeModel::OFF_SALE) {
E('_ERR_PRIZE_CONVERT_IS_OFFSALE');
return false;
}
// 可见范围
if (!$this->verifyArea($this->_result)) {
E('_ERR_PRIZE_CONVERT_NOT_IN_AREA');
return false;
};
// 获取已经兑换的数据
$convertServ = new ConvertService();
$this->_result['exchanged_times'] = $convertServ->count_by_conds([
'ia_id' => $this->data['ia_id'],
'uid' => $this->uid,
'convert_status' => [
ConvertModel::CONVERT_STATUS_AGREE,
ConvertModel::CONVERT_STATUS_ING
]
]);
// 处理图片
$this->getPicture();
// 过滤不需要的字段
$this->filterField();
return true;
}
/**
* 过滤不需要的字段
*/
protected function filterField()
{
$field = [
'status',
'created',
'updated',
'deleted',
'range_mem',
'range_dep',
'domain',
'is_all',
'ia_id',
'sequence'
];
foreach ($field as $key) {
unset($this->_result[$key]);
}
return true;
}
/**
* 处理图片
* @return bool
*/
protected function getPicture()
{
// 获取图片地址
$attServ = new Attach();
$this->_result['picture'] = explode(',', $this->_result['picture']);
$attArr = $attServ->listAttachUrl($this->_result['picture']);
// 重构图片数据结构
$this->_result['picture'] = [];
foreach ($attArr as $item) {
$this->_result['picture'][] = $item['atAttachment'];
}
return true;
}
}