文件
fenleixinxi/application/api/controller/AdminMerchant.php
linda 11174f8693 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 必填校验断言按 分类→标题→内容 顺序修正
2026-10-15 14:56:06 +08:00

103 行
3.7 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\api\controller;
use think\Db;
/**
* 后台管理端 · 商家管理(Module-ADM-MERCHANT)
* 路由:
* GET /api/v1/admin/merchants AM1 商家列表
* POST /api/v1/admin/merchant/:id/audit AM2 商家资质审核
*/
class AdminMerchant extends V1
{
/**
* AM1 商家列表
* GET /api/v1/admin/merchants 入参 {status?,keyword?,page,size}
* → 分页 {list:[{id,name,logo,contact,category,auditStatus,license,shopStatus,violations,postCount,createdAt}],page,size,total,hasMore}
* 注意:id 返回 fc_merchant.user_id(与前端商家列表一致)
*/
public function index()
{
$status = $this->input('status', '');
$keyword = trim((string)$this->input('keyword', ''));
// 闭包重建查询:TP5.0 的 count() 会清空 Query::options,不能复用同一对象
list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($status, $keyword) {
$q = Db::name('fc_merchant');
if ($status !== '' && $status !== null) {
$q->where('audit_status', (int)$status);
}
if ($keyword !== '') {
$q->where('name', 'like', '%' . $keyword . '%');
}
if ($forCount) {
return $q;
}
return $q->order('id desc');
});
$list = [];
foreach ($rows as $row) {
$list[] = [
'id' => (int)$row['user_id'],
'name' => (string)$row['name'],
'logo' => (string)$row['logo'],
'contact' => (string)$row['contact'],
'category' => (string)$row['category'],
'auditStatus' => (int)$row['audit_status'],
'license' => (string)$row['license'],
'shopStatus' => (string)$row['shop_status'],
'violations' => (int)$row['violations'],
'postCount' => (int)$row['post_count'],
'createdAt' => $this->iso($row['createtime']),
];
}
$this->ok($this->paginate($list, $total, $page, $size));
}
/**
* AM2 商家资质审核
* POST /api/v1/admin/merchant/: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)');
}
$merchant = Db::name('fc_merchant')->where('user_id', $id)->find();
if (!$merchant) {
$this->fail('商家不存在', 404);
}
Db::name('fc_merchant')->where('user_id', $id)->update([
'audit_status' => $auditStatus,
'audit_reason' => $reason,
'shop_status' => $auditStatus === 1 ? 'normal' : 'banned',
'updatetime' => time(),
]);
if ($auditStatus === 1) {
Db::name('fc_user_ext')->where('user_id', $id)->update([
'user_type' => 2,
'updatetime' => time(),
]);
$this->notify($id, 'system', '商家资质审核结果', '恭喜,您的商家资质已通过审核。');
} else {
$this->notify($id, 'system', '商家资质审核结果', '您的商家资质未通过:' . $reason);
}
$this->adminLog('审核商家 #' . $id . ' 结果' . $auditStatus);
$this->ok(['id' => $id, 'auditStatus' => $auditStatus]);
}
}