LikeListController.class.php
2.44 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
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/4/11
* Time: 19:10
*/
namespace Apicp\Controller\News;
use Com\PackageValidate;
use Common\Common\User;
use Common\Service\LikeService;
class LikeListController extends \Apicp\Controller\AbstractController
{
/**
* LikeList
* @desc 点赞列表
* @param int article_id:true 新闻ID
* @return array 点赞列表
* array(
'list' => array( // 点赞列表
'uid' => 'B4B3BAFE7F00000173E870DA83A9751E', // 人员ID
'username' => '张三', // 人员姓名
'face' => 'http://shp.qpic.cn/bizmp/gdZUibR6BHrkuqSjvCzX33qvZpCIOaYZiaFRnciae9WgxiaWXqxkqIOyeg/', // 头像
'created' => 1434567890000, // 点赞时间
),
);
*/
public function Index_post()
{
// 验证规则
$rules = [
'article_id' => 'require|integer',
'page' => 'integer',
'limit' => 'integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 点赞列表
$likeServ = new LikeService();
list($start, $perpage) = page_limit($postData['page'], $postData['limit']);
$likeList = $likeServ->list_by_conds(['article_id' => $postData['article_id']], [$start, $perpage]);
$total = $likeServ->count_by_conds(['article_id' => $postData['article_id']]);
if ($likeList) {
// 人员信息
$uids = array_column($likeList, 'uid');
$userServ = &User::instance();
$userList = $userServ->listAll(['memUids' => $uids]);
$userList = array_combine_by_key($userList, 'memUid');
// 合并头像
if ($userList) {
foreach ($likeList as $k => $v) {
if (isset($userList[$v['uid']])) {
$likeList[$k]['username'] = isset($userList[$v['uid']]) ? $userList[$v['uid']]['memUsername'] : '';
$likeList[$k]['face'] = isset($userList[$v['uid']]) ? $userList[$v['uid']]['memFace'] : '';
}
}
}
}
$this->_result = [
'list' => $likeList,
'total' => $total,
'page' => $postData['page'],
'limit' => $postData['limit']
];
}
}