WebLanguage.php
2.9 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
<?php
/**
* @remark :
* @name :WebLanguage.php
* @author :lyh
* @method :post
* @time :2023/11/30 10:50
*/
namespace App\Models\WebSetting;
use App\Models\Base;
use App\Models\Project\CountryCustom;
use Illuminate\Support\Facades\Cache;
class WebLanguage extends Base
{
protected $table = 'gl_web_language';
/**
* 关键词17种语种
*/
public static function getKeywordsCountry($project = null)
{
$languageIds = [1,4,5,6,7,8,9,10,11,14,15,18,22,26,40,68,78,95,99];
//加入项目主语种
if (!empty($project)){
$mainLangId = $project->main_lang_id;
array_unshift($languageIds,(int)$mainLangId);
}
$projectId = $project->id;
$languageIds=array_unique($languageIds);
return WebLanguage::with(["countryCustom" => function($query) use ($projectId) {
$query->where('project_id', $projectId);
}])->whereIn("id",$languageIds)->get();
}
/**
* @param $id
* @return mixed
* @author zbj
* @date 2023/12/11
*/
public static function getLangById($id){
$cache_key = 'lang_'.$id;
$lang = Cache::get($cache_key);
if(!$lang){
$lang = self::find($id);
Cache::put($cache_key, $lang, 7200);
}
return $lang;
}
/**
* @param $lang
* @return mixed
* @author zbj
* @date 2023/12/11
*/
public static function getIdByLang($lang){
$cache_key = 'lang_id_'.$lang;
$id = Cache::get($cache_key);
if(!$id){
$id = self::where('short', $lang)->value('id');
Cache::put($cache_key, $id, 7200);
}
return $id;
}
/**
* 获取项目主语种
*/
public static function getProjectMainLang($mainLangId = 1)
{
$mainLang = self::find($mainLangId);
if (empty($mainLang)){
return null;
}
return $mainLang;
}
/**
* 关键词17种语种IDS
*/
public static function getKeywordsCountryIds($project = null): array
{
$languageIds = [1,4,5,6,7,8,9,10,11,14,15,18,22,26,40,68,78,95,99];
//加入项目主语种
if (!empty($project)){
$mainLangId = $project->main_lang_id;
array_unshift($languageIds,(int)$mainLangId);
}
return array_unique($languageIds);
}
/**
* 关联语种自定义跳转设置
*/
public function countryCustom(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(CountryCustom::class, 'language_id', 'id');
}
public static function getShorts(){
$key = 'language_shorts';
$list = Cache::get($key);
if (!$list) {
$list = self::pluck('short')->toArray();
if($list){
Cache::put($key, $list, 24 * 3600);
}
}
return $list;
}
}