PrizeListController.class.php
2.8 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
<?php
/**
* Created by IntelliJ IDEA.
* 微信端奖品列表
* User: zs_anything
* Date: 2016/12/07
* Time: 上午14:27
*/
namespace Api\Controller\Mall;
use Common\Common\Attach;
use Common\Common\Department;
use Common\Service\PrizeService;
class PrizeListController extends AbstractController
{
public function Index()
{
$page = I('post.page', 1);
$limit = I('post.limit', 10);
list($start, $limit, $page) = page_limit($page, $limit);
$loginUserInfo = $this->_login->user;
$rangeDepStr = $this->__getUserDepartments($loginUserInfo);
$params = array(
'rangeMem' => $loginUserInfo['memUid'],
'rangeDep' => $rangeDepStr
);
$prizeService = new PrizeService();
$data = $prizeService->getWxPrizePageList($params, array($start, $limit));
// 封装图片url
$this->formatAttrUrl($data);
// 格式化库存
$this->formatReserve($data);
$total = $prizeService->countWxPrize($params);
$this->_result = [
'list' => $data,
'page' => $page,
'total' => $total
];
return true;
}
/**
* 获取当前登录用户所属部门, 包括所有上级部门
* @param $loginUserInfo
* @return string
*/
private function __getUserDepartments($loginUserInfo)
{
$departmentUtil = new Department();
$userDepartments = $departmentUtil->list_dpId_by_uid($loginUserInfo['memUid'], true);
$departmentArray = array();
foreach ($userDepartments as $value) {
$departmentArray = array_merge($departmentArray, $value);
}
$rangeDepStr = implode('|', array_unique($departmentArray));
return $rangeDepStr;
}
/**
* 封装奖品图片url
* @param $data
* @return mixed
*/
private function formatAttrUrl(&$data)
{
$attIdArr = [];
foreach ($data as &$item) {
$item['picture'] = explode(',', $item['picture']);
$item['picture'] = $item['picture'][0];
$attIdArr[] = $item['picture'];
}
$attachUtil = new Attach();
$attArr = $attachUtil->listAttachUrl($attIdArr);
foreach ($data as &$item) {
if (isset($attArr[$item['picture']])) {
$item['picture'] = $attArr[$item['picture']]['atAttachment'];
} else {
$item['picture'] = '';
}
}
return $data;
}
/**
* 格式化库存 大于9999 显示9999+
* @param $data
* @return mixed
*/
public function formatReserve(&$data)
{
foreach ($data as &$obj) {
if ($obj['reserve'] > 9999) {
$obj['reserve'] = "9999+";
}
}
return $data;
}
}