ListController.class.php
2.96 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
<?php
/**
* 查询顶级评论列表接口
* 鲜彤 2016-08-05 15:40:23
*/
namespace Api\Controller\Comment;
use Common\Common\Comment;
use Common\Common\Constant;
use Common\Common\User;
class ListController extends AbstractController
{
public function Index()
{
// 评论对象ID
$cmtObjid = I('post.cmtObjid');
// 子评论的页大小 默认5 最大1000
$childPageSize = I('post.childPageSize');
$page = I('post.page'); // 当前页码
$perpage = I('post.limit'); // 页大小 默认30 最大200
// 评论对象id不能为空
if (! $cmtObjid) {
$this->_set_error("_ERR_EMPTY_CMTOBJ_ID");
return false;
}
// 排序规则(倒序)
$orderList = [[
'column' => 'cmtCreated',
'orderType' => 'desc',
]];
// 组织查询条件
$condition = array(
"cmtObjid" => $cmtObjid,
"childPageSize" => $childPageSize,
"memUid" => $this->_login->user['memUid'],
'orderList' => $orderList,
);
// 搜索评论列表
$result = Comment::instance()->listAll($condition, '', $page, $perpage);
if (!empty($result['list'])) {
// 用户UID集合
$uids = array_column($result['list'], 'memUid');
$userClass = User::instance();
$userData = $userClass->listByUid($uids);
// 循环列表,添加是否允许删除
foreach ($result['list'] as &$_comment) {
$_comment['allow_delete'] = $_comment['memUid'] == $this->_login->user['memUid'] ? 1 : 0;
$_comment['user_sex'] = $userData[$_comment['memUid']] ? $userData[$_comment['memUid']]['memGender'] : 0;
// 匿名时,隐藏用户姓名和图像
if (isset($_comment['cmtAnonymous']) && Constant::ANONYMOUS_OK == $_comment['cmtAnonymous']) {
$_comment['memUsername'] = '';
$_comment['memFace'] = '';
}
foreach ($_comment['childComentList'] as &$_childComment) {
$_childComment['allow_delete'] = $_childComment['memUid'] == $this->_login->user['memUid'] ? 1 : 0;
}
}
}
// 返回数据
$this->_result = array(
"page" => $result['pageNum'],
"limit" => $result['pageSize'],
"total" => $result['total'],
"cmttlNums" => $result['cmttlNums'],
"cmttlLikes" => $result['cmttlLikes'],
"cmttlObjLikes" => $result['cmttlObjLikes'],
"memUidCmtObjLikeState" => $result['memUidCmtObjLikeState'],
"memUidLikeList" => $result['memUidLikeList'],
"childPageNum" => $result['childPageNum'],
"childPageSize" => $result['childPageSize'],
"childTotal" => $result['childTotal'],
"list" => $result['list']
);
return true;
}
}