From 12e5b93a38b6aec7d10f4ba1574063ae8e5cd41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 29 Apr 2025 11:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=98=BE=E7=A4=BA=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/common/model/User.php | 60 ------------------ .../common/service/AuthService.php | 63 ++++++++++++++++++- .../dashboard/GetBasestatisticsController.php | 9 +-- SuperAdmin/app/dashboard/page.tsx | 2 +- 4 files changed, 68 insertions(+), 66 deletions(-) diff --git a/Server/application/common/model/User.php b/Server/application/common/model/User.php index 5d9b15b7..bd37c17f 100644 --- a/Server/application/common/model/User.php +++ b/Server/application/common/model/User.php @@ -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 手机号 diff --git a/Server/application/common/service/AuthService.php b/Server/application/common/service/AuthService.php index 8afc53a2..b94c57cc 100644 --- a/Server/application/common/service/AuthService.php +++ b/Server/application/common/service/AuthService.php @@ -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)) { // 记录登录失败 diff --git a/Server/application/superadmin/controller/dashboard/GetBasestatisticsController.php b/Server/application/superadmin/controller/dashboard/GetBasestatisticsController.php index 71ea2132..01278b8c 100644 --- a/Server/application/superadmin/controller/dashboard/GetBasestatisticsController.php +++ b/Server/application/superadmin/controller/dashboard/GetBasestatisticsController.php @@ -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(), ] ); } diff --git a/SuperAdmin/app/dashboard/page.tsx b/SuperAdmin/app/dashboard/page.tsx index 962f1c9f..502ea542 100644 --- a/SuperAdmin/app/dashboard/page.tsx +++ b/SuperAdmin/app/dashboard/page.tsx @@ -99,7 +99,7 @@ export default function DashboardPage() { - 客户总数 + 设备总数