From f134b0e759b3d768969e384086eb7be97bb0f54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Wed, 11 Mar 2026 11:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8B=A5=E5=B9=B2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cms/Domain/TenantDomainController.php | 12 ++ .../controller/SiteSettingsController.php | 175 +++++++++++++++--- app/admin/route/routes/siteSettings.php | 2 + app/model/System/SystemSiteSetting.php | 41 ++++ app/model/Tenant/Tenant.php | 2 +- public/themes/default/index.php | 3 + 6 files changed, 210 insertions(+), 25 deletions(-) create mode 100644 app/model/System/SystemSiteSetting.php diff --git a/app/admin/controller/Cms/Domain/TenantDomainController.php b/app/admin/controller/Cms/Domain/TenantDomainController.php index d404534..cfff0d0 100644 --- a/app/admin/controller/Cms/Domain/TenantDomainController.php +++ b/app/admin/controller/Cms/Domain/TenantDomainController.php @@ -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)) { return json([ 'code' => 400, diff --git a/app/admin/controller/SiteSettingsController.php b/app/admin/controller/SiteSettingsController.php index 57cbd66..31adab4 100644 --- a/app/admin/controller/SiteSettingsController.php +++ b/app/admin/controller/SiteSettingsController.php @@ -8,7 +8,9 @@ use app\admin\BaseController; use think\exception\ValidateException; use think\facade\Db; use think\response\Json; +use app\model\System\SystemSiteSetting; use app\model\System\SystemSiteSettings; +use app\model\Tenant\Tenant; class SiteSettingsController extends BaseController { @@ -18,28 +20,43 @@ class SiteSettingsController extends BaseController */ public function getNormalInfos() { - // 定义你需要的 label 列表 - $targetLabels = [ - 'sitename', - 'logo', - 'logow', - 'description', - 'copyright', - 'companyname', - 'icp' - ]; + // 获取当前租户ID + $tid = $this->request->param('tid', 0, 'int'); - $siteSettings = SystemSiteSettings::where('delete_time', null) - ->whereIn('label', $targetLabels) // 仅筛选指定的 label - ->field('label, value') - ->select(); + // 查询站点设置 + $siteSetting = SystemSiteSetting::where('delete_time', null) + ->where('tid', $tid) + ->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()); return json([ 'code' => 200, 'msg' => '获取成功', - 'data' => $siteSettings->toArray() + 'data' => $data ]); } @@ -51,18 +68,46 @@ class SiteSettingsController extends BaseController { $params = $this->request->param(); $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])) { - SystemSiteSettings::update( - ['value' => (string)$rawData[$label]], - ['label' => $label] - ); - } + // 查找或创建记录 + $siteSetting = SystemSiteSetting::where('delete_time', null) + ->where('tid', $tid) + ->find(); + + 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' => '基本信息保存成功']); } @@ -173,4 +218,86 @@ class SiteSettingsController extends BaseController 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' => '企业信息保存成功']); + } } diff --git a/app/admin/route/routes/siteSettings.php b/app/admin/route/routes/siteSettings.php index 7a9f8c8..0beff17 100644 --- a/app/admin/route/routes/siteSettings.php +++ b/app/admin/route/routes/siteSettings.php @@ -8,3 +8,5 @@ Route::get('loginVerifyInfos', 'app\\admin\\controller\\SiteSettingsController@g Route::post('saveloginVerifyInfos', 'app\\admin\\controller\\SiteSettingsController@saveVerifyInfos'); Route::get('legalInfos', 'app\\admin\\controller\\SiteSettingsController@getLegalInfos'); Route::post('saveLegalInfos', 'app\\admin\\controller\\SiteSettingsController@saveLegalInfos'); +Route::get('companyInfos', 'app\\admin\\controller\\SiteSettingsController@getCompanyInfos'); +Route::post('saveCompanyInfos', 'app\\admin\\controller\\SiteSettingsController@saveCompanyInfos'); diff --git a/app/model/System/SystemSiteSetting.php b/app/model/System/SystemSiteSetting.php new file mode 100644 index 0000000..a144724 --- /dev/null +++ b/app/model/System/SystemSiteSetting.php @@ -0,0 +1,41 @@ + +// +---------------------------------------------------------------------- + +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', + ]; +} diff --git a/app/model/Tenant/Tenant.php b/app/model/Tenant/Tenant.php index 5c1e28d..8d4e2dd 100644 --- a/app/model/Tenant/Tenant.php +++ b/app/model/Tenant/Tenant.php @@ -30,7 +30,7 @@ class Tenant extends Model 'contact_phone' => 'string', 'contact_email' => 'string', 'address' => 'string', - 'domain' => 'string', + 'worktime' => 'string', 'status' => 'integer', 'create_time' => 'datetime', 'update_time' => 'datetime', diff --git a/public/themes/default/index.php b/public/themes/default/index.php index 8f0a888..c40b17e 100644 --- a/public/themes/default/index.php +++ b/public/themes/default/index.php @@ -1,3 +1,6 @@ +