PrizeDetailController.class.php
3.48 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Created by IntelliJ IDEA.
* 奖品详情
* User: zhoutao
* Date: 2016-12-06
* Time: 16:48:56
*/
namespace Apicp\Controller\Mall;
use Common\Common\Attach;
use Common\Common\Department;
use Common\Common\User;
use Common\Model\ConvertModel;
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->getWithOutDeleted($this->data['ia_id']);
if (empty($this->_result)) {
return true;
}
// 获取已经兑换的数据
$convertServ = new ConvertService();
$this->_result['exchanged_times'] = $convertServ->count_by_conds([
'ia_id' => $this->data['ia_id'],
'convert_status' => ConvertModel::CONVERT_STATUS_AGREE
]);
// 处理人员部门范围
$this->getArea();
// 处理图片
$this->getPicture();
// 过滤不需要的字段
$this->filterField();
return true;
}
/**
* 过滤不需要的字段
*/
protected function filterField()
{
$field = [
'created',
'updated',
'deleted'
];
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'][] = [
'atId' => $item['atId'],
'atAttachment' => $item['atAttachment']
];
}
return true;
}
/**
* 处理可见范围
* @return bool
*/
protected function getArea()
{
// 获取人员
if (!empty($this->_result['range_mem'])) {
$memServ = new User();
$memberArr = $memServ->listByUid(explode(',', $this->_result['range_mem']));
$this->_result['range_mem'] = [];
foreach ($memberArr as $member) {
$this->_result['range_mem'][] = [
'memUid' => $member['memUid'],
'memFace' => $member['memFace'],
'memUsername' => $member['memUsername'],
];
}
}
// 获取部门
if (!empty($this->_result['range_dep'])) {
$depServ = new Department();
$depArr = $depServ->listById(explode(',', $this->_result['range_dep']));
$this->_result['range_dep'] = [];
foreach ($depArr as $dep) {
$this->_result['range_dep'][] = [
'dpId' => $dep['dpId'],
'dpName' => $dep['dpName'],
];
}
}
return true;
}
}