Эх сурвалжийг харах

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

kevin 1 жил өмнө
parent
commit
8e63c7d801

+ 8 - 6
common/models/CurrencyConversions.php

@@ -12,7 +12,8 @@ use Yii;
  * @property int PERIOD_NUM 期数
  * @property int FROM_CURRENCY_ID 源
  * @property int TO_CURRENCY_ID 目标
- * @property double RATE 汇率
+ * @property double PRODUCT_RATE 商品汇率
+ * @property double BONUSES_RATE 奖金汇率
  * @property int ACTIVE 状态
  * @property int CREATED_AT 创建时间
  * @property int UPDATED_AT 更新时间
@@ -49,7 +50,8 @@ class CurrencyConversions extends \common\components\ActiveRecord
             'PERIOD_NUM' => '期数',
             'FROM_CURRENCY_ID' => '源',
             'TO_CURRENCY_ID' => '目标',
-            'RATE' => '汇率',
+            'PRODUCT_RATE' => '商品汇率',
+            'BONUSES_RATE' => '奖金汇率',
             'ACTIVE' => '状态:1正常 0异常',
             'CREATED_AT' => '创建时间',
             'UPDATED_AT' => '更新时间',
@@ -115,7 +117,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
      * @param int $toCurrencyId
      * @return mixed.
      */
-    public static function getRate(int $fromCurrencyId, int $toCurrencyId): ?array
+    public static function getRate(int $fromCurrencyId, int $toCurrencyId, string $rateType = 'product'): ?array
     {
         $data = self::findOneAsArray('FROM_CURRENCY_ID=:FROM_CURRENCY_ID AND TO_CURRENCY_ID=:TO_CURRENCY_ID AND ACTIVE=1',
             [
@@ -123,7 +125,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
                 ':TO_CURRENCY_ID' => $toCurrencyId,
             ]);
 
-        return $data['RATE'] ?? 0.0;
+        return $rateType == 'product' ? ($data['PRODUCT_RATE'] ?? 0.0) : ($data['BONUSES_RATE'] ?? 0.0);
     }
 
     /**
@@ -131,7 +133,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
      * @param int $toCurrencyId
      * @return mixed.
      */
-    public static function getToUSDRate(int $toCurrencyId)
+    public static function getToUSDRate(int $toCurrencyId, string $rateType = 'product')
     {
         $data = self::findOneAsArray('FROM_CURRENCY_ID=:FROM_CURRENCY_ID AND TO_CURRENCY_ID=:TO_CURRENCY_ID AND ACTIVE=1',
             [
@@ -139,7 +141,7 @@ class CurrencyConversions extends \common\components\ActiveRecord
                 ':TO_CURRENCY_ID' => $toCurrencyId,
             ]);
 
-        return $data['RATE'] ?? 0.0;
+        return $rateType == 'product' ? ($data['PRODUCT_RATE'] ?? 0.0) : ($data['BONUSES_RATE'] ?? 0.0);
     }
 
     public static function updateOne(int $fromCurrencyId, int $toCurrencyId): bool

+ 11 - 8
common/models/forms/CurrenciesConversionsForm.php

@@ -23,7 +23,8 @@ class CurrenciesConversionsForm extends Model
 
     public $from_currency_id;
     public $to_currency_id;
-    public $rate;
+    public $product_rate;
+    public $bonuses_rate;
     public $synchronize;
 
     private $period;
@@ -43,7 +44,7 @@ class CurrenciesConversionsForm extends Model
     public function rules()
     {
         return [
-            [['from_currency_id', 'to_currency_id', 'rate'], 'required'],
+            [['from_currency_id', 'to_currency_id', 'product_rate', 'bonuses_rate'], 'required'],
         ];
     }
 
@@ -52,7 +53,8 @@ class CurrenciesConversionsForm extends Model
         return [
             'from_currency_id' => 'From Currency Name', // 源汇率
             'to_currency_id' => 'To Currency Name', // 目标汇率
-            'rate' => 'Rate', // 汇率
+            'product_rate' => 'Product Rate', // 商品汇率
+            'bonuses_rate' => 'Bonuses_rate Rate', // 奖金汇率
         ];
     }
 
@@ -64,7 +66,7 @@ class CurrenciesConversionsForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'setCurrenciesConversions' => ['from_currency_id', 'to_currency_id', 'rate'],
+            'setCurrenciesConversions' => ['from_currency_id', 'to_currency_id', 'product_rate', 'bonuses_rate'],
         ];
 
         return array_merge($parentScenarios, $customScenarios);
@@ -94,16 +96,17 @@ class CurrenciesConversionsForm extends Model
             $model->PERIOD_NUM = $this->period->getNowPeriodNum();
             $model->FROM_CURRENCY_ID = $this->from_currency_id;
             $model->TO_CURRENCY_ID = $this->to_currency_id;
-            $model->RATE = $this->rate;
+            $model->PRODUCT_RATE = $this->product_rate;
+            $model->BONUSES_RATE = $this->bonuses_rate;
             $model->ACTIVE = StatusEnum::ACTIVE;
             $model->CREATED_AT = Date::nowTime();
-            $model->CREATED_BY = $this->goodsNo;
+            $model->CREATED_BY = \Yii::$app->user->id;;
             if (!$model->save()) {
                 throw new Exception(Form::formatErrorsForApi($model->getErrors()));
             }
 
-            // 选择商品汇率同步,并且美元汇率变化时,更新商品属性
-            if ($postData['synchronize'] && (($this->from_currency_id == 104) || ($this->to_currency_id == 104))) {
+            // 选择商品汇率同步,更新商品属性
+            if ($postData['synchronize']) {
                 // 异步属性商品价格
                 $taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle('config/update-exchange-rate', $model->ID);
                 if($taskKey === false){

+ 1 - 1
common/models/forms/ShopGoodsForm.php

@@ -350,7 +350,7 @@ class ShopGoodsForm extends Model
                 // 商品
                 $shopGoods = ShopGoods::findOne(['ID' => $goodsNature->GOODS_ID]);
                 // 刷新销售价格
-                $goodsNature->SELL_PRICE = $shopGoods->SELL_PRICE_STANDARD * $currencyConversions->RATE;
+                $goodsNature->SELL_PRICE = $shopGoods->SELL_PRICE_STANDARD * $currencyConversions->PRODUCT_RATE;
                 if (!$goodsNature->save()) {
                     $transaction->rollBack();
                     throw new Exception(Form::formatErrorsForApi($goodsNature->getErrors()));