yunzer/app/admin/controller/UsersController.php
2025-06-07 09:15:14 +08:00

98 lines
2.9 KiB
PHP

<?php
/**
* 商业使用授权协议
*
* Copyright (c) 2025 [云泽网]. 保留所有权利.
*
* 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
* 未经授权商业使用本软件属于侵权行为,将承担法律责任。
*
* 授权购买请联系: 357099073@qq.com
* 官方网站: https://www.yunzer.cn
*
* 评估用户须知:
* 1. 禁止移除版权声明
* 2. 禁止用于生产环境
* 3. 禁止转售或分发
*/
/**
* 后台管理系统-用户管理
*/
namespace app\admin\controller;
use app\admin\controller\BaseController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\admin\controller\Log;
use think\App;
use app\admin\model\User\Users;
class UsersController extends BaseController
{
/**
* 统计用户数量
*/
public function counts()
{
try {
// 统计用户总数
$total = Users::where('delete_time', 0)
->where('status', 1)
->count();
// 获取今日新增用户数
$today = strtotime(date('Y-m-d'));
$todayNew = Users::where('delete_time', 0)
->where('status', 1)
->where('create_time', '>=', $today)
->count();
// 获取最近7天的用户数据
$dates = [];
$counts = [];
$totalCounts = []; // 存储每天的总用户数
for ($i = 6; $i >= 0; $i--) {
$date = date('Y-m-d', strtotime("-$i days"));
$start = strtotime($date);
$end = $start + 86400;
// 获取当天新增用户数
$count = Users::where('delete_time', 0)
->where('status', 1)
->where('create_time', '>=', $start)
->where('create_time', '<', $end)
->count();
// 获取截至当天的总用户数
$totalCount = Users::where('delete_time', 0)
->where('status', 1)
->where('create_time', '<', $end)
->count();
$dates[] = $date;
$counts[] = $count;
$totalCounts[] = $totalCount;
}
return json([
'code' => 0,
'msg' => '获取成功',
'data' => [
'total' => $total,
'todayNew' => $todayNew,
'dates' => $dates,
'counts' => $counts,
'totalCounts' => $totalCounts
]
]);
} catch (\Exception $e) {
return json([
'code' => 1,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
}