ProjectCountryLogic.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
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
{
public function __construct()
{
parent::__construct();
$this->model = new CountryModel();
$this->param = $this->requestAll;
}
/**
* @name :(获取当前项目关联的多语言)get_country_info
* @author :lyh
* @method :post
* @time :2023/4/28 17:03
*/
public function country_info(){
$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);
}
/**
* @name :(更新多语言设置)country_edit
* @author :lyh
* @method :post
* @time :2023/4/28 17:42
*/
public function country_save(){
//处理数据
if(!isset($this->param['country_lists']) || empty($this->param['country_lists'])){
$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'];
$rs = $this->model->add($this->param);
}else{
$rs = $this->model->edit($this->param,['project_id'=>$this->user['project_id']]);
}
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)){
$country_lists = [];
}else{
//默认选中主语种
$country_lists = explode(',', $country_lists);
}
$main_lang_id = $this->project['main_lang_id'] ?? 1;
if (!in_array($main_lang_id, $country_lists)) {
$country_lists[] = $main_lang_id;
}
return implode(',', $country_lists);
}
protected function countrySortFormat($country_sort){
$webLanguageModel = new WebLanguage();
$idArr = $webLanguageModel->selectField(['id'=>['not in',explode(',',$country_sort)]],'id');
$countryStr = $country_sort.','.implode(',',$idArr);
return $countryStr;
}
}