一、基础设施
- 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
121 行
4.2 KiB
PHP
121 行
4.2 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Db;
|
||
|
||
/**
|
||
* 后台管理端 · 信息审核(Module-ADM-AUDIT)
|
||
* 路由:
|
||
* GET /api/v1/admin/posts/pending AP1 待审核信息列表
|
||
* POST /api/v1/admin/post/:id/audit AP2 信息审核(通过/驳回)
|
||
* POST /api/v1/admin/post/:id/offline AP3 信息下架
|
||
*/
|
||
class AdminPost extends V1
|
||
{
|
||
/**
|
||
* AP1 待审核信息列表
|
||
* GET /api/v1/admin/posts/pending 入参 {page,size}
|
||
* → 分页 {list:[{id,title,categoryId,categoryName,userId,userName,area,price,priceUnit,createdAt,isPaid,content}],page,size,total,hasMore}
|
||
* 条件:audit_status=0 且未删除(deletetime is null),按 createtime 升序
|
||
*/
|
||
public function pending()
|
||
{
|
||
list($page, $size) = $this->pager();
|
||
|
||
$query = Db::name('fc_post')->alias('p')
|
||
->join('fc_category c', 'c.id = p.category_id', 'LEFT')
|
||
->join('user u', 'u.id = p.user_id', 'LEFT')
|
||
->where('p.audit_status', 0)
|
||
->whereNull('p.deletetime');
|
||
|
||
$total = $query->count();
|
||
$rows = $query->field('p.*, c.name AS category_name, u.nickname AS user_name')
|
||
->order('p.createtime asc')
|
||
->page($page, $size)
|
||
->select();
|
||
|
||
$list = [];
|
||
foreach ($rows as $row) {
|
||
$list[] = [
|
||
'id' => (int)$row['id'],
|
||
'title' => (string)$row['title'],
|
||
'categoryId' => (int)$row['category_id'],
|
||
'categoryName' => (string)$row['category_name'],
|
||
'userId' => (int)$row['user_id'],
|
||
'userName' => (string)$row['user_name'],
|
||
'area' => (string)$row['area'],
|
||
'price' => (float)$row['price'],
|
||
'priceUnit' => (string)$row['price_unit'],
|
||
'createdAt' => $this->iso($row['createtime']),
|
||
'isPaid' => (bool)$row['is_paid'],
|
||
'content' => (string)$row['content'],
|
||
];
|
||
}
|
||
|
||
$this->ok($this->paginate($list, $total, $page, $size));
|
||
}
|
||
|
||
/**
|
||
* AP2 信息审核
|
||
* POST /api/v1/admin/post/:id/audit 入参 {auditStatus,reason?} → {id,auditStatus}
|
||
* 规则 BR-11:auditStatus 仅允许 1(通过)/2(驳回)
|
||
*/
|
||
public function audit()
|
||
{
|
||
$id = (int)$this->request->param('id', 0);
|
||
$auditStatus = (int)$this->input('auditStatus', 0);
|
||
$reason = trim((string)$this->input('reason', ''));
|
||
|
||
if (!in_array($auditStatus, [1, 2], true)) {
|
||
$this->fail('审核状态仅支持通过(1)/驳回(2)');
|
||
}
|
||
|
||
$post = Db::name('fc_post')->where('id', $id)->find();
|
||
if (!$post) {
|
||
$this->fail('信息不存在', 404);
|
||
}
|
||
|
||
Db::name('fc_post')->where('id', $id)->update([
|
||
'audit_status' => $auditStatus,
|
||
'audit_reason' => $reason,
|
||
'updatetime' => time(),
|
||
]);
|
||
|
||
if ($auditStatus === 1) {
|
||
Db::name('fc_category')->where('id', $post['category_id'])->setInc('post_count');
|
||
$this->notify($post['user_id'], 'system', '审核通过', '您发布的信息「' . $post['title'] . '」已审核通过。');
|
||
} else {
|
||
$this->notify($post['user_id'], 'system', '审核驳回', '您发布的信息「' . $post['title'] . '」被驳回:' . $reason);
|
||
}
|
||
|
||
$this->adminLog('审核信息 #' . $id . ' 结果' . $auditStatus);
|
||
|
||
$this->ok(['id' => (int)$id, 'auditStatus' => (int)$auditStatus]);
|
||
}
|
||
|
||
/**
|
||
* AP3 信息下架
|
||
* POST /api/v1/admin/post/:id/offline → {id,offline}
|
||
*/
|
||
public function offline()
|
||
{
|
||
$id = (int)$this->request->param('id', 0);
|
||
|
||
$post = Db::name('fc_post')->where('id', $id)->find();
|
||
if (!$post) {
|
||
$this->fail('信息不存在', 404);
|
||
}
|
||
|
||
Db::name('fc_post')->where('id', $id)->update([
|
||
'status' => 0,
|
||
'updatetime' => time(),
|
||
]);
|
||
|
||
$this->notify($post['user_id'], 'system', '信息已下架', '您发布的信息「' . $post['title'] . '」已被下架。');
|
||
$this->adminLog('下架信息 #' . $id);
|
||
|
||
$this->ok(['id' => (int)$id, 'offline' => true]);
|
||
}
|
||
}
|