|
...
|
...
|
@@ -10,8 +10,14 @@ |
|
|
|
namespace App\Http\Logic\Bside\SeoSetting;
|
|
|
|
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Devops\Servers;
|
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Project\DeployOptimize;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\WebSetting\WebSetting;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class DomainSettingLogic extends BaseLogic
|
|
|
|
{
|
|
...
|
...
|
@@ -19,6 +25,37 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
$this->model = new WebSetting();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取域名设置及目标解析记录
|
|
|
|
* @return array
|
|
|
|
* @author Akun
|
|
|
|
* @date 2025/03/21 10:09
|
|
|
|
*/
|
|
|
|
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'];
|
|
|
|
//获取域名解析
|
|
|
|
$project_model = new Project();
|
|
|
|
$project_info = $project_model->read(['project_id' => $this->user['project_id']], ['serve_id']);
|
|
|
|
|
|
|
|
if ($project_info) {
|
|
|
|
$server_model = new ServersIp();
|
|
|
|
$record_info = $server_model->read(['id' => $project_info['serve_id']], ['domain']);
|
|
|
|
$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];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -28,26 +65,73 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/20 16:12
|
|
|
|
*/
|
|
|
|
public function saveDomain(){
|
|
|
|
$domain = parse_url($this->param['domain'], PHP_URL_HOST);
|
|
|
|
if(!empty($domain)){
|
|
|
|
$this->param['domain'] = trim($domain['host']);
|
|
|
|
public function saveDomain()
|
|
|
|
{
|
|
|
|
//获取主域名
|
|
|
|
$domain_parse = parse_url(trim($this->param['domain']));
|
|
|
|
$domain = $domain_parse['host'] ?? $domain_parse['path'];
|
|
|
|
if (!$domain) {
|
|
|
|
$this->fail('主域名填写错误');
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取解析服务器详情
|
|
|
|
$server_model = new ServersIp();
|
|
|
|
$record_info = $server_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain']);
|
|
|
|
if (!$record_info) {
|
|
|
|
$this->fail('解析记录不存在');
|
|
|
|
}
|
|
|
|
//保存一条主域名记录
|
|
|
|
|
|
|
|
//获取项目详情
|
|
|
|
$project_model = new Project();
|
|
|
|
$project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);
|
|
|
|
if (!$project_info) {
|
|
|
|
$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);
|
|
|
|
|
|
|
|
//判断blog二级域名是否已经解析
|
|
|
|
if (!check_domain_record($blog_domain, $record_info)) {
|
|
|
|
$this->fail($blog_domain . '还未解析cname至' . $this->param['record']);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$this->saveWebSetting($this->param['domain']);
|
|
|
|
//保存一条主域名记录
|
|
|
|
$this->saveWebSetting($domain);
|
|
|
|
|
|
|
|
//添加域名到域名管理
|
|
|
|
$info = $this->model->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
if($info === false){
|
|
|
|
//保存数据
|
|
|
|
$this->param['domain'] = str_replace('www','blog',$this->param['domain']);
|
|
|
|
$id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);
|
|
|
|
$projectModel = new DeployOptimize();
|
|
|
|
$projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]);
|
|
|
|
}else{
|
|
|
|
$this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_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']]);
|
|
|
|
|
|
|
|
//创建建站任务
|
|
|
|
$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
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('保存失败,请联系管理员');
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -59,13 +143,13 @@ class DomainSettingLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/20 15:38
|
|
|
|
*/
|
|
|
|
public function saveWebSetting($domain){
|
|
|
|
$webSettingModel = new WebSetting();
|
|
|
|
$settingInfo = $webSettingModel->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
if($settingInfo === false){
|
|
|
|
$webSettingModel->add(['seo_domain'=>$domain,'project_id'=>$this->user['project_id']]);
|
|
|
|
}else{
|
|
|
|
$webSettingModel->edit(['seo_domain'=>$domain],['id'=>$settingInfo['id']]);
|
|
|
|
public function saveWebSetting($domain)
|
|
|
|
{
|
|
|
|
$settingInfo = $this->model->read(['project_id' => $this->user['project_id']]);
|
|
|
|
if ($settingInfo === false) {
|
|
|
|
$this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
|
|
|
|
} else {
|
|
|
|
$this->model->edit(['seo_domain' => $domain], ['id' => $settingInfo['id']]);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
...
|
...
|
|