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,100 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 后台管理端 · 数据总览(Module-ADM-DASHBOARD)
|
||||
* 路由:
|
||||
* GET /api/v1/admin/dashboard/overview AD1 核心指标
|
||||
* GET /api/v1/admin/dashboard/trend AD2 趋势(近 7 天)
|
||||
*/
|
||||
class AdminDashboard extends V1
|
||||
{
|
||||
/**
|
||||
* AD1 核心指标
|
||||
* GET /api/v1/admin/dashboard/overview
|
||||
* → {pv,uv,todayPostCount,todayOrderAmount,memberCount,merchantCount,commissionTotal,pendingAudit,postGrowth,orderGrowth,userGrowth}
|
||||
*/
|
||||
public function overview()
|
||||
{
|
||||
$pv = (int)Db::name('fc_post')->sum('views');
|
||||
$uv = (int)Db::name('user')->count();
|
||||
|
||||
$todayStart = strtotime(date('Y-m-d'));
|
||||
$todayPostCount = (int)Db::name('fc_post')->where('createtime', '>=', $todayStart)->count();
|
||||
$todayOrderAmount = (float)Db::name('fc_order')->where('status', 'paid')
|
||||
->where('createtime', '>=', $todayStart)->sum('amount');
|
||||
|
||||
$now = time();
|
||||
$memberCount = (int)Db::name('fc_user_ext')->where('is_member', 1)
|
||||
->where(function ($q) use ($now) {
|
||||
$q->whereNull('member_expiretime')->whereOr('member_expiretime', '>', $now);
|
||||
})->count();
|
||||
|
||||
$merchantCount = (int)Db::name('fc_merchant')->count();
|
||||
$commissionTotal = (float)Db::name('fc_commission')->sum('amount');
|
||||
$pendingAudit = (int)Db::name('fc_post')->where('audit_status', 0)->count();
|
||||
|
||||
$this->ok([
|
||||
'pv' => $pv,
|
||||
'uv' => $uv,
|
||||
'todayPostCount' => $todayPostCount,
|
||||
'todayOrderAmount' => round($todayOrderAmount, 2),
|
||||
'memberCount' => $memberCount,
|
||||
'merchantCount' => $merchantCount,
|
||||
'commissionTotal' => round($commissionTotal, 2),
|
||||
'pendingAudit' => $pendingAudit,
|
||||
'postGrowth' => 0.0,
|
||||
'orderGrowth' => 0.0,
|
||||
'userGrowth' => 0.0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* AD2 趋势(近 7 天,含当天)
|
||||
* GET /api/v1/admin/dashboard/trend 入参 {type} type∈traffic|revenue|userGrowth
|
||||
* traffic → [{date,pv,uv}] uv=当天新增用户
|
||||
* revenue → [{date,amount}] 当天 paid 订单金额
|
||||
* userGrowth → [{date,newUser,totalUser}]
|
||||
* 未知 type 回退 traffic
|
||||
*/
|
||||
public function trend()
|
||||
{
|
||||
$type = (string)$this->input('type', 'traffic');
|
||||
if (!in_array($type, ['traffic', 'revenue', 'userGrowth'], true)) {
|
||||
$type = 'traffic';
|
||||
}
|
||||
|
||||
$days = [];
|
||||
for ($i = 6; $i >= 0; $i--) {
|
||||
$days[] = date('Y-m-d', strtotime('-' . $i . ' day'));
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($days as $date) {
|
||||
$start = strtotime($date);
|
||||
$end = $start + 86400;
|
||||
|
||||
if ($type === 'traffic') {
|
||||
$pv = (int)Db::name('fc_post')->where('createtime', '>=', $start)
|
||||
->where('createtime', '<', $end)->sum('views');
|
||||
$uv = (int)Db::name('user')->where('jointime', '>=', $start)
|
||||
->where('jointime', '<', $end)->count();
|
||||
$result[] = ['date' => $date, 'pv' => $pv, 'uv' => $uv];
|
||||
} elseif ($type === 'revenue') {
|
||||
$amount = (float)Db::name('fc_order')->where('status', 'paid')
|
||||
->where('createtime', '>=', $start)->where('createtime', '<', $end)->sum('amount');
|
||||
$result[] = ['date' => $date, 'amount' => round($amount, 2)];
|
||||
} else {
|
||||
$newUser = (int)Db::name('user')->where('jointime', '>=', $start)
|
||||
->where('jointime', '<', $end)->count();
|
||||
$totalUser = (int)Db::name('user')->where('jointime', '<', $end)->count();
|
||||
$result[] = ['date' => $date, 'newUser' => $newUser, 'totalUser' => $totalUser];
|
||||
}
|
||||
}
|
||||
|
||||
$this->ok($result);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户