'ID', 'NAME' => '名字', 'CODE' => '简码', 'LOCAL_CURRENCY_ID' => '货币ID', 'DEFAULT_LANGUAGE_ID' => '语言ID', 'ACTIVE' => '状态:1正常 0异常', 'LANGUAGE_KEY' => '语言KEY', 'CREATED_AT' => '创建时间', 'UPDATED_AT' => '更新时间', ]; } /** * 从缓存获取信息 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getFromCache() { $data = Yii::$app->cache->get(Cache::COUNTRIES_KEY); if (!$data) { // 获取信息 $data = static::find()->orderBy('ACTIVE DESC, ID ASC')->indexBy('ID')->asArray()->all(); Yii::$app->cache->set(Cache::COUNTRIES_KEY, $data); } // i18n转换 foreach ($data as &$item) { $item['COUNTRY_NAME'] = Yii::t('ctx', $item['LANGUAGE_KEY']); } return $data; } /** * @return array|\yii\db\ActiveRecord[] */ public static function getAllData() { return static::find()->where('1=1')->indexBy('ID')->orderBy('ACTIVE DESC, ID ASC')->asArray()->all(); } /** * 更新缓存 * @return array|\yii\db\ActiveRecord[] */ public static function updateToCache() { // 获取配置 $data = static::find()->where('1=1')->orderBy('ACTIVE DESC, ID ASC')->asArray()->indexBy('ID')->all(); Yii::$app->cache->set(Cache::COUNTRIES_KEY, $data); return $data; } /** * 通过ID获取 * @param string $id * @return array|null */ public static function getById(string $id) { return self::findOneAsArray('ID=:ID', [':ID' => $id]); } }