feat(api): 新增小程序用户端与后台管理端 v1 业务接口(62 端点)
一、基础设施
- 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
这个提交包含在:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 后台管理端 · 会员管理(Module-ADM-MEMBER)
|
||||
* 路由:
|
||||
* GET /api/v1/admin/users AMB1 用户列表
|
||||
* POST /api/v1/admin/member/benefit AMB2 会员权益配置
|
||||
*/
|
||||
class AdminMember extends V1
|
||||
{
|
||||
/**
|
||||
* AMB1 用户列表
|
||||
* GET /api/v1/admin/users 入参 {page,size}
|
||||
* → 分页 {list:[{id,nickname,phone,userType,isMember,status,registerAt}],page,size,total,hasMore}
|
||||
*/
|
||||
public function users()
|
||||
{
|
||||
list($page, $size) = $this->pager();
|
||||
|
||||
$query = Db::name('user')->alias('u')
|
||||
->join('fc_user_ext e', 'e.user_id = u.id', 'LEFT');
|
||||
$total = (int)$query->count();
|
||||
$rows = $query->field('u.id,u.nickname,u.mobile,u.status,u.jointime,e.user_type,e.is_member,e.member_expiretime')
|
||||
->order('u.id desc')
|
||||
->page($page, $size)
|
||||
->select();
|
||||
|
||||
$now = time();
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$isMember = (int)$row['is_member'] === 1
|
||||
&& (!$row['member_expiretime'] || (int)$row['member_expiretime'] > $now);
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'nickname' => (string)$row['nickname'],
|
||||
'phone' => (string)$row['mobile'],
|
||||
'userType' => (int)$row['user_type'],
|
||||
'isMember' => $isMember,
|
||||
'status' => $row['status'] === 'normal' ? 1 : 0,
|
||||
'registerAt' => $this->iso($row['jointime']),
|
||||
];
|
||||
}
|
||||
|
||||
$this->ok($this->paginate($list, $total, $page, $size));
|
||||
}
|
||||
|
||||
/**
|
||||
* AMB2 会员权益配置
|
||||
* POST /api/v1/admin/member/benefit 入参 {freeView,postDiscount,distRate,benefits[]}
|
||||
* → {freeView,postDiscount,distRate,benefits[]}
|
||||
* 未被传入的字段保持原值;freeView <0 报错
|
||||
*/
|
||||
public function saveBenefit()
|
||||
{
|
||||
$current = $this->cfg('member.benefit', []);
|
||||
if (!is_array($current)) {
|
||||
$current = [];
|
||||
}
|
||||
|
||||
$freeView = $this->input('freeView', null);
|
||||
if ($freeView !== null && $freeView !== '') {
|
||||
if ((int)$freeView < 0) {
|
||||
$this->fail('免费查看条数不能为负');
|
||||
}
|
||||
$current['freeView'] = (int)$freeView;
|
||||
}
|
||||
|
||||
$postDiscount = $this->input('postDiscount', null);
|
||||
if ($postDiscount !== null && $postDiscount !== '') {
|
||||
$current['postDiscount'] = (string)$postDiscount;
|
||||
}
|
||||
|
||||
$distRate = $this->input('distRate', null);
|
||||
if ($distRate !== null && $distRate !== '') {
|
||||
$current['distRate'] = (string)$distRate;
|
||||
}
|
||||
|
||||
$benefits = $this->input('benefits', null);
|
||||
if ($benefits !== null && $benefits !== '') {
|
||||
if (is_array($benefits)) {
|
||||
$current['benefits'] = array_values($benefits);
|
||||
} else {
|
||||
$decoded = json_decode((string)$benefits, true);
|
||||
$current['benefits'] = is_array($decoded) ? $decoded : [(string)$benefits];
|
||||
}
|
||||
}
|
||||
|
||||
$defaults = [
|
||||
'freeView' => 20,
|
||||
'postDiscount' => '8 折',
|
||||
'distRate' => '一级 20% / 二级 10%',
|
||||
'benefits' => [],
|
||||
];
|
||||
$current = array_merge($defaults, $current);
|
||||
|
||||
$this->setCfg('member.benefit', $current);
|
||||
$this->adminLog('修改会员权益配置');
|
||||
|
||||
$this->ok([
|
||||
'freeView' => (int)$current['freeView'],
|
||||
'postDiscount' => (string)$current['postDiscount'],
|
||||
'distRate' => (string)$current['distRate'],
|
||||
'benefits' => array_values((array)$current['benefits']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户