一、基础设施
- 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
99 行
3.5 KiB
PHP
99 行
3.5 KiB
PHP
<?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()
|
||
{
|
||
list($page, $size) = $this->pager();
|
||
$status = $this->input('status', '');
|
||
$keyword = trim((string)$this->input('keyword', ''));
|
||
|
||
$query = Db::name('fc_merchant');
|
||
if ($status !== '' && $status !== null) {
|
||
$query->where('audit_status', (int)$status);
|
||
}
|
||
if ($keyword !== '') {
|
||
$query->where('name', 'like', '%' . $keyword . '%');
|
||
}
|
||
$total = $query->count();
|
||
$rows = $query->order('id desc')->page($page, $size)->select();
|
||
|
||
$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]);
|
||
}
|
||
}
|