adminOnly(); } /** * AC1 评价列表 * GET /api/v1/admin/comments 入参 {page,size} * → 分页 {list:[{id,postId,postTitle,user,score,content,images,reply,top,createdAt}],page,size,total,hasMore} */ public function index() { // 闭包重建查询:TP5.0 的 count() 会清空 Query::options,不能复用同一对象 list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) { $q = Db::name('fc_comment')->alias('co') ->join('fc_post p', 'p.id = co.post_id', 'LEFT') ->join('user u', 'u.id = co.user_id', 'LEFT'); if ($forCount) { return $q; } return $q->field('co.*, p.title AS post_title, u.nickname AS nickname') ->order('co.id desc'); }); $list = []; foreach ($rows as $row) { $list[] = [ 'id' => (int)$row['id'], 'postId' => (int)$row['post_id'], 'postTitle' => (string)$row['post_title'], 'user' => (string)$row['nickname'], 'score' => (int)$row['score'], 'content' => (string)$row['content'], 'images' => $this->jsonArr($row['images']), 'reply' => (string)$row['reply'], 'top' => (bool)$row['top'], 'createdAt' => $this->iso($row['createtime']), ]; } $this->ok($this->paginate($list, $total, $page, $size)); } /** * AC2 评价回复 * POST /api/v1/admin/comment/:id/reply 入参 {id?,reply} → {id,reply} */ public function reply() { $id = (int)$this->request->param('id', 0); if (!$id) { $id = (int)$this->input('id', 0); } $reply = trim((string)$this->input('reply', '')); if ($reply === '') { $this->fail('回复内容不能为空'); } $comment = Db::name('fc_comment')->where('id', $id)->find(); if (!$comment) { $this->fail('评价不存在', 404); } Db::name('fc_comment')->where('id', $id)->update([ 'reply' => $reply, 'replytime' => time(), ]); $this->notify($comment['user_id'], 'interact', '评价已回复', '您的评价收到商家回复:' . $reply); $this->adminLog('回复评价 #' . $id); $this->ok(['id' => (int)$id, 'reply' => $reply]); } /** * AC3 举报列表 * GET /api/v1/admin/reports → 数组 [{id,targetType,targetId,reason,reporter,status,createdAt}] */ public function reports() { $rows = Db::name('fc_report')->order('createtime desc')->select(); $list = []; foreach ($rows as $row) { $list[] = [ 'id' => (int)$row['id'], 'targetType' => (string)$row['target_type'], 'targetId' => (int)$row['target_id'], 'reason' => (string)$row['reason'], 'reporter' => (string)$row['reporter_id'], 'status' => (string)$row['status'], 'createdAt' => $this->iso($row['createtime']), ]; } $this->ok($list); } }