WebLanguage.php 1.7 KB
<?php
/**
 * @remark :
 * @name   :WebLanguage.php
 * @author :lyh
 * @method :post
 * @time   :2023/11/30 10:50
 */

namespace App\Models\WebSetting;

use App\Models\Base;
use Illuminate\Support\Facades\Cache;

class WebLanguage extends Base
{
    protected $table = 'gl_web_language';


    /**
     * @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);
    }

}