作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

... ... @@ -12,9 +12,6 @@ namespace App\Http\Controllers\Bside\SeoSetting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\SeoSetting\DomainSettingLogic;
use App\Models\Domain\DomainInfo;
use App\Models\WebSetting\WebSetting;
use Illuminate\Http\Request;
/**
* @remark :白帽系统设置二级域名
... ... @@ -25,12 +22,6 @@ use Illuminate\Http\Request;
*/
class DomainSettingController extends BaseController
{
public function __construct(Request $request)
{
$this->model = new WebSetting();
parent::__construct($request);
}
/**
* @remark :获取当前二级域名详情
* @name :getInfo
... ... @@ -38,9 +29,10 @@ class DomainSettingController extends BaseController
* @method :post
* @time :2025/3/20 11:26
*/
public function getInfo(){
$data = $this->model->read(['project_id'=>$this->user['project_id']],['seo_domain']);
$this->response('success',Code::SUCCESS,$data);
public function getInfo(DomainSettingLogic $logic)
{
$data = $logic->infoDomain();
$this->response('success', Code::SUCCESS, $data);
}
/**
... ... @@ -50,13 +42,16 @@ class DomainSettingController extends BaseController
* @method :post
* @time :2025/3/20 11:29
*/
public function save(DomainSettingLogic $logic){
public function save(DomainSettingLogic $logic)
{
$this->request->validate([
'domain'=>['required'],
],[
'domain.required' => 'domain不能为空',
'domain' => ['required'],
'record' => ['required'],
], [
'domain.required' => '主域名不能为空',
'record.required' => '解析记录不能为空',
]);
$data = $logic->saveDomain();
$this->response('success',Code::SUCCESS,$data);
$this->response('success', Code::SUCCESS, $data);
}
}
... ...
... ... @@ -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();
}
... ...
... ... @@ -16,4 +16,5 @@ class DomainCreateTask extends Base
const TYPE_MAIN = 1;
const TYPE_AMP = 2;
const TYPE_CUSTOM = 3;
const TYPE_BLOG = 4;
}
... ...