一、基础设施
- 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
119 行
3.8 KiB
PHP
119 行
3.8 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Db;
|
||
|
||
/**
|
||
* 后台管理端 · 订单管理(Module-ADM-ORDER)
|
||
* 路由:
|
||
* GET /api/v1/admin/orders AO1 订单列表
|
||
* POST /api/v1/admin/order/:id/refund AO2 订单退款
|
||
* POST /api/v1/admin/order/supplement AO3 订单补单
|
||
*/
|
||
class AdminOrder extends V1
|
||
{
|
||
/**
|
||
* AO1 订单列表
|
||
* GET /api/v1/admin/orders 入参 {type?,page,size}
|
||
* → 分页 {list:[{id,orderNo,type,title,amount,payType,status,userId,userName,createdAt}],page,size,total,hasMore}
|
||
*/
|
||
public function index()
|
||
{
|
||
list($page, $size) = $this->pager();
|
||
$type = trim((string)$this->input('type', ''));
|
||
|
||
$query = Db::name('fc_order')->alias('o')
|
||
->join('user u', 'u.id = o.user_id', 'LEFT');
|
||
|
||
if ($type !== '') {
|
||
$query->where('o.type', $type);
|
||
}
|
||
|
||
$total = $query->count();
|
||
$rows = $query->field('o.*, u.nickname AS nickname')
|
||
->order('o.createtime desc')
|
||
->page($page, $size)
|
||
->select();
|
||
|
||
$list = [];
|
||
foreach ($rows as $row) {
|
||
$list[] = [
|
||
'id' => (int)$row['id'],
|
||
'orderNo' => (string)$row['order_no'],
|
||
'type' => (string)$row['type'],
|
||
'title' => (string)$row['title'],
|
||
'amount' => (float)$row['amount'],
|
||
'payType' => (string)$row['pay_type'],
|
||
'status' => (string)$row['status'],
|
||
'userId' => (int)$row['user_id'],
|
||
'userName' => (string)$row['nickname'],
|
||
'createdAt' => $this->iso($row['createtime']),
|
||
];
|
||
}
|
||
|
||
$this->ok($this->paginate($list, $total, $page, $size));
|
||
}
|
||
|
||
/**
|
||
* AO2 订单退款
|
||
* POST /api/v1/admin/order/:id/refund 入参 {amount,reason?} → {id,refunded}
|
||
* 规则 BR-10:退款金额需大于 0
|
||
*/
|
||
public function refund()
|
||
{
|
||
$id = (int)$this->request->param('id', 0);
|
||
$amount = round((float)$this->input('amount', 0), 2);
|
||
$reason = trim((string)$this->input('reason', ''));
|
||
|
||
if ($amount <= 0) {
|
||
$this->fail('退款金额需大于 0');
|
||
}
|
||
|
||
$order = Db::name('fc_order')->where('id', $id)->find();
|
||
if (!$order) {
|
||
$this->fail('订单不存在', 404);
|
||
}
|
||
|
||
Db::name('fc_order')->where('id', $id)->update([
|
||
'status' => 'refunded',
|
||
'refund_amount' => $amount,
|
||
'refund_reason' => $reason,
|
||
]);
|
||
|
||
$this->notify($order['user_id'], 'system', '订单已退款', '您的订单「' . $order['title'] . '」已退款 ' . $amount . ' 元。');
|
||
$this->adminLog('订单退款 #' . $id . ' 金额' . $amount);
|
||
|
||
$this->ok(['id' => (int)$id, 'refunded' => true]);
|
||
}
|
||
|
||
/**
|
||
* AO3 订单补单
|
||
* POST /api/v1/admin/order/supplement 入参 {orderNo} → {orderNo,supplemented}
|
||
* 幂等:已支付直接返回
|
||
*/
|
||
public function supplement()
|
||
{
|
||
$orderNo = trim((string)$this->input('orderNo', ''));
|
||
if ($orderNo === '') {
|
||
$this->fail('订单号不能为空');
|
||
}
|
||
|
||
$order = Db::name('fc_order')->where('order_no', $orderNo)->find();
|
||
if (!$order) {
|
||
$this->fail('订单不存在', 404);
|
||
}
|
||
|
||
if ($order['status'] !== 'paid') {
|
||
Db::name('fc_order')->where('id', $order['id'])->update([
|
||
'status' => 'paid',
|
||
'paytime' => time(),
|
||
]);
|
||
$this->flow('income', '订单补单', $order['amount'], 0, $order['id']);
|
||
$this->adminLog('订单补单 #' . $orderNo);
|
||
}
|
||
|
||
$this->ok(['orderNo' => (string)$orderNo, 'supplemented' => true]);
|
||
}
|
||
}
|