后台优化
This commit is contained in:
77
application/adminghd/controller/Dashboard.php
Normal file
77
application/adminghd/controller/Dashboard.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\adminghd\controller;
|
||||
|
||||
use app\adminghd\common\Base;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 系统概览控制器
|
||||
* GHD预测后台独立实现,不再依赖common模块
|
||||
*/
|
||||
class Dashboard extends Base
|
||||
{
|
||||
/**
|
||||
* 后台首页概览
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->view->fetch('dashboard/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统计数据
|
||||
* adminghd模块独立实现,使用ghd_wechat_user表
|
||||
*/
|
||||
public function getStatistics()
|
||||
{
|
||||
try {
|
||||
// adminghd模块使用的表名(固定)
|
||||
$userTable = 'ghd_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
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user