作者 lyh
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside\Setting; @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside\Setting;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Controllers\Bside\BaseController; 6 use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Aside\Domain\DomainInfoLogic;
7 use App\Http\Logic\Bside\Setting\ProjectCountryLogic; 8 use App\Http\Logic\Bside\Setting\ProjectCountryLogic;
8 9
9 /** 10 /**
@@ -32,4 +33,59 @@ class ProjectCountryController extends BaseController @@ -32,4 +33,59 @@ class ProjectCountryController extends BaseController
32 $projectCountryLogic->country_save(); 33 $projectCountryLogic->country_save();
33 $this->response('success'); 34 $this->response('success');
34 } 35 }
  36 +
  37 + /**
  38 + * 设置语种自定义跳转链接
  39 + * @param DomainInfoLogic $domainInfoLogic
  40 + * @author Akun
  41 + * @date 2024/03/05 9:47
  42 + */
  43 + public function custom_save(DomainInfoLogic $domainInfoLogic){
  44 + $this->request->validate([
  45 + 'language_id'=>'required',
  46 + 'custom_domain'=>'required',
  47 + 'is_create'=>'required'
  48 + ],[
  49 + 'language_id.required' => 'language_id不能为空',
  50 + 'custom_domain.required' => 'custom_domain不能为空',
  51 + 'is_create.required' => 'is_create不能为空'
  52 + ]);
  53 + $domainInfoLogic->country_custom($this->user['project_id']);
  54 + $this->response('success');
  55 + }
  56 +
  57 +
  58 + /**
  59 + * 清除语种自定义跳转链接
  60 + * @param ProjectCountryLogic $projectCountryLogic
  61 + * @author Akun
  62 + * @date 2024/03/05 10:20
  63 + */
  64 + public function custom_del(ProjectCountryLogic $projectCountryLogic){
  65 + $this->request->validate([
  66 + 'language_id'=>'required'
  67 + ],[
  68 + 'language_id.required' => 'language_id不能为空'
  69 + ]);
  70 +
  71 + $projectCountryLogic->country_custom_del();
  72 + $this->response('success');
  73 + }
  74 +
  75 + /**
  76 + * 获取语种自定义跳转链接详情
  77 + * @param ProjectCountryLogic $projectCountryLogic
  78 + * @author Akun
  79 + * @date 2024/03/06 14:37
  80 + */
  81 + public function custom_info(ProjectCountryLogic $projectCountryLogic){
  82 + $this->request->validate([
  83 + 'language_id'=>'required'
  84 + ],[
  85 + 'language_id.required' => 'language_id不能为空'
  86 + ]);
  87 +
  88 + $info = $projectCountryLogic->country_custom_info();
  89 + $this->response('success',Code::SUCCESS,$info);
  90 + }
35 } 91 }
@@ -6,6 +6,7 @@ namespace App\Http\Logic\Aside\Domain; @@ -6,6 +6,7 @@ namespace App\Http\Logic\Aside\Domain;
6 use App\Http\Logic\Aside\BaseLogic; 6 use App\Http\Logic\Aside\BaseLogic;
7 use App\Models\Devops\ServerConfig; 7 use App\Models\Devops\ServerConfig;
8 use App\Models\Domain\DomainInfo; 8 use App\Models\Domain\DomainInfo;
  9 +use App\Models\Project\CountryCustom;
