一、基础设施
- 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
68 行
1.9 KiB
PHP
68 行
1.9 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Db;
|
||
|
||
/**
|
||
* 用户端 · 消息中心(Module-MESSAGE)
|
||
* 路由:
|
||
* GET /api/v1/message/list M1 消息列表
|
||
* POST /api/v1/message/:id/read M2 标记已读
|
||
*
|
||
* 说明:user_id=0 表示全体广播消息,用户可见。
|
||
*/
|
||
class Message extends V1
|
||
{
|
||
/**
|
||
* M1 消息列表
|
||
* GET /api/v1/message/list 入参 {type?,page,size}
|
||
* → 分页 {list:[{id,type,title,content,read,createdAt}],page,size,total,hasMore}
|
||
*/
|
||
public function list()
|
||
{
|
||
$user = $this->auth();
|
||
$uid = (int)$user['id'];
|
||
list($page, $size) = $this->pager();
|
||
$type = $this->input('type', '');
|
||
|
||
$query = Db::name('fc_message')->where('user_id', 'in', [$uid, 0]);
|
||
if ($type !== '' && $type !== null) {
|
||
$query->where('type', $type);
|
||
}
|
||
$total = $query->count();
|
||
$rows = $query->order('createtime desc')->page($page, $size)->select();
|
||
|
||
$list = [];
|
||
foreach ($rows as $row) {
|
||
$list[] = [
|
||
'id' => (int)$row['id'],
|
||
'type' => (string)$row['type'],
|
||
'title' => (string)$row['title'],
|
||
'content' => (string)$row['content'],
|
||
'read' => (bool)(int)$row['isread'],
|
||
'createdAt' => $this->iso($row['createtime']),
|
||
];
|
||
}
|
||
|
||
$this->ok($this->paginate($list, $total, $page, $size));
|
||
}
|
||
|
||
/**
|
||
* M2 标记已读
|
||
* POST /api/v1/message/:id/read → {read:true}
|
||
*/
|
||
public function read()
|
||
{
|
||
$user = $this->auth();
|
||
$uid = (int)$user['id'];
|
||
$id = (int)$this->request->param('id', 0);
|
||
|
||
Db::name('fc_message')->where('id', $id)
|
||
->where('user_id', 'in', [$uid, 0])
|
||
->update(['isread' => 1, 'readtime' => time()]);
|
||
|
||
$this->ok(['read' => true]);
|
||
}
|
||
}
|