修复若干bug

This commit is contained in:
2026-03-10 22:24:06 +08:00
parent 7cdb591f69
commit 98156991c1
16 changed files with 1021 additions and 892 deletions
+49 -1
View File
@@ -9,6 +9,7 @@ use think\App;
use think\exception\ValidateException;
use think\Validate;
use think\Request;
use think\facade\Db;
// 在控制器方法中添加
header('Access-Control-Allow-Origin: *');
@@ -44,6 +45,12 @@ abstract class BaseController
*/
protected $middleware = [];
/**
* 当前租户ID
* @var int
*/
protected $tenantId = 0;
/**
* 构造方法
* @access public
@@ -59,7 +66,48 @@ abstract class BaseController
}
// 初始化
protected function initialize() {}
protected function initialize()
{
// 自动检测并设置租户ID
$this->initTenantId();
}
/**
* 初始化租户ID
* 优先从 Referer 获取来源域名,否则使用当前访问域名
* 从 mete_tenant_domain 表查询对应的 tid
*/
protected function initTenantId(): void
{
// 优先从 Referer 获取来源域名(跨域调用场景)
$referer = $this->request->header('Referer');
if ($referer) {
$host = parse_url($referer, PHP_URL_HOST);
} else {
// 否则使用当前访问域名
$host = $this->request->host(true);
}
// 查询域名对应的租户ID
$tenantDomain = Db::name('mete_tenant_domain')
->where('full_domain', $host)
->where('status', 1)
->whereNull('delete_time')
->find();
if ($tenantDomain) {
$this->tenantId = (int)$tenantDomain['tid'];
}
}
/**
* 获取当前租户ID
* @return int
*/
protected function getTenantId(): int
{
return $this->tenantId;
}
/**
* 验证数据