9 use App\Models\Project\DeployOptimize; 10 use App\Models\Project\DeployOptimize;
10 use App\Models\Project\Project; 11 use App\Models\Project\Project;
11 use App\Utils\HttpUtils; 12 use App\Utils\HttpUtils;
@@ -350,4 +351,68 @@ class DomainInfoLogic extends BaseLogic @@ -350,4 +351,68 @@ class DomainInfoLogic extends BaseLogic
350 } 351 }
351 return false; 352 return false;
352 } 353 }
  354 +
  355 + /**
  356 + * 设置语种自定义跳转链接
  357 + * @param $project_id
  358 + * @return array
  359 + * @author Akun
  360 + * @date 2024/03/05 9:48
  361 + */
  362 + public function country_custom($project_id){
  363 + $project_model = new Project();
  364 + $project_info = $project_model->read(['id'=>$project_id],'serve_id');
  365 + if($project_info === false){
  366 + $this->fail('获取项目数据失败');
  367 + }
  368 +
  369 + $custom_model = new CountryCustom();
  370 + if($this->param['is_create']){
  371 + //需要创建站点
  372 + $server_model = new ServerConfig();
  373 + $server_info = $server_model->read(['id'=>$project_info['serve_id']],['init_domain', 'host']);
  374 + if($server_info === false){
  375 + $this->fail('获取服务器数据失败');
  376 + }
  377 +
  378 + //域名是否都已经解析
  379 + if(strpos($this->param['custom_domain'],'//') === false){
  380 + $this->param['custom_domain'] = '//'.$this->param['custom_domain'];
  381 + }
  382 + $domain_arr = parse_url($this->param['custom_domain']);
  383 + if(!isset($domain_arr['host'])){
  384 + $this->fail('自定义域名填写错误');
  385 + }
  386 + $this->param['custom_domain'] = $domain_arr['host'];
  387 + //判断域名是否已经被使用
  388 + $has_info = $custom_model->read(['custom_domain'=>$this->param['custom_domain']]);
  389 + if($has_info && ($has_info['project_id'] != $project_id || $has_info['language_id'] != $this->param['language_id'])){
  390 + $this->fail('自定义域名已被使用');
  391 + }
  392 + if(!$this->check_cname($this->param['custom_domain'], $server_info)){
  393 + $this->fail('域名' . $this->param['custom_domain'] . '未解析至目标服务器');
  394 + }
  395 + }else{
  396 + $this->param['custom_domain'] = str_replace('https://','',$this->param['custom_domain']);
  397 + $this->param['custom_domain'] = str_replace('http://','',$this->param['custom_domain']);
  398 + $this->param['custom_domain'] = str_replace('//','',$this->param['custom_domain']);
  399 + }
  400 +
  401 + $info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]);
  402 + if($info === false){
  403 + $this->param['project_id'] = $project_id;
  404 + $custom_model->add($this->param);
  405 + }else{
  406 + $custom_model->edit($this->param,['id'=>$info['id']]);
  407 + }
  408 +
  409 + if($this->param['is_create']){
  410 + //创建站点,设置证书
  411 + $this->param['key'] = $this->param['private_key'] ?? '';
  412 + $this->param['cert'] = $this->param['private_cert'] ?? '';
  413 + $this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],0);
  414 + }
  415 +
  416 + return $this->success();
  417 + }
353 } 418 }
@@ -4,6 +4,8 @@ namespace App\Http\Logic\Bside\Setting; @@ -4,6 +4,8 @@ namespace App\Http\Logic\Bside\Setting;
4 4
5 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
6 use App\Models\Project\Country as CountryModel; 6 use App\Models\Project\Country as CountryModel;
  7 +use App\Models\Project\CountryCustom;
  8 +use App\Models\WebSetting\WebLanguage;
7 9
8 class ProjectCountryLogic extends BaseLogic 10 class ProjectCountryLogic extends BaseLogic
9 { 11 {
@@ -24,8 +26,11 @@ class ProjectCountryLogic extends BaseLogic @@ -24,8 +26,11 @@ class ProjectCountryLogic extends BaseLogic
24 $lists = $this->model->read(['project_id'=>$this->user['project_id']]); 26 $lists = $this->model->read(['project_id'=>$this->user['project_id']]);
25 if (empty($lists)){ 27 if (empty($lists)){
26 $lists['country_lists'] = ''; 28 $lists['country_lists'] = '';
  29 + $lists['country_sort'] = '';
27 } 30 }
28 $lists['country_lists'] = $this->countryListsFormat($lists['country_lists']); 31 $lists['country_lists'] = $this->countryListsFormat($lists['country_lists']);
  32 + $lists['country_sort'] = $this->countrySortFormat($lists['country_sort']);
  33 +
29 return $this->success($lists); 34 return $this->success($lists);
30 } 35 }
31 36
@@ -41,6 +46,12 @@ class ProjectCountryLogic extends BaseLogic @@ -41,6 +46,12 @@ class ProjectCountryLogic extends BaseLogic
41 $this->param['country_lists'] = ''; 46 $this->param['country_lists'] = '';
42 } 47 }
43 $this->param['country_lists'] = $this->countryListsFormat($this->param['country_lists']); 48 $this->param['country_lists'] = $this->countryListsFormat($this->param['country_lists']);
  49 +
  50 + if(!isset($this->param['country_sort']) || empty($this->param['country_sort'])){
  51 + $this->param['country_sort'] = '';
  52 + }
  53 + $this->param['country_sort'] = $this->countrySortFormat($this->param['country_sort']);
  54 +
