fix(api): 修复 TP5.0 查询构造器复用与数组入参两处系统性缺陷
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 必填校验断言按 分类→标题→内容 顺序修正
这个提交包含在:
@@ -133,20 +133,31 @@ class V1 extends Api
|
||||
|
||||
/* ==================== 入参 ==================== */
|
||||
|
||||
/** 读取单个入参(POST 优先,其次 GET) */
|
||||
/**
|
||||
* 读取单个入参(POST 优先,其次 GET)
|
||||
*
|
||||
* 注意:不能使用 $this->request->post($key) —— TP5.0 的 Request::input() 在参数名
|
||||
* 不含 '/' 时会按字符串强转,若值本身是数组(如 media[]/benefits[]/icons)
|
||||
* 会抛 InvalidArgumentException('variable type error:array')。
|
||||
* 这里改用 post(false)/get(false) 取原始数组,天然支持数组与 JSON 请求体。
|
||||
*/
|
||||
protected function input($key, $default = null)
|
||||
{
|
||||
$val = $this->request->post($key, null);
|
||||
if ($val === null || $val === '') {
|
||||
$val = $this->request->get($key, $default);
|
||||
$raw = array_merge((array)$this->request->get(false), (array)$this->request->post(false));
|
||||
if (!array_key_exists($key, $raw)) {
|
||||
return $default;
|
||||
}
|
||||
return $val === null ? $default : $val;
|
||||
$val = $raw[$key];
|
||||
if ($val === '' || $val === null) {
|
||||
return $default;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/** 全部入参 */
|
||||
/** 全部入参(数组安全) */
|
||||
protected function inputs()
|
||||
{
|
||||
return array_merge((array)$this->request->get(), (array)$this->request->post());
|
||||
return array_merge((array)$this->request->get(false), (array)$this->request->post(false));
|
||||
}
|
||||
|
||||
/** 必填校验,失败直接返回业务错误 */
|
||||
@@ -204,6 +215,31 @@ class V1 extends Api
|
||||
return $this->paginate(array_slice($items, ($page - 1) * $size, $size), $total, $page, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用「数据库分页查询」(正确处理 TP5.0 的查询构造器复用陷阱)
|
||||
*
|
||||
* 注意:TP5.0 的 count() 内部会执行 $this->options = [],
|
||||
* 因此**绝不能**复用同一个 Query 对象先 count() 再 select(),
|
||||
* 否则 alias / join / where 全部丢失(表现为 SQL 报错或筛选失效)。
|
||||
*
|
||||
* 用法:
|
||||
* list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($x) {
|
||||
* $q = Db::name('fc_xxx')->alias('t')->join('...')->where(...);
|
||||
* return $forCount ? $q : $q->field('...')->order('...');
|
||||
* });
|
||||
*
|
||||
* @param callable $builder function(bool $forCount): \think\db\Query
|
||||
* @param int $defaultSize
|
||||
* @return array [rows, total, page, size]
|
||||
*/
|
||||
protected function pageQuery(callable $builder, $defaultSize = 10)
|
||||
{
|
||||
list($page, $size) = $this->pager($defaultSize);
|
||||
$total = (int)$builder(true)->count();
|
||||
$rows = $builder(false)->page($page, $size)->select();
|
||||
return [$rows, $total, $page, $size];
|
||||
}
|
||||
|
||||
/* ==================== 业务配置(fa_fc_config) ==================== */
|
||||
|
||||
/**
|
||||
|
||||
在新工单中引用
屏蔽一个用户