52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\lists\community;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\community\CommunityComment;
|
|
use app\common\model\community\CommunityPost;
|
|
use app\common\model\user\User;
|
|
|
|
class CommunityCommentLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['post_id', 'user_id', 'status'],
|
|
];
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
$lists = CommunityComment::where($this->searchWhere)
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order('id', 'desc')
|
|
->select()
|
|
->toArray();
|
|
|
|
$userIds = array_unique(array_column($lists, 'user_id'));
|
|
$users = User::whereIn('id', $userIds)->column('nickname,avatar', 'id');
|
|
|
|
$postIds = array_unique(array_column($lists, 'post_id'));
|
|
$posts = CommunityPost::whereIn('id', $postIds)->column('content,user_id', 'id');
|
|
|
|
foreach ($lists as &$item) {
|
|
$user = $users[$item['user_id']] ?? [];
|
|
$item['nickname'] = $user['nickname'] ?? '-';
|
|
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
|
|
$post = $posts[$item['post_id']] ?? [];
|
|
$item['post_content'] = isset($post['content']) ? mb_substr($post['content'], 0, 50) : '-';
|
|
$postUser = !empty($post['user_id']) ? (User::field('nickname')->findOrEmpty($post['user_id'])->toArray()) : [];
|
|
$item['post_nickname'] = $postUser['nickname'] ?? '-';
|
|
}
|
|
|
|
return $lists;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return CommunityComment::where($this->searchWhere)->count();
|
|
}
|
|
}
|