6b46767d86
- Updated `getProductInfo` method in `Member` model to use a unified model for fetching product data. - Refactored `logLogin` method to utilize `MemberLoginLog` for logging login attempts. - Introduced `getDashboardStats` method in `AuthService` to gather user-specific statistics, including remaining quotas and counts of authorized accounts, published tasks, and works. - Added new database configuration for Douyin business statistics.
141 lines
3.2 KiB
PHP
141 lines
3.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* 用户模型 (对应原系统 member 表)
|
|
* 数据库连接: dbmember (member库)
|
|
*/
|
|
class Member extends Model
|
|
{
|
|
// 设置连接名 (对应 config/database.php 中的 connections)
|
|
protected $connection = 'dbmember';
|
|
|
|
// 表名
|
|
protected $name = 'member';
|
|
|
|
// 主键
|
|
protected $pk = 'userid';
|
|
|
|
// 自动时间戳
|
|
protected $autoWriteTimestamp = false;
|
|
|
|
// 隐藏字段
|
|
protected $hidden = ['password'];
|
|
|
|
/**
|
|
* 根据用户名查找用户
|
|
* @param string $username
|
|
* @return Member|null
|
|
*/
|
|
public static function findByUsername(string $username): ?Member
|
|
{
|
|
return self::where('username', $username)->find();
|
|
}
|
|
|
|
/**
|
|
* 根据用户ID查找用户
|
|
* @param int $userid
|
|
* @return Member|null
|
|
*/
|
|
public static function findByUserid(int $userid): ?Member
|
|
{
|
|
return self::where('userid', $userid)->find();
|
|
}
|
|
|
|
/**
|
|
* 验证密码
|
|
* 当前项目统一使用双重 MD5。
|
|
*
|
|
* @param string $password 明文密码
|
|
* @return bool
|
|
*/
|
|
public function verifyPassword(string $password): bool
|
|
{
|
|
return self::makePassword($password) === $this->password;
|
|
}
|
|
|
|
/**
|
|
* 生成系统使用的密码摘要
|
|
* @param string $password 明文密码
|
|
* @return string
|
|
*/
|
|
public static function makePassword(string $password): string
|
|
{
|
|
return md5(md5($password));
|
|
}
|
|
|
|
/**
|
|
* 检查用户是否被禁用
|
|
* @return bool
|
|
*/
|
|
public function isDisabled(): bool
|
|
{
|
|
return $this->disabled == 1;
|
|
}
|
|
|
|
/**
|
|
* 检查账号是否过期
|
|
* @return bool
|
|
*/
|
|
public function isExpired(): bool
|
|
{
|
|
if (empty($this->endtime)) {
|
|
return false;
|
|
}
|
|
return $this->endtime < time();
|
|
}
|
|
|
|
/**
|
|
* 获取用户套餐信息
|
|
* @return array|null
|
|
*/
|
|
public function getProductInfo(): ?array
|
|
{
|
|
// 套餐配置改由模型统一封装,避免业务层散落裸表查询。
|
|
$product = ProductList::findByVType((int) $this->v_type);
|
|
|
|
return $product ? $product->toArray() : null;
|
|
}
|
|
|
|
/**
|
|
* 获取代理商信息
|
|
* @return array|null
|
|
*/
|
|
public function getAgentInfo(): ?array
|
|
{
|
|
if (empty($this->formtypeid)) {
|
|
return null;
|
|
}
|
|
|
|
return self::where('userid', $this->formtypeid)->find();
|
|
}
|
|
|
|
/**
|
|
* 记录登录日志
|
|
* @param bool $success
|
|
* @param string $loginType
|
|
* @return void
|
|
*/
|
|
public function logLogin(bool $success, string $loginType = 'password'): void
|
|
{
|
|
try {
|
|
MemberLoginLog::recordLogin([
|
|
'userid' => $this->userid,
|
|
'ip' => request()->ip(),
|
|
'time' => time(),
|
|
'succeed' => $success ? 1 : 0,
|
|
'diqu' => '',
|
|
'login_type' => $loginType,
|
|
'adminid' => 0,
|
|
'v_type' => $this->v_type ?? 0,
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
// 日志记录失败不影响登录
|
|
}
|
|
}
|
|
}
|