'ID', 'country_id' => '国家ID', 'freight' => '运费', 'free_shipping' => '免运费阈值', 'currency_id' => '币种ID', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } public function country() { return $this->hasOne(Countries::class, ['ID' => 'country_id']); } public function currency() { return $this->hasOne(Currency::class, ['ID' => 'currency_id']); } /** * 从缓存获取信息 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getFromCache() { $data = Yii::$app->cache->get(Cache::FREE_TEMPLATE_KEY); if (!$data) { // 获取信息 $data = static::find()->orderBy('id ASC')->indexBy('id')->asArray()->all(); Yii::$app->cache->set(Cache::FREE_TEMPLATE_KEY, $data); } return $data; } /** * @return array|\yii\db\ActiveRecord[] */ public static function getAllData() { return static::find()->indexBy('id')->orderBy('id ASC')->asArray()->all(); } /** * 更新缓存 * @return array|\yii\db\ActiveRecord[] */ public static function updateToCache() { // 获取配置 $data = static::find()->orderBy('id ASC')->asArray()->indexBy('id')->all(); Yii::$app->cache->set(Cache::FREE_TEMPLATE_KEY, $data); return $data; } /** * 通过$countryId获取 * @param string $countryId * @return array|null */ public static function getByCountryId(string $countryId): ?array { return self::findOneAsArray('country_id=:country_id', [':country_id' => $countryId]); } }