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,141 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 后台管理端 · 分销管理(Module-ADM-DIST)
|
||||
* 路由:
|
||||
* GET /api/v1/admin/dist/setting AD1 分销设置读取
|
||||
* POST /api/v1/admin/dist/setting AD2 分销设置保存
|
||||
* GET /api/v1/admin/dist/withdraws AD3 提现申请列表
|
||||
* POST /api/v1/admin/dist/withdraw/:id/pay AD4 提现审核(打款/驳回)
|
||||
*/
|
||||
class AdminDist extends V1
|
||||
{
|
||||
/**
|
||||
* AD1 分销设置读取
|
||||
* GET /api/v1/admin/dist/setting → {enabled,level,level1Rate,level2Rate,settleCycle,minWithdraw}
|
||||
*/
|
||||
public function setting()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->saveSetting();
|
||||
}
|
||||
$this->ok($this->distConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* AD2 分销设置保存
|
||||
* POST /api/v1/admin/dist/setting 入参 {enabled,level,level1Rate,level2Rate,settleCycle,minWithdraw}
|
||||
* 规则 BR-08:一级+二级分佣比例不能超过 100%
|
||||
*/
|
||||
public function saveSetting()
|
||||
{
|
||||
$enabled = $this->input('enabled', $this->cfg('dist.enabled', 1));
|
||||
$level = (int)$this->input('level', $this->cfg('dist.level', 2));
|
||||
$level1Rate = (float)$this->input('level1Rate', $this->cfg('dist.level1Rate', 20));
|
||||
$level2Rate = (float)$this->input('level2Rate', $this->cfg('dist.level2Rate', 10));
|
||||
$settleCycle = (string)$this->input('settleCycle', $this->cfg('dist.settleCycle', 'T+7'));
|
||||
$minWithdraw = (float)$this->input('minWithdraw', $this->cfg('dist.minWithdraw', 50));
|
||||
|
||||
if ($level1Rate + $level2Rate > 100) {
|
||||
$this->fail('一级+二级分佣比例不能超过 100%');
|
||||
}
|
||||
|
||||
$this->setCfg('dist.enabled', $enabled ? 1 : 0);
|
||||
$this->setCfg('dist.level', $level);
|
||||
$this->setCfg('dist.level1Rate', $level1Rate);
|
||||
$this->setCfg('dist.level2Rate', $level2Rate);
|
||||
$this->setCfg('dist.settleCycle', $settleCycle);
|
||||
$this->setCfg('dist.minWithdraw', $minWithdraw);
|
||||
|
||||
$this->adminLog('修改分销设置');
|
||||
|
||||
$this->ok($this->distConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* AD3 提现申请列表
|
||||
* GET /api/v1/admin/dist/withdraws → 数组 [{id,withdrawNo,user,amount,status,channel,createdAt}]
|
||||
*/
|
||||
public function withdraws()
|
||||
{
|
||||
$rows = Db::name('fc_withdraw')->alias('w')
|
||||
->join('user u', 'u.id = w.user_id', 'LEFT')
|
||||
->field('w.*, u.nickname AS nickname')
|
||||
->order('w.createtime desc')
|
||||
->select();
|
||||
|
||||
$list = [];
|
||||
foreach ($rows as $row) {
|
||||
$list[] = [
|
||||
'id' => (int)$row['id'],
|
||||
'withdrawNo' => (string)$row['withdraw_no'],
|
||||
'user' => (string)$row['nickname'],
|
||||
'amount' => (float)$row['amount'],
|
||||
'status' => (string)$row['status'],
|
||||
'channel' => (string)$row['channel'],
|
||||
'createdAt' => $this->iso($row['createtime']),
|
||||
];
|
||||
}
|
||||
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* AD4 提现审核
|
||||
* POST /api/v1/admin/dist/withdraw/:id/pay 入参 {op,reason?} → {id,status}
|
||||
* 规则 BR-09:op=reject 时 reason 必填
|
||||
*/
|
||||
public function handleWithdraw()
|
||||
{
|
||||
$id = (int)$this->request->param('id', 0);
|
||||
$op = (string)$this->input('op', '');
|
||||
$reason = trim((string)$this->input('reason', ''));
|
||||
|
||||
if ($op === 'reject' && $reason === '') {
|
||||
$this->fail('驳回需填写原因');
|
||||
}
|
||||
|
||||
$withdraw = Db::name('fc_withdraw')->where('id', $id)->find();
|
||||
if (!$withdraw) {
|
||||
$this->fail('提现记录不存在', 404);
|
||||
}
|
||||
|
||||
if ($op === 'reject') {
|
||||
$status = 'rejected';
|
||||
Db::name('fc_withdraw')->where('id', $id)->update([
|
||||
'status' => $status,
|
||||
'reason' => $reason,
|
||||
]);
|
||||
$this->notify($withdraw['user_id'], 'system', '提现被驳回', '您的提现申请被驳回:' . $reason);
|
||||
} else {
|
||||
$status = 'paid';
|
||||
Db::name('fc_withdraw')->where('id', $id)->update([
|
||||
'status' => $status,
|
||||
'paytime' => time(),
|
||||
]);
|
||||
$this->flow('expense', '佣金提现', $withdraw['amount'], 0, $id);
|
||||
$this->notify($withdraw['user_id'], 'system', '提现已打款', '您的提现申请已打款,请注意查收。');
|
||||
}
|
||||
|
||||
$this->adminLog('处理提现 #' . $id . ' 结果' . $status);
|
||||
|
||||
$this->ok(['id' => (int)$id, 'status' => $status]);
|
||||
}
|
||||
|
||||
/** 组装分销设置结构 */
|
||||
protected function distConfig()
|
||||
{
|
||||
return [
|
||||
'enabled' => (bool)$this->cfg('dist.enabled', 1),
|
||||
'level' => (int)$this->cfg('dist.level', 2),
|
||||
'level1Rate' => (float)$this->cfg('dist.level1Rate', 20),
|
||||
'level2Rate' => (float)$this->cfg('dist.level2Rate', 10),
|
||||
'settleCycle' => (string)$this->cfg('dist.settleCycle', 'T+7'),
|
||||
'minWithdraw' => (float)$this->cfg('dist.minWithdraw', 50),
|
||||
];
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户