作者 lyh
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Http\Logic\Bside\Setting\ProjectCountryLogic;
/**
... ... @@ -32,4 +33,59 @@ class ProjectCountryController extends BaseController
$projectCountryLogic->country_save();
$this->response('success');
}
/**
* 设置语种自定义跳转链接
* @param DomainInfoLogic $domainInfoLogic
* @author Akun
* @date 2024/03/05 9:47
*/
public function custom_save(DomainInfoLogic $domainInfoLogic){
$this->request->validate([
'language_id'=>'required',
'custom_domain'=>'required',
'is_create'=>'required'
],[
'language_id.required' => 'language_id不能为空',
'custom_domain.required' => 'custom_domain不能为空',
'is_create.required' => 'is_create不能为空'
]);
$domainInfoLogic->country_custom($this->user['project_id']);
$this->response('success');
}
/**
* 清除语种自定义跳转链接
* @param ProjectCountryLogic $projectCountryLogic
* @author Akun
* @date 2024/03/05 10:20
*/
public function custom_del(ProjectCountryLogic $projectCountryLogic){
$this->request->validate([
'language_id'=>'required'
],[
'language_id.required' => 'language_id不能为空'
]);
$projectCountryLogic->country_custom_del();
$this->response('success');
}
/**
* 获取语种自定义跳转链接详情
* @param ProjectCountryLogic $projectCountryLogic
* @author Akun
* @date 2024/03/06 14:37
*/
public function custom_info(ProjectCountryLogic $projectCountryLogic){
$this->request->validate([
'language_id'=>'required'
],[
'language_id.required' => 'language_id不能为空'
]);
$info = $projectCountryLogic->country_custom_info();
$this->response('success',Code::SUCCESS,$info);
}
}
... ...
... ... @@ -6,6 +6,7 @@ namespace App\Http\Logic\Aside\Domain;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
use App\Models\Project\CountryCustom;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
... ... @@ -350,4 +351,68 @@ class DomainInfoLogic extends BaseLogic
}
return false;
}
/**
* 设置语种自定义跳转链接
* @param $project_id
* @return array
* @author Akun
* @date 2024/03/05 9:48
*/
public function country_custom($project_id){
$project_model = new Project();
$project_info = $project_model->read(['id'=>$project_id],'serve_id');
if($project_info === false){
$this->fail('获取项目数据失败');
}
$custom_model = new CountryCustom();
if($this->param['is_create']){
//需要创建站点
$server_model = new ServerConfig();
$server_info = $server_model->read(['id'=>$project_info['serve_id']],['init_domain', 'host']);
if($server_info === false){
$this->fail('获取服务器数据失败');
}
//域名是否都已经解析
if(strpos($this->param['custom_domain'],'//') === false){
$this->param['custom_domain'] = '//'.$this->param['custom_domain'];
}
$domain_arr = parse_url($this->param['custom_domain']);
if(!isset($domain_arr['host'])){
$this->fail('自定义域名填写错误');
}
$this->param['custom_domain'] = $domain_arr['host'];
//判断域名是否已经被使用
$has_info = $custom_model->read(['custom_domain'=>$this->param['custom_domain']]);
if($has_info && ($has_info['project_id'] != $project_id || $has_info['language_id'] != $this->param['language_id'])){
$this->fail('自定义域名已被使用');
}
if(!$this->check_cname($this->param['custom_domain'], $server_info)){
$this->fail('域名' . $this->param['custom_domain'] . '未解析至目标服务器');
}
}else{
$this->param['custom_domain'] = str_replace('https://','',$this->param['custom_domain']);
$this->param['custom_domain'] = str_replace('http://','',$this->param['custom_domain']);
$this->param['custom_domain'] = str_replace('//','',$this->param['custom_domain']);
}
$info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]);
if($info === false){
$this->param['project_id'] = $project_id;
$custom_model->add($this->param);
}else{
$custom_model->edit($this->param,['id'=>$info['id']]);
}
if($this->param['is_create']){
//创建站点,设置证书
$this->param['key'] = $this->param['private_key'] ?? '';
$this->param['cert'] = $this->param['private_cert'] ?? '';
$this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],0);
}
return $this->success();
}
}
... ...
... ... @@ -4,6 +4,8 @@ namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Project\Country as CountryModel;
use App\Models\Project\CountryCustom;
use App\Models\WebSetting\WebLanguage;
class ProjectCountryLogic extends BaseLogic
{
... ... @@ -24,8 +26,11 @@ class ProjectCountryLogic extends BaseLogic
$lists = $this->model->read(['project_id'=>$this->user['project_id']]);
if (empty($lists)){
$lists['country_lists'] = '';
$lists['country_sort'] = '';
}
$lists['country_lists'] = $this->countryListsFormat($lists['country_lists']);
$lists['country_sort'] = $this->countrySortFormat($lists['country_sort']);
return $this->success($lists);
}
... ... @@ -41,6 +46,12 @@ class ProjectCountryLogic extends BaseLogic
$this->param['country_lists'] = '';
}
$this->param['country_lists'] = $this->countryListsFormat($this->param['country_lists']);
if(!isset($this->param['country_sort']) || empty($this->param['country_sort'])){
$this->param['country_sort'] = '';
}
$this->param['country_sort'] = $this->countrySortFormat($this->param['country_sort']);
$info = $this->model->read(['project_id'=>$this->user['project_id']]);
if($info === false){
$this->param['project_id'] = $this->user['project_id'];
... ... @@ -51,9 +62,45 @@ class ProjectCountryLogic extends BaseLogic
if($rs === false){
$this->fail('当前数据不存在');
}
$custom_model = new CountryCustom();
//将未勾选的设置了自定义跳转的语种,置为不可用
$custom_model->edit(['status'=>0],['project_id'=>$this->user['project_id'],'language_id'=>['not in',explode(',',$this->param['country_lists'])]]);
//将勾选的设置了自定义跳转的语种,置为可用
$custom_model->edit(['status'=>1],['project_id'=>$this->user['project_id'],'language_id'=>['in',explode(',',$this->param['country_lists'])]]);
return $this->success();
}
/**
* 删除语种自定义跳转
* @return array
* @author Akun
* @date 2024/03/05 10:18
*/
public function country_custom_del(){
$custom_model = new CountryCustom();
$rs = $custom_model->del(['project_id'=>$this->user['project_id'],'language_id'=>$this->param['language_id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* 获取语种自定义跳转详情
* @return array|bool
* @author Akun
* @date 2024/03/06 14:38
*/
public function country_custom_info(){
$custom_model = new CountryCustom();
$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']);
return $this->success($info?:[]);
}
protected function countryListsFormat($country_lists)
{
if(empty($country_lists)){
... ... @@ -68,4 +115,14 @@ class ProjectCountryLogic extends BaseLogic
}
return implode(',', $country_lists);
}
protected function countrySortFormat($country_sort){
if(empty($country_sort)){
$webLanguageModel = new WebLanguage();
$all_language_ids = array_column($webLanguageModel->list([],'id',['id'],'asc'),'id');
$country_sort = implode(',',$all_language_ids);
}
return $country_sort;
}
}
... ...
... ... @@ -28,11 +28,15 @@ class WebSettingAmpLogic extends BaseLogic
return $this->success();
}
//log图处理
$info['top_logo'] = getImageUrl($info['top_logo'],$this->user['storage_type'],$this->user['project_location']);
$info['top_logo'] = Arr::s2a($info['top_logo']);
if(!empty($info['top_logo'])){
$info['top_logo']['url'] = getImageUrl($info['top_logo']['url'], $this->user['storage_type'], $this->user['project_location']);
}
//banner处理
$info['index_banner'] = Arr::s2a($info['index_banner']);
if (!empty($info['index_banner'])) {
foreach ($info['index_banner'] as &$v) {
$v = getImageUrl($v,$this->user['storage_type'],$this->user['project_location']);
$v['url'] = getImageUrl($v['url'], $this->user['storage_type'], $this->user['project_location']);
}
}
return $this->success($info);
... ... @@ -48,12 +52,16 @@ class WebSettingAmpLogic extends BaseLogic
{
try {
//log图处理
$this->param['top_logo'] = str_replace_url($this->param['top_logo'] ?? '');
if (isset($this->param['top_logo']) && $this->param['top_logo']) {
$this->param['top_logo']['url'] = str_replace_url($this->param['top_logo']['url'] ?? '');
}
$this->param['top_logo'] = Arr::a2s($this->param['top_logo'] ?? []);
//banner处理
$index_banner = [];
if (isset($this->param['index_banner']) && $this->param['index_banner']) {
foreach ($this->param['index_banner'] as $v) {
$index_banner[] = str_replace_url($v);
$v['url'] = str_replace_url($v['url'] ?? '');
$index_banner[] = $v;
}
}
$this->param['index_banner'] = Arr::a2s($index_banner);
... ...
<?php
namespace App\Models\Project;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
class CountryCustom extends Base
{
use SoftDeletes;
protected $table = 'gl_project_country_custom';
}
... ...
... ... @@ -168,6 +168,9 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('country')->group(function () {
Route::any('/info', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'info'])->name('web_setting_country_info');
Route::any('/save', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'save'])->name('web_setting_country_save');
Route::any('/custom_save', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_save'])->name('web_setting_country_custom_save');
Route::any('/custom_del', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_del'])->name('web_setting_country_custom_del');
Route::any('/custom_info', [\App\Http\Controllers\Bside\Setting\ProjectCountryController::class, 'custom_info'])->name('web_setting_country_custom_info');
});
//客服设置
Route::prefix('service')->group(function () {
... ...