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

78 lines
2.3 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
namespace app\admin\controller;
use app\admin\common\Base;
use think\Db;
/**
* 系统概览控制器
* 早熟预测后台独立实现不再依赖common模块
*/
class Dashboard extends Base
{
/**
* 后台首页概览
*/
public function index()
{
return $this->view->fetch('dashboard/index');
}
/**
* 获取统计数据
* admin模块独立实现使用wechat_user表
*/
public function getStatistics()
{
try {
// admin模块使用的表名固定
$userTable = 'wechat_user';
$infoTable = 'wechat_real_time_info';
$recordTable = 'wechat_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
]
]);
}
}
}