alias('c') ->with(['article' => function($query) { $query->field('id,content,topic_id'); }]) ->field('c.*,u.nickname,u.avatar,u.sn') ->join('user u', 'u.id = c.user_id') ->where($where) ->order(['id' => 'desc']) ->append(['status_desc']) ->paginate([ 'page' => $get['page'], 'list_rows' => $get['limit'], 'var_page' => 'page' ]); foreach ($lists as &$item) { $item['avatar'] = !empty($item['avatar']) ? UrlServer::getFileUrl($item['avatar']) : ''; $item['status_desc'] = CommunityCommentEnum::getStatusDesc($item['status']); $item['topic_name'] = $item['article']['topic']['name'] ?? ''; } return ['count' => $lists->total(), 'lists' => $lists->getCollection()]; } /** * @notes 详情 * @param $id * @return array * @author 段誉 * @date 2022/5/10 12:15 */ public static function detail($id) { return CommunityComment::with(['article'])->findOrEmpty($id)->toArray(); } /** * @notes 审核成功 * @param $post * @return CommunityComment * @author 段誉 * @date 2022/5/10 15:11 */ public static function audit($post) { return CommunityComment::where(['id' => $post['id']])->update([ 'status' => $post['status'], 'update_time' => time() ]); } /** * @notes 删除评论 * @param $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/5/10 15:23 */ public static function del($id) { // 删除评论 $comment = CommunityComment::find($id); $comment->del = 1; $comment->update_time = time(); $comment->save(); // 更新文章评论数 CommunityArticle::where([ ['id', '=', $comment['article_id']], ['comment', '>=', 1]] )->dec('comment')->update(); } }