ProjectCountryLogic.php
2.1 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
<?php
namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Project\Country as CountryModel;
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_lists'] = $this->countryListsFormat($lists['country_lists']);
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']);
$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('当前数据不存在');
}
return $this->success();
}
protected function countryListsFormat($country_lists)
{
//默认选中主语种
$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);
}
}