|
...
|
...
|
@@ -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;
|
|
...
|
...
|
@@ -36,12 +38,16 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function infoDomain()
|
|
|
|
{
|
|
|
|
$domain = $record = '';
|
|
|
|
$domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_domain']);
|
|
|
|
if (isset($domain_info['seo_domain']) && $domain_info['seo_domain']) {
|
|
|
|
//已经绑定了主域名
|
|
|
|
$domain = $domain_info['seo_domain'];
|
|
|
|
//获取域名解析
|
|
|
|
$domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']);
|
|
|
|
$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) {
|
|
|
|
//已经绑定了主域名,获取域名解析
|
|
|
|
$project_model = new Project();
|
|
|
|
$project_info = $project_model->read(['id' => $this->user['project_id']], ['serve_id']);
|
|
|
|
|
|
...
|
...
|
@@ -51,16 +57,18 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
$record = $record_info ? $record_info['domain'] : '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//未绑定主域名
|
|
|
|
//未绑定主域名,分配域名解析
|
|
|
|
$record = Servers::where('init_domain', 'like', 'seo%')->where('being_number', '<', 10)->orderBy('being_number', 'desc')->orderBy('id', 'asc')->value('init_domain') ?? '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['domain' => $domain, 'record' => $record];
|
|
|
|
return ['type' => $type, 'domain' => $domain, 'record' => $record, 'ftp' => $ftp];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存设置
|
|
|
|
* @name :saveDomain
|
|
|
|
* @throws \App\Exceptions\AsideGlobalException
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/20 16:12
|
|
...
|
...
|
@@ -74,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']);
|
|
...
|
...
|
@@ -88,6 +89,23 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
$this->fail('获取项目数据失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
$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('解析记录不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取解析服务器详情
|
|
|
|
$record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
|
|
|
|
if (!$record_info) {
|
|
|
|
$this->fail('解析记录不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
//构建blog二级域名
|
|
|
|
$domain_array = explode('.', $domain);
|
|
|
|
if (count($domain_array) == 1) {
|
|
...
|
...
|
@@ -101,7 +119,7 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
|
|
|
|
//判断blog二级域名是否已经解析
|
|
|
|
if (!check_domain_record($blog_domain, $record_info)) {
|
|
|
|
$this->fail($blog_domain . '还未解析cname至' . $this->param['record']);
|
|
|
|
$this->fail($blog_domain . '还未解析cname至' . $record);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
...
|
...
|
@@ -109,19 +127,17 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
//保存一条主域名记录
|
|
|
|
$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']]);
|
|
|
|
$this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
|
|
|
|
} else {
|
|
|
|
$this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]);
|
|
|
|
$this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加域名到域名管理
|
|
|
|
$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
|
|
...
|
...
|
@@ -129,7 +145,6 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
|
|
|
|
//变更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']]);
|
|
|
|
|
|
|
|
//创建建站任务
|
|
...
|
...
|
@@ -147,5 +162,52 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
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();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|