| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace common\models;
- use common\helpers\Cache;
- use Yii;
- /**
- * This is the model class for table "{{%CURRENCIES}}".
- *
- * @property string $ID
- * @property string $NAME 名字
- * @property string $CODE 简码
- * @property int $ACTIVE 状态
- * @property int $CREATED_AT 创建时间
- * @property int $UPDATED_AT 更新时间
- */
- class Currency extends \common\components\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%CURRENCIES}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['ID'], 'unique'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'NAME' => '币种',
- 'CODE' => '简码',
- 'ACTIVE' => '状态:1正常 0异常',
- 'CREATED_AT' => '创建时间',
- 'UPDATED_AT' => '更新时间',
- ];
- }
- /**
- * 从缓存获取信息
- * @return array|mixed|\yii\db\ActiveRecord[]
- */
- public static function getFromCache()
- {
- $data = Yii::$app->cache->get(Cache::CURRENCIES_KEY);
- if (!$data) {
- // 获取信息
- $data = static::find()->where('ACTIVE=1')->orderBy('ACTIVE DESC, ID ASC')->indexBy('ID')->asArray()->all();
- Yii::$app->cache->set(Cache::CURRENCIES_KEY, $data);
- }
- 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::CURRENCIES_KEY, $data);
- return $data;
- }
- /**
- * 通过ID获取
- * @param string $id
- * @return array|null
- */
- public static function getById(string $id): ?array
- {
- return self::findOneAsArray('ID=:ID', [':ID' => $id]);
- }
- }
|