UserMedalListController.class.php
4.88 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
136
137
138
139
<?php
/**
* Created by IntelliJ IDEA.
* 勋章列表
* User: zhoutao
* Reader: zhoutao 2017-05-31 10:07:35
* Date: 2017-05-24 15:43:49
*/
namespace Apicp\Controller\Medal;
use Com\PackageValidate;
use Common\Common\Attach;
use Common\Common\Constant;
use Common\Common\Integral;
use Common\Common\User;
use Common\Model\MedalLogModel;
use Common\Model\MedalModel;
use Common\Service\MedalLogService;
use Common\Service\MedalService;
use Common\Service\MemberMedalService;
class UserMedalListController extends AbstractController
{
/**
* UserMedalList
* @author tangxingguo
* @desc 列表接口
* @param String uid:true 人员ID
* @param String start_time 开始时间(毫秒级时间戳)
* @param String end_time 结束时间(毫秒级时间戳)
* @param Int get_type 获得类型(1=自主获得;2=手动增加)
* @return Array
array(
'page' => 1, // 当前页
'limit' => 20, // 当前页条数
'total' => 100, // 总条数
'list' => array(
array(
'created' => 122321313123, // 勋章发放时间
'get_type' => 1, // 获得类型(1=自主获得;2=手动增加)
'medal_name' => '学习楷模', // 勋章名称
'icon_type' => 1, // 图标类型(1=用户上传;2=系统图标)用户上传的图标会有icon_url,系统图标前端至icon库查找
'icon' => 'medal03', // 图标
'icon_url' => 'http://baidu.com', // 图标
'ea_name' => '辣鸡', // 操作人
)
)
);
*/
public function index()
{
$rules = [
'uid' => 'require',
'start_time' => 'integer',
'end_time' => 'integer',
'get_type' => 'integer',
'page' => 'integer',
'limit' => 'integer',
];
// 验证请求数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
$uid = $postData['uid'];
// 分页
$page = $postData['page'] ?? Constant::PAGING_DEFAULT_PAGE;
$limit = $postData['limit'] ?? Constant::PAGING_DEFAULT_LIMIT;
list($start, $perpage) = page_limit($page, $limit);
// 条件
$conds = ['mem_uid' => $uid];
if (isset($postData['start_time'])) {
$conds['created >= ?'] = $postData['start_time'];
}
if (isset($postData['end_time'])) {
$conds['created <= ?'] = $postData['end_time'];
}
if (isset($postData['get_type'])) {
$conds['get_type'] = $postData['get_type'];
}
// 排序
$orderOption = ['created' => 'DESC'];
// 勋章发放记录
$medalLogServ = new MedalLogService();
$logList = $medalLogServ->list_by_conds($conds, [$start, $perpage], $orderOption);
// 勋章列表
if (!empty($logList)) {
$medalServ = new MedalService();
$imIds = array_column($logList, 'im_id');
$medalList = $medalServ->list_by_conds(['im_id' => $imIds]);
if (!empty($medalList)) {
$medalList = array_combine_by_key($medalList, 'im_id');
// 获取自定义用户icon连接
foreach ($medalList as $v) {
if ($v['icon_type'] == MedalModel::ICON_TYPE_USER_UPLOAD) {
$customIconIds[] = $v['icon'];
}
}
if (!empty($customIconIds)) {
$attachUtil = new Attach();
$attArrs = $attachUtil->listAttachUrl($customIconIds);
}
}
// 拼接数据
foreach ($logList as &$v) {
$v['get_type'] = MedalLogModel::GET_TYPE_HM == $v['get_type'] ?
MedalLogModel::GET_TYPE_HM : MedalLogModel::GET_TYPE_AUTO;
// 勋章名称
$v['medal_name'] = $medalList[$v['im_id']]['name'] ?? '';
// 图标类型 1: 用户上传 2: 系统图标
if (isset($medalList[$v['im_id']])) {
$v['icon'] = $medalList[$v['im_id']]['icon'];
$v['icon_type'] = $medalList[$v['im_id']]['icon_type'];
}
// 自定义上次拼接附件连接
$v['icon_url'] = $attArrs[$medalList[$v['im_id']]['icon']]['atAttachment'] ?? '';
}
}
$total = $medalLogServ->count_by_conds($conds);
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => $total,
'list' => array_values($logList)
];
return true;
}
}