- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
108 行
4.1 KiB
PHP
108 行
4.1 KiB
PHP
<?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
|
||
{
|
||
/** 管理端接口必须校验管理员身份(V1 默认关闭了 URI 权限校验) */
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->adminOnly();
|
||
}
|
||
|
||
/**
|
||
* 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);
|
||
}
|
||
}
|