|
...
|
...
|
@@ -9,7 +9,9 @@ |
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside\SeoSetting;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Devops\ServerConfig;
|
|
|
|
use App\Models\Devops\Servers;
|
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
...
|
...
|
@@ -37,11 +39,11 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
public function infoDomain()
|
|
|
|
{
|
|
|
|
$domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']);
|
|
|
|
$domain = $domain_info['seo_domain'] ?: '';
|
|
|
|
$ftp = $domain_info['seo_ftp'] ? json_decode($domain['seo_ftp'], true) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
|
|
|
|
$type = $domain_info['seo_type'] ?: 1;
|
|
|
|
$record = '';
|
|
|
|
$type = $domain_info['seo_type'] ?? WebSetting::SEO_TYPE_PUBLIC;
|
|
|
|
$domain = $domain_info['seo_domain'] ?? '';
|
|
|
|
$ftp = isset($domain_info['seo_ftp']) && $domain_info['seo_ftp'] ? Arr::s2a($domain_info['seo_ftp']) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
|
|
|
|
|
|
|
|
$record = '';
|
|
|
|
if ($type == WebSetting::SEO_TYPE_PUBLIC) {
|
|
|
|
//公共服务器
|
|
|
|
if ($domain) {
|
|
...
|
...
|
@@ -65,7 +67,8 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存设置
|
|
|
|
* @name :saveDomain
|
|
|
|
* @throws \App\Exceptions\AsideGlobalException
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/20 16:12
|
|
...
|
...
|
@@ -79,13 +82,6 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
$this->fail('主域名填写错误');
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取解析服务器详情
|
|
|
|
$server_ip_model = new ServersIp();
|
|
|
|
$record_info = $server_ip_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain', 'total']);
|
|
|
|
if (!$record_info) {
|
|
|
|
$this->fail('解析记录不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取项目详情
|
|
|
|
$project_model = new Project();
|
|
|
|
$project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);
|
|
...
|
...
|
@@ -93,64 +89,125 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
$this->fail('获取项目数据失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
//构建blog二级域名
|
|
|
|
$domain_array = explode('.', $domain);
|
|
|
|
if (count($domain_array) == 1) {
|
|
|
|
$this->fail('请填写正确的主域名');
|
|
|
|
} elseif (count($domain_array) == 2) {
|
|
|
|
array_unshift($domain_array, 'blog');
|
|
|
|
} else {
|
|
|
|
$domain_array[0] = 'blog';
|
|
|
|
}
|
|
|
|
$blog_domain = implode('.', $domain_array);
|
|
|
|
$server_ip_model = new ServersIp();
|
|
|
|
$domain_model = new DomainInfo();
|
|
|
|
$server_model = new Servers();
|
|
|
|
$optimize_model = new DeployOptimize();
|
|
|
|
if ($this->param['type'] == WebSetting::SEO_TYPE_PUBLIC) {
|
|
|
|
//公共服务器
|
|
|
|
$record = $this->param['record'] ?? '';
|
|
|
|
if (empty($record)) {
|
|
|
|
$this->fail('解析记录不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断blog二级域名是否已经解析
|
|
|
|
if (!check_domain_record($blog_domain, $record_info)) {
|
|
|
|
$this->fail($blog_domain . '还未解析cname至' . $this->param['record']);
|
|
|
|
}
|
|
|
|
//获取解析服务器详情
|
|
|
|
$record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
|
|
|
|
if (!$record_info) {
|
|
|
|
$this->fail('解析记录不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//保存一条主域名记录
|
|
|
|
$setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
|
|
|
|
if ($setting_info === false) {
|
|
|
|
$this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
|
|
|
|
//构建blog二级域名
|
|
|
|
$domain_array = explode('.', $domain);
|
|
|
|
if (count($domain_array) == 1) {
|
|
|
|
$this->fail('请填写正确的主域名');
|
|
|
|
} elseif (count($domain_array) == 2) {
|
|
|
|
array_unshift($domain_array, 'blog');
|
|
|
|
} else {
|
|
|
|
$this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]);
|
|
|
|
$domain_array[0] = 'blog';
|
|
|
|
}
|
|
|
|
$blog_domain = implode('.', $domain_array);
|
|
|
|
|
|
|
|
//添加域名到域名管理
|
|
|
|
$domain_model = new DomainInfo();
|
|
|
|
$info = $domain_model->read(['domain' => $blog_domain]);
|
|
|
|
if ($info === false) {
|
|
|
|
$id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
|
|
|
|
|
|
|
|
//保存优化设置
|
|
|
|
$optimize_model = new DeployOptimize();
|
|
|
|
$optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//保存项目ip
|
|
|
|
$project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//变更ip使用数量
|
|
|
|
$server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
|
|
|
|
$server_model = new Servers();
|
|
|
|
$server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
|
|
|
|
|
|
|
|
//创建建站任务
|
|
|
|
$domain_create_model = new DomainCreateTask();
|
|
|
|
$domain_create_model->add([
|
|
|
|
'server_id' => $record_info['servers_id'],
|
|
|
|
'project_id' => $this->user['project_id'],
|
|
|
|
'domain_id' => $id,
|
|
|
|
'type' => DomainCreateTask::TYPE_BLOG
|
|
|
|
]);
|
|
|
|
//判断blog二级域名是否已经解析
|
|
|
|
if (!check_domain_record($blog_domain, $record_info)) {
|
|
|
|
$this->fail($blog_domain . '还未解析cname至' . $record);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('保存失败,请联系管理员');
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//保存一条主域名记录
|
|
|
|
$setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
|
|
|
|
if ($setting_info === false) {
|
|
|
|
$this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
|
|
|
|
} else {
|
|
|
|
$this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加域名到域名管理
|
|
|
|
$info = $domain_model->read(['domain' => $blog_domain]);
|
|
|
|
if ($info === false) {
|
|
|
|
$id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
|
|
|
|
|
|
|
|
//保存优化设置
|
|
|
|
$optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//保存项目ip
|
|
|
|
$project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//变更ip使用数量
|
|
|
|
$server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
|
|
|
|
$server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
|
|
|
|
|
|
|
|
//创建建站任务
|
|
|
|
$domain_create_model = new DomainCreateTask();
|
|
|
|
$domain_create_model->add([
|
|
|
|
'server_id' => $record_info['servers_id'],
|
|
|
|
'project_id' => $this->user['project_id'],
|
|
|
|
'domain_id' => $id,
|
|
|
|
'type' => DomainCreateTask::TYPE_BLOG
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('保存失败,请联系管理员');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//个人服务器
|
|
|
|
$ftp = $this->param['ftp'] ?? [];
|
|
|
|
if (empty($ftp) || empty($ftp['url']) || empty($ftp['username']) || empty($ftp['password']) || empty($ftp['port'])) {
|
|
|
|
$this->fail('ftp信息填写未完整');
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取自建站服务器详情
|
|
|
|
$record_info = $server_ip_model->read(['servers_id' => ServerConfig::SELF_SITE_ID], ['id', 'servers_id', 'total']);
|
|
|
|
if (!$record_info) {
|
|
|
|
$this->fail('解析记录不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//保存一条主域名记录
|
|
|
|
$setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
|
|
|
|
if ($setting_info === false) {
|
|
|
|
$this->model->add(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp), 'project_id' => $this->user['project_id']]);
|
|
|
|
} else {
|
|
|
|
$this->model->edit(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp)], ['id' => $setting_info['id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加域名到域名管理
|
|
|
|
$info = $domain_model->read(['domain' => $domain]);
|
|
|
|
if ($info === false) {
|
|
|
|
$id = $domain_model->addReturnId(['domain' => $domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
|
|
|
|
|
|
|
|
//保存优化设置
|
|
|
|
$optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//保存项目ip
|
|
|
|
$project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
|
|
|
|
|
|
|
|
//变更ip使用数量
|
|
|
|
$server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
|
|
|
|
$server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('保存失败,请联系管理员');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|