Просмотр исходного кода

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

kevin 1 год назад
Родитель
Сommit
b662f9b880
2 измененных файлов с 20 добавлено и 5 удалено
  1. 11 0
      common/models/Countries.php
  2. 9 5
      common/models/forms/UserBasicForm.php

+ 11 - 0
common/models/Countries.php

@@ -102,4 +102,15 @@ class Countries extends \common\components\ActiveRecord
     {
         return self::findOneAsArray('ID=:ID', [':ID' => $id]);
     }
+
+    /**
+     * 通过ID查询币种.
+     * @param string $id
+     * @return int|mixed
+     */
+    public static function getCurrency(string $id)
+    {
+        $record = self::findOneAsArray('ID=:ID', [':ID' => $id]);
+        return $record['LOCAL_CURRENCY_ID'] ?? 0;
+    }
 }

+ 9 - 5
common/models/forms/UserBasicForm.php

@@ -9,6 +9,8 @@ use common\helpers\Form;
 use common\helpers\LoggerTool;
 use common\helpers\Tool;
 use common\libs\logging\operate\AdminOperate;
+use common\models\Countries;
+use common\models\Currency;
 use common\models\CurrencyConversions;
 use common\models\Instalment;
 use common\models\Period;
@@ -144,12 +146,14 @@ class UserBasicForm extends Model {
         $userModel = User::findOne(['ID' => $this->userId]);
         // 原国家
         $beforeCountry = $userModel->COUNTRY_ID;
+        $beforeCurrencyId = Countries::getCurrency($beforeCountry);
         // 移民前汇率
-        $beforeCurrency = CurrencyConversions::getToUSDRate($beforeCountry);
+        $beforeCurrencyRate = CurrencyConversions::getToUSDRate($beforeCurrencyId);
         // 移民后汇率
-        $afterCurrency = CurrencyConversions::getToUSDRate($this->country);
-        LoggerTool::debug(json_encode(['modifyProfile', $beforeCountry, $this->country, $afterCurrency]));
-        if (!$afterCurrency) {
+        $beforeCurrencyId = Countries::getCurrency($this->country);
+        $afterCurrencyRate = CurrencyConversions::getToUSDRate($beforeCurrencyId);
+        LoggerTool::debug(json_encode(['modifyProfile', $beforeCountry, $this->country, $afterCurrencyRate]));
+        if (!$afterCurrencyRate) {
             throw new Exception(Yii::t('app', 'currencyDoesNotExist'));
         }
         // 如果移民,则需要进行移民条件检查
@@ -187,7 +191,7 @@ class UserBasicForm extends Model {
             // 现金钱包余额转换
             $userWallet = UserWallet::findOne(['USER_ID' => $this->userId]);
             if ($userWallet && $userWallet->CASH > 0) {
-                $userWallet->CASH = Tool::convertAmount($userWallet->CASH, $beforeCurrency, $afterCurrency);
+                $userWallet->CASH = Tool::convertAmount($userWallet->CASH, $beforeCurrencyRate, $afterCurrencyRate);
                 if (!$userWallet->save()) {
                     $transaction->rollBack();
                     throw new Exception($userModel->getErrors());