refactor(member, auth): streamline product info retrieval and enhance dashboard statistics
- 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.
This commit is contained in:
+14
-19
@@ -95,13 +95,10 @@ class Member extends Model
|
||||
*/
|
||||
public function getProductInfo(): ?array
|
||||
{
|
||||
// 从主库获取套餐信息
|
||||
$product = \think\facade\Db::connect('dbbiz')
|
||||
->name('product_list')
|
||||
->where('v_type', $this->v_type)
|
||||
->find();
|
||||
// 套餐配置改由模型统一封装,避免业务层散落裸表查询。
|
||||
$product = ProductList::findByVType((int) $this->v_type);
|
||||
|
||||
return $product;
|
||||
return $product ? $product->toArray() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,19 +123,17 @@ class Member extends Model
|
||||
public function logLogin(bool $success, string $loginType = 'password'): void
|
||||
{
|
||||
try {
|
||||
\think\facade\Db::connect('dbmember')
|
||||
->name('member_login_log')
|
||||
->insert([
|
||||
'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 (\Exception $e) {
|
||||
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) {
|
||||
// 日志记录失败不影响登录
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user