更新若干bug

This commit is contained in:
李志强 2026-03-11 11:11:10 +08:00
parent 5dffe62adc
commit f134b0e759
6 changed files with 210 additions and 25 deletions

View File

@ -117,6 +117,18 @@ class TenantDomainController extends BaseController
]); ]);
} }
// 检查该租户是否已有域名数据
$hasDomain = TenantDomain::where('tid', $tid)
->where('delete_time', null)
->find();
if ($hasDomain) {
return json([
'code' => 400,
'msg' => '该租户已有域名,请删除后再次申请'
]);
}
if (empty($subDomain)) { if (empty($subDomain)) {
return json([ return json([
'code' => 400, 'code' => 400,

View File

@ -8,7 +8,9 @@ use app\admin\BaseController;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Db; use think\facade\Db;
use think\response\Json; use think\response\Json;
use app\model\System\SystemSiteSetting;
use app\model\System\SystemSiteSettings; use app\model\System\SystemSiteSettings;
use app\model\Tenant\Tenant;
class SiteSettingsController extends BaseController class SiteSettingsController extends BaseController
{ {
@ -18,28 +20,43 @@ class SiteSettingsController extends BaseController
*/ */
public function getNormalInfos() public function getNormalInfos()
{ {
// 定义你需要的 label 列表 // 获取当前租户ID
$targetLabels = [ $tid = $this->request->param('tid', 0, 'int');
'sitename',
'logo',
'logow',
'description',
'copyright',
'companyname',
'icp'
];
$siteSettings = SystemSiteSettings::where('delete_time', null) // 查询站点设置
->whereIn('label', $targetLabels) // 仅筛选指定的 label $siteSetting = SystemSiteSetting::where('delete_time', null)
->field('label, value') ->where('tid', $tid)
->select(); ->find();
// 如果没有数据,返回空值结构
if (!$siteSetting) {
$data = [
'sitename' => '',
'logo' => '',
'logow' => '',
'description' => '',
'copyright' => '',
'companyname' => '',
'icp' => ''
];
} else {
$data = [
'sitename' => $siteSetting->sitename ?? '',
'logo' => $siteSetting->logo ?? '',
'logow' => $siteSetting->{'logo-w'} ?? '',
'description' => $siteSetting->description ?? '',
'copyright' => $siteSetting->copyright ?? '',
'companyname' => $siteSetting->companyname ?? '',
'icp' => $siteSetting->icp ?? ''
];
}
$this->logSuccess('站点设置管理', '查看基本信息配置', [], $this->getAdminUserInfo()); $this->logSuccess('站点设置管理', '查看基本信息配置', [], $this->getAdminUserInfo());
return json([ return json([
'code' => 200, 'code' => 200,
'msg' => '获取成功', 'msg' => '获取成功',
'data' => $siteSettings->toArray() 'data' => $data
]); ]);
} }
@ -51,18 +68,46 @@ class SiteSettingsController extends BaseController
{ {
$params = $this->request->param(); $params = $this->request->param();
$rawData = isset($params['data']) ? json_decode($params['data'], true) : $params; $rawData = isset($params['data']) ? json_decode($params['data'], true) : $params;
$allowedLabels = ['sitename', 'logo', 'logow', 'description', 'copyright', 'companyname', 'icp']; $tid = $params['tid'] ?? 0;
foreach ($allowedLabels as $label) { // 查找或创建记录
if (isset($rawData[$label])) { $siteSetting = SystemSiteSetting::where('delete_time', null)
SystemSiteSettings::update( ->where('tid', $tid)
['value' => (string)$rawData[$label]], ->find();
['label' => $label]
); if (!$siteSetting) {
} $siteSetting = new SystemSiteSetting();
$siteSetting->tid = $tid;
$siteSetting->create_time = date('Y-m-d H:i:s');
} }
$this->logSuccess('站点设置管理', '保存基本信息', ['labels' => $allowedLabels], $this->getAdminUserInfo()); // 更新字段
if (isset($rawData['sitename'])) {
$siteSetting->sitename = (string)$rawData['sitename'];
}
if (isset($rawData['logo'])) {
$siteSetting->logo = (string)$rawData['logo'];
}
if (isset($rawData['logow'])) {
$siteSetting->{'logo-w'} = (string)$rawData['logow'];
}
if (isset($rawData['description'])) {
$siteSetting->description = (string)$rawData['description'];
}
if (isset($rawData['copyright'])) {
$siteSetting->copyright = (string)$rawData['copyright'];
}
if (isset($rawData['companyname'])) {
$siteSetting->companyname = (string)$rawData['companyname'];
}
if (isset($rawData['icp'])) {
$siteSetting->icp = (string)$rawData['icp'];
}
$siteSetting->update_time = date('Y-m-d H:i:s');
$siteSetting->save();
$this->logSuccess('站点设置管理', '保存基本信息', ['tid' => $tid], $this->getAdminUserInfo());
return json(['code' => 200, 'msg' => '基本信息保存成功']); return json(['code' => 200, 'msg' => '基本信息保存成功']);
} }
@ -173,4 +218,86 @@ class SiteSettingsController extends BaseController
return json(['code' => 200, 'msg' => '法律声明和隐私条款保存成功']); return json(['code' => 200, 'msg' => '法律声明和隐私条款保存成功']);
} }
/**
* 获取企业信息
* @return Json
*/
public function getCompanyInfos()
{
// 获取当前租户ID
$tid = $this->request->param('tid', 0, 'int');
// 查询租户信息
$tenant = Tenant::where('delete_time', null)
->where('id', $tid)
->find();
// 如果没有数据,返回空值结构
if (!$tenant) {
$data = [
'contact_phone' => '',
'contact_email' => '',
'address' => '',
'worktime' => ''
];
} else {
$data = [
'contact_phone' => $tenant->contact_phone ?? '',
'contact_email' => $tenant->contact_email ?? '',
'address' => $tenant->address ?? '',
'worktime' => $tenant->worktime ?? ''
];
}
$this->logSuccess('站点设置管理', '查看企业信息', [], $this->getAdminUserInfo());
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $data
]);
}
/**
* 保存企业信息
* @return Json
*/
public function saveCompanyInfos()
{
$params = $this->request->param();
$tid = $params['tid'] ?? 0;
// 查找租户记录
$tenant = Tenant::where('delete_time', null)
->where('id', $tid)
->find();
if (!$tenant) {
return json([
'code' => 404,
'msg' => '租户不存在'
]);
}
// 更新字段
if (isset($params['contact_phone'])) {
$tenant->contact_phone = (string)$params['contact_phone'];
}
if (isset($params['contact_email'])) {
$tenant->contact_email = (string)$params['contact_email'];
}
if (isset($params['address'])) {
$tenant->address = (string)$params['address'];
}
if (isset($params['worktime'])) {
$tenant->worktime = (string)$params['worktime'];
}
$tenant->save();
$this->logSuccess('站点设置管理', '保存企业信息', ['tid' => $tid], $this->getAdminUserInfo());
return json(['code' => 200, 'msg' => '企业信息保存成功']);
}
} }

View File

@ -8,3 +8,5 @@ Route::get('loginVerifyInfos', 'app\\admin\\controller\\SiteSettingsController@g
Route::post('saveloginVerifyInfos', 'app\\admin\\controller\\SiteSettingsController@saveVerifyInfos'); Route::post('saveloginVerifyInfos', 'app\\admin\\controller\\SiteSettingsController@saveVerifyInfos');
Route::get('legalInfos', 'app\\admin\\controller\\SiteSettingsController@getLegalInfos'); Route::get('legalInfos', 'app\\admin\\controller\\SiteSettingsController@getLegalInfos');
Route::post('saveLegalInfos', 'app\\admin\\controller\\SiteSettingsController@saveLegalInfos'); Route::post('saveLegalInfos', 'app\\admin\\controller\\SiteSettingsController@saveLegalInfos');
Route::get('companyInfos', 'app\\admin\\controller\\SiteSettingsController@getCompanyInfos');
Route::post('saveCompanyInfos', 'app\\admin\\controller\\SiteSettingsController@saveCompanyInfos');

View File

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app\model\System;
use think\Model;
use think\model\concern\SoftDelete;
/**
* 站点设置模型
*/
class SystemSiteSetting extends Model
{
// 启用软删除
use SoftDelete;
// 数据库表名
protected $name = 'mete_system_site_setting';
// 字段类型转换
protected $type = [
'id' => 'integer',
'tid' => 'integer',
'sitename' => 'string',
'logo' => 'string',
'logo-w' => 'string',
'description' => 'string',
'copyright' => 'string',
'companyname' => 'string',
'icp' => 'string',
'create_time' => 'datetime',
];
}

View File

@ -30,7 +30,7 @@ class Tenant extends Model
'contact_phone' => 'string', 'contact_phone' => 'string',
'contact_email' => 'string', 'contact_email' => 'string',
'address' => 'string', 'address' => 'string',
'domain' => 'string', 'worktime' => 'string',
'status' => 'integer', 'status' => 'integer',
'create_time' => 'datetime', 'create_time' => 'datetime',
'update_time' => 'datetime', 'update_time' => 'datetime',

View File

@ -1,3 +1,6 @@
<?php
?>
<!DOCTYPE html> <!DOCTYPE html>
<html class="no-js" lang=""> <html class="no-js" lang="">