1) count() 后复用同一 Query 会清空 options,导致 alias/join/where 丢失 (SQL 报错 Unknown column/table,或筛选静默失效) → 基类新增 pageQuery(callable) 助手,8 个分页接口全部改用闭包重建查询 2) TP5.0 Request::input() 对不含 / 的参数名做字符串强转,值若为数组会抛 variable type error:array(影响 media[]/benefits[]/permissions[]/icons) → 基类 input()/inputs() 改用 post(false)/get(false) 取原始数组 3) 种子数据:佣金调整为 settled 336.4 / 未结算 950,使可提现余额 = 186.4(与前端 mock 对齐) 4) 测试脚本:P1 必填校验断言按 分类→标题→内容 顺序修正
72 行
2.1 KiB
PHP
72 行
2.1 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'];
|
||
$type = $this->input('type', '');
|
||
|
||
// 闭包重建查询:TP5.0 的 count() 会清空 Query::options,不能复用同一对象
|
||
list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($uid, $type) {
|
||
$q = Db::name('fc_message')->where('user_id', 'in', [$uid, 0]);
|
||
if ($type !== '' && $type !== null) {
|
||
$q->where('type', $type);
|
||
}
|
||
if ($forCount) {
|
||
return $q;
|
||
}
|
||
return $q->order('createtime desc');
|
||
});
|
||
|
||
$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]);
|
||
}
|
||
}
|