44 $info = $this->model->read(['project_id'=>$this->user['project_id']]); 55 $info = $this->model->read(['project_id'=>$this->user['project_id']]);
45 if($info === false){ 56 if($info === false){
46 $this->param['project_id'] = $this->user['project_id']; 57 $this->param['project_id'] = $this->user['project_id'];
@@ -51,9 +62,45 @@ class ProjectCountryLogic extends BaseLogic @@ -51,9 +62,45 @@ class ProjectCountryLogic extends BaseLogic
51 if($rs === false){ 62 if($rs === false){
52 $this->fail('当前数据不存在'); 63 $this->fail('当前数据不存在');
53 } 64 }
  65 +
  66 + $custom_model = new CountryCustom();
  67 + //将未勾选的设置了自定义跳转的语种,置为不可用
  68 + $custom_model->edit(['status'=>0],['project_id'=>$this->user['project_id'],'language_id'=>['not in',explode(',',$this->param['country_lists'])]]);
  69 + //将勾选的设置了自定义跳转的语种,置为可用
  70 + $custom_model->edit(['status'=>1],['project_id'=>$this->user['project_id'],'language_id'=>['in',explode(',',$this->param['country_lists'])]]);
  71 +
54 return $this->success(); 72 return $this->success();
55 } 73 }
56 74
  75 + /**
  76 + * 删除语种自定义跳转
  77 + * @return array
  78 + * @author Akun
  79 + * @date 2024/03/05 10:18
  80 + */
  81 + public function country_custom_del(){
  82 + $custom_model = new CountryCustom();
  83 + $rs = $custom_model->del(['project_id'=>$this->user['project_id'],'language_id'=>$this->param['language_id']]);
  84 + if($rs === false){
  85 + $this->fail('error');
  86 + }
  87 +
  88 + return $this->success();
  89 + }
  90 +
  91 + /**
  92 + * 获取语种自定义跳转详情
  93 + * @return array|bool
  94 + * @author Akun
  95 + * @date 2024/03/06 14:38
  96 + */
  97 + public function country_custom_info(){
  98 + $custom_model = new CountryCustom();
  99 + $info = $custom_model->read(['project_id'=>$this->user['project_id'],'language_id'=>$this->param['language_id']],['language_id','custom_domain','is_create','type','private_key','private_cert']);
  100 +
  101 + return $this->success($info?:[]);
  102 + }
  103 +
57 protected function countryListsFormat($country_lists) 104 protected function countryListsFormat($country_lists)
58 { 105 {
59 if(empty($country_lists)){ 106 if(empty($country_lists)){
@@ -68,4 +115,14 @@ class ProjectCountryLogic extends BaseLogic @@ -68,4 +115,14 @@ class ProjectCountryLogic extends BaseLogic
68 } 115 }
69 return implode(',', $country_lists); 116 return implode(',', $country_lists);
70 } 117 }
  118 +
  119 + protected function countrySortFormat($country_sort){
  120 + if(empty($country_sort)){
  121 + $webLanguageModel = new WebLanguage();
  122 + $all_language_ids = array_column($webLanguageModel->list([],'id',['id'],'asc'),'id');
  123 + $country_sort = implode(',',$all_language_ids);
  124 + }
  125 +
  126 + return $country_sort;
  127 + }
