创建模型

This commit is contained in:
2025-05-12 09:04:46 +08:00
parent fc327e9f48
commit 8ee9ab1b92
19 changed files with 594 additions and 139 deletions

View File

@@ -2,7 +2,7 @@
namespace App\BaseApp;
use App\Models\UserModel;
use App\Models\AdminModel;
use App\Service\common\JWTService;
use App\Service\common\UtilsService;
use Exception;
@@ -25,6 +25,10 @@ class BaseService
* @var int 用户ID默认值为0表示未登录状态
*/
protected int $userId = 0;
/**
* @var int 角色ID默认值为0表示未登录状态
*/
protected int $roleId = 0;
/**
* @var array 用户信息
@@ -36,11 +40,6 @@ class BaseService
*/
protected $model;
/**
* @var bool 是否需要验证用户权限
*/
protected bool $isAuth = true;
/**
* @var array 查询的字段
*/
@@ -93,17 +92,9 @@ class BaseService
public function __construct()
{
if ($this->isAuth) {
$this->userInfo = JWTService::getInstance()->getToken()->getUserInfo();
$this->userId = $this->userInfo['id'] ?? 0;
} else {
try {
$this->userInfo = JWTService::getInstance()->getToken()->getUserInfo();
$this->userId = $this->userInfo['id'] ?? 0;
} catch (Exception $e) {
$this->userId = 0;
}
}
$this->userInfo = JWTService::getInstance()->getToken()->getUserInfo();
$this->userId = $this->userInfo['id'] ?? 0;
$this->roleId = $this->userInfo['role_id'] ?? 0;
$this->utils = UtilsService::getInstance();
}