超管后台 - 仪表盘显示设备总数

This commit is contained in:
柳清爽
2025-04-29 11:22:10 +08:00
parent 319437cc2b
commit 12e5b93a38
4 changed files with 68 additions and 66 deletions

View File

@@ -54,66 +54,6 @@ class User extends Model
'deleteTime' => 'integer'
];
/**
* 获取用户信息
* @param string $account 账号(手机号)
* @param string $password 密码(可能是加密后的)
* @param int $typeId 身份信息
* @return array|null
*/
public static function getUser($account, $password, $typeId)
{
// 查询用户
$user = self::where('account', $account)
->where('typeId', $typeId)
->where('status', 1)
->find();
if (!$user) {
// 记录日志
\think\facade\Log::info('用户不存在或已禁用', ['account' => $account]);
return null;
}
// 记录密码验证信息
\think\facade\Log::info('密码验证', [
'account' => $account,
'input_password' => $password,
'stored_hash' => $user->passwordMd5,
]);
// 验证密码
$isValid = ($user->passwordMd5 == md5($password));
\think\facade\Log::info('密码验证结果', [
'account' => $account,
'is_valid' => $isValid,
]);
if (!$isValid) {
return null;
}
// 更新登录信息
$user->lastLoginIp = request()->ip();
$user->lastLoginTime = time();
$user->save();
// 用手机号当做默认用户名(如果没有设置用户名)
$username = $user->username ?: $user->account;
return [
'id' => $user->id,
'username' => $username,
'account' => $user->account,
'avatar' => $user->avatar,
'isAdmin' => $user->isAdmin,
'companyId' => $user->companyId,
'typeId' => $user->typeId,
'lastLoginIp' => $user->lastLoginIp,
'lastLoginTime' => $user->lastLoginTime
];
}
/**
* 通过手机号获取用户信息
* @param string $account 手机号

View File

@@ -21,6 +21,67 @@ class AuthService
*/
protected $smsService;
/**
* 获取用户信息
* @param string $account 账号(手机号)
* @param string $password 密码(可能是加密后的)
* @param int $typeId 身份信息
* @return array|null
*/
protected function getUser($account, $password, $typeId)
{
// 查询用户
$user = User::where('account', $account)
->where('typeId', $typeId)
->where('status', 1)
->find();
if (!$user) {
// 记录日志
\think\facade\Log::info('用户不存在或已禁用', ['account' => $account]);
return null;
}
// 记录密码验证信息
\think\facade\Log::info('密码验证', [
'account' => $account,
'input_password' => $password,
'stored_hash' => $user->passwordMd5,
]);
// 验证密码
$isValid = ($user->passwordMd5 == md5($password));
\think\facade\Log::info('密码验证结果', [
'account' => $account,
'is_valid' => $isValid,
]);
if (!$isValid) {
return null;
}
// 更新登录信息
$user->lastLoginIp = request()->ip();
$user->lastLoginTime = time();
$user->save();
// 用手机号当做默认用户名(如果没有设置用户名)
$username = $user->username ?: $user->account;
return [
'id' => $user->id,
'username' => $username,
'account' => $user->account,
'avatar' => $user->avatar,
'isAdmin' => $user->isAdmin,
'companyId' => $user->companyId,
'typeId' => $user->typeId,
'lastLoginIp' => $user->lastLoginIp,
'lastLoginTime' => $user->lastLoginTime
];
}
/**
* 构造函数
*/
@@ -40,7 +101,7 @@ class AuthService
public function login($account, $password, $typeId, $ip)
{
// 获取用户信息
$user = User::getUser($account, $password, $typeId);
$user = $this->getUser($account, $password, $typeId);
if (empty($user)) {
// 记录登录失败

View File

@@ -4,6 +4,7 @@ namespace app\superadmin\controller\dashboard;
use app\common\model\Administrator as AdministratorModel;
use app\common\model\Company as CompanyModel;
use app\common\model\Device as DeviceModel;
use library\ResponseHelper;
use think\Controller;
@@ -33,13 +34,13 @@ class GetBasestatisticsController extends Controller
}
/**
* 客户总数
* 设备总数
*
* @return int
*/
protected function getCustomerCount(): int
protected function getDeviceCount(): int
{
return $this->getCompanyCount();
return DeviceModel::count('*');
}
/**
@@ -53,7 +54,7 @@ class GetBasestatisticsController extends Controller
[
'companyCount' => $this->getCompanyCount(),
'adminCount' => $this->getAdminCount(),
'customerCount' => $this->getCustomerCount(),
'customerCount' => $this->getDeviceCount(),
]
);
}

View File

@@ -99,7 +99,7 @@ export default function DashboardPage() {
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<CardTitle className="text-sm font-medium"></CardTitle>
<Users className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>