Files
code/application/common/controller/DashboardBase.php
2026-01-29 17:48:51 +08:00

69 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 系统概览公共控制器
* 提供统一的业务逻辑供admin和adminghd模块继承使用
*/
namespace app\common\controller;
use app\common\common\BaseController;
use think\Db;
class DashboardBase extends BaseController
{
/**
* 获取统计数据
*/
public function getStatistics()
{
try {
// 获取表名
$userTable = $this->getTableName('user');
$infoTable = $this->getTableName('real_time_info');
$recordTable = $this->getTableName('calculate_record');
// 小程序注册用户数量
$userCount = Db::name($userTable)->count();
// 首页资讯数量
$infoCount = Db::name($infoTable)->count();
// 最近一次计算时间
$lastCalculate = Db::name($recordTable)
->order('create_time desc')
->value('create_time');
// 今日新增用户
$todayUserCount = Db::name($userTable)
->whereTime('create_time', 'today')
->count();
// 总计算次数
$totalCalculateCount = Db::name($recordTable)->count();
return json([
'status' => 1,
'msg' => '获取成功',
'data' => [
'user_count' => $userCount,
'info_count' => $infoCount,
'last_calculate_time' => $lastCalculate ?: '暂无',
'today_user_count' => $todayUserCount,
'total_calculate_count' => $totalCalculateCount
]
]);
} catch (\Exception $e) {
return json([
'status' => 0,
'msg' => '获取失败:' . $e->getMessage(),
'data' => [
'user_count' => 0,
'info_count' => 0,
'last_calculate_time' => '暂无',
'today_user_count' => 0,
'total_calculate_count' => 0
]
]);
}
}
}