71 } 128 }
@@ -28,11 +28,15 @@ class WebSettingAmpLogic extends BaseLogic @@ -28,11 +28,15 @@ class WebSettingAmpLogic extends BaseLogic
28 return $this->success(); 28 return $this->success();
29 } 29 }
30 //log图处理 30 //log图处理
31 - $info['top_logo'] = getImageUrl($info['top_logo'],$this->user['storage_type'],$this->user['project_location']); 31 + $info['top_logo'] = Arr::s2a($info['top_logo']);
  32 + if(!empty($info['top_logo'])){
  33 + $info['top_logo']['url'] = getImageUrl($info['top_logo']['url'], $this->user['storage_type'], $this->user['project_location']);
  34 + }
32 //banner处理 35 //banner处理
  36 + $info['index_banner'] = Arr::s2a($info['index_banner']);
33 if (!empty($info['index_banner'])) { 37 if (!empty($info['index_banner'])) {
34 foreach ($info['index_banner'] as &$v) { 38 foreach ($info['index_banner'] as &$v) {
35 - $v = getImageUrl($v,$this->user['storage_type'],$this->user['project_location']); 39 + $v['url'] = getImageUrl($v['url'], $this->user['storage_type'], $this->user['project_location']);
36 } 40 }
37 } 41 }
38 return $this->success($info); 42 return $this->success($info);
@@ -48,12 +52,16 @@ class WebSettingAmpLogic extends BaseLogic @@ -48,12 +52,16 @@ class WebSettingAmpLogic extends BaseLogic
48 { 52 {
49 try { 53 try {
50 //log图处理 54 //log图处理
51 - $this->param['top_logo'] = str_replace_url($this->param['top_logo'] ?? ''); 55 + if (isset($this->param['top_logo']) && $this->param['top_logo']) {
  56 + $this->param['top_logo']['url'] = str_replace_url($this->param['top_logo']['url'] ?? '');
  57 + }
  58 + $this->param['top_logo'] = Arr::a2s($this->param['top_logo'] ?? []);
52 //banner处理 59 //banner处理
53 $index_banner = []; 60 $index_banner = [];
54 if (isset($this->param['index_banner']) && $this->param['index_banner']) { 61 if (isset($this->param['index_banner']) && $this->param['index_banner']) {
55 foreach ($this->param['index_banner'] as $v) { 62 foreach ($this->param['index_banner'] as $v) {
56 - $index_banner[] = str_replace_url($v); 63 + $v['url'] = str_replace_url($v['url'] ?? '');
  64 + $index_banner[] = $v;
57 } 65 }
58 } 66 }
59 $this->param['index_banner'] = Arr::a2s($index_banner); 67 $this->param['index_banner'] = Arr::a2s($index_banner);
  1 +<?php
  2 +
  3 +namespace App\Models\Project;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class CountryCustom extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + protected $table = 'gl_project_country_custom';
  13 +}
@@ -168,6 +168,9 @@ Route::middleware(['bloginauth'])->group(function () { @@ -168,6 +168,9 @@ Route::middleware(['bloginauth'])->group(function () {
168 Route::prefix('country')->group(function () { 168 Route::prefix('country')->group(function () {
169 Route::any('/info', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'info'])->name('web_setting_country_info'); 169 Route::any('/info', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'info'])->name('web_setting_country_info');
170 Route::any('/save', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'save'])->name('web_setting_country_save'); 170 Route::any('/save', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'save'])->name('web_setting_country_save');
  171 + Route::any('/custom_save', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_save'])->name('web_setting_country_custom_save');
  172 + Route::any('/custom_del', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_del'])->name('web_setting_country_custom_del');
  173 + Route::any('/custom_info', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_info'])->name('web_setting_country_custom_info');
171 }); 174 });
172 //客服设置 175 //客服设置
173 Route::prefix('service')->group(function () { 176 Route::prefix('service')->group(function () {