feat(api): 新增小程序用户端与后台管理端 v1 业务接口(62 端点)
一、基础设施
- route.php:58 条路由覆盖 /api/v1/**;:id 用 \d+ 约束、长路径优先
- api/controller/V1.php:响应适配为 {code,message,data}(FastAdmin 原生 {code,msg,time,data} 不兼容);
Authorization Bearer 鉴权;统一分页;业务公共 userInfo/ext/flow/notify/adminLog
- admin/command/FcInstall.php:19 张 fa_fc_* 表 + 种子数据,幂等可重跑
二、控制器 17 个
- 用户端 Auth/Home/Post/Member/Distribution/Message/Setting
- 后台端 AdminDashboard/AdminMerchant/AdminMember/AdminPost/AdminComment/
AdminDist/AdminOrder/AdminFinance/AdminRbac/AdminSetting
三、契约一致性
- 字段与小程序 common/mock/data.js 逐字段对齐,Mock 与真实接口可对拍
- 实现 BR-01~BR-12,错误文案与前端 mock 完全一致
- 详情联系方式强制脱敏,付费/会员方可解锁
四、验证
- tools/verify-api.mjs:63 端点契约 + 12 条业务规则 + 8 步双端闭环
- docs/05-后端实现规范.md
这个提交包含在:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 后台管理端 · 评价管理(Module-ADM-COMMENT)
|
||||
* 路由:
|
||||
* GET /api/v1/admin/comments AC1 评价列表
|
||||
* POST /api/v1/admin/comment/:id/reply AC2 评价回复
|
||||
* GET /api/v1/admin/reports AC3 举报列表
|
||||
*/
|
||||
class AdminComment extends V1
|
||||
{
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
list($page, $size) = $this->pager();
|
||||
|
||||
$query = 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');
|
||||
|
||||
$total = $query->count();
|
||||
$rows = $query->field('co.*, p.title AS post_title, u.nickname AS nickname')
|
||||
->order('co.id desc')
|
||||
->page($page, $size)
|
||||
->select();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户