Przeglądaj źródła

feat: NG-15: 新会员注册时增加国家与语言选项.

kevin 1 rok temu
rodzic
commit
5714b9afdf
2 zmienionych plików z 26 dodań i 8 usunięć
  1. 11 0
      common/models/Currency.php
  2. 15 8
      common/models/CurrencyConversions.php

+ 11 - 0
common/models/Currency.php

@@ -95,4 +95,15 @@ class Currency extends \common\components\ActiveRecord
     {
         return self::findOneAsArray('ID=:ID', [':ID' => $id]);
     }
+
+    /**
+     * 通过ID获取
+     * @param string $id
+     * @return string|null
+     */
+    public static function getNameById(string $id): ?string
+    {
+        $record = self::findOneAsArray('ID=:ID', [':ID' => $id]);
+        return $record['NAME'] ?? '';
+    }
 }

+ 15 - 8
common/models/CurrencyConversions.php

@@ -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')