|
|
@@ -48,8 +48,8 @@ class CurrencyConversions extends \common\components\ActiveRecord
|
|
|
return [
|
|
|
'ID' => 'ID',
|
|
|
'PERIOD_NUM' => '期数',
|
|
|
- 'FROM_CURRENCY_ID' => '源',
|
|
|
- 'TO_CURRENCY_ID' => '目标',
|
|
|
+ 'FROM_CURRENCY_ID' => '源币种',
|
|
|
+ 'TO_CURRENCY_ID' => '目标币种',
|
|
|
'PRODUCT_RATE' => '商品汇率',
|
|
|
'BONUSES_RATE' => '奖金汇率',
|
|
|
'ACTIVE' => '状态:1正常 0异常',
|
|
|
@@ -66,14 +66,19 @@ class CurrencyConversions extends \common\components\ActiveRecord
|
|
|
*/
|
|
|
public static function getFromCache()
|
|
|
{
|
|
|
- $data = Yii::$app->cache->get(Cache::CURRENCIES_CONVERSIONS_KEY);
|
|
|
- if (!$data) {
|
|
|
+ $records = Yii::$app->cache->get(Cache::CURRENCIES_CONVERSIONS_KEY);
|
|
|
+ if (!$records) {
|
|
|
// 获取信息
|
|
|
- $data = static::find()->where('ACTIVE=1')->orderBy('ID ASC')->indexBy('ID')->asArray()->all();
|
|
|
- Yii::$app->cache->set(Cache::CURRENCIES_CONVERSIONS_KEY, $data);
|
|
|
+ $records = self::getAllData();
|
|
|
+ Yii::$app->cache->set(Cache::CURRENCIES_CONVERSIONS_KEY, $records);
|
|
|
}
|
|
|
|
|
|
- return $data;
|
|
|
+ foreach ($records as &$record) {
|
|
|
+ $record['FROM_CURRENCY'] = Currency::getNameById($record['FROM_CURRENCY_ID']);
|
|
|
+ $record['TO_CURRENCY'] = Currency::getNameById($record['TO_CURRENCY_ID']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $records;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -91,7 +96,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
|
|
|
public static function updateToCache()
|
|
|
{
|
|
|
// 获取配置
|
|
|
- $data = static::find()->where('ACTIVE=1')->orderBy('ID ASC')->asArray()->indexBy('ID')->all();
|
|
|
+ $data = self::getAllData();
|
|
|
Yii::$app->cache->set(Cache::CURRENCIES_CONVERSIONS_KEY, $data);
|
|
|
return $data;
|
|
|
}
|
|
|
@@ -115,6 +120,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
|
|
|
* 查询汇率.
|
|
|
* @param int $fromCurrencyId
|
|
|
* @param int $toCurrencyId
|
|
|
+ * @param string $rateType
|
|
|
* @return mixed.
|
|
|
*/
|
|
|
public static function getRate(int $fromCurrencyId, int $toCurrencyId, string $rateType = 'product'): ?array
|
|
|
@@ -131,6 +137,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
|
|
|
/**
|
|
|
* 查询汇率.
|
|
|
* @param int $toCurrencyId
|
|
|
+ * @param string $rateType
|
|
|
* @return mixed.
|
|
|
*/
|
|
|
public static function getToUSDRate(int $toCurrencyId, string $rateType = 'product')
|