Quellcode durchsuchen

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

zhangl vor 1 Jahr
Ursprung
Commit
3a164bb95f
1 geänderte Dateien mit 64 neuen und 11 gelöschten Zeilen
  1. 64 11
      common/models/forms/OrderForm.php

+ 64 - 11
common/models/forms/OrderForm.php

@@ -503,6 +503,7 @@ class OrderForm extends Model
                         $realPv = $goods['PRICE_PV'] * $discount;
                         $realPriceStandard = $goods['SELL_PRICE_STANDARD'] * $discount;
                     }
+
                     if($goods['PV_SPLIT']==1){ // 当商品为PV分期时
                         $pvSplit = $this->_pvSplit($realPv);
                         $currentPv = $pvSplit['current'];
@@ -830,16 +831,34 @@ class OrderForm extends Model
         $ids = $this->goodsId;
         $totalAmount = 0;
         $totalPv = 0;
+        $totalRealPv = 0;
+        $totalAmountStandard = 0;
+
         $goodsType = ShopGoods::getGoodType();
         $hasInstalment = 0;
         $userId = Info::getUserIdByUserName($this->userName);
-        $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
+        $user = User::getEnCodeInfo($userId);
+
+        // 报单中心汇率
+        $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
+        $decCountry = Countries::getById($decCountryId);
+        $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
+        // 会员汇率
+        $country = Countries::getById($userId);
+        $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
+
         foreach ($this->goodsNum as $k => $v) {
             if ($v) {
                 $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
                 if (!$goods) {
-                    throw new Exception('Products does not exists!');
+                    throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
                 }
+                $goodsNature = ShopGoodsNature::findOneAsArray('GOODS_ID=:GOODS_ID AND COUNTRY_ID=:COUNTRY_ID',
+                    [':GOODS_ID' => $ids[$k], ':COUNTRY_ID' => $user['COUNTRY_ID']]);
+                if (!$goodsNature) {
+                    throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
+                }
+
                 if($goods['STORE_NUMS']>0){
                     if ($goods['TYPE'] == 1 || $goods['TYPE'] == 2) {
                         $discount = $goodsType[$goods['TYPE']]['discount'];
@@ -852,25 +871,43 @@ class OrderForm extends Model
                         $realPv = $goods['PRICE_PV'] * $discount;
                         $realPriceStandard = $goods['SELL_PRICE_STANDARD'] * $discount;
                     }
+
+                    if($goods['PV_SPLIT']==1){ // 当商品为PV分期时
+                        $pvSplit = $this->_pvSplit($realPv);
+                        $currentPv = $pvSplit['current'];
+                        $remainPv = $pvSplit['remain'];
+                        $totalPv += $currentPv * intval($v);
+                        $totalRealPv += $realPv * intval($v);
+                        $this->_remainPv += $remainPv * intval($v);
+                    }else{
+                        $currentPv = $goods['PRICE_PV'];
+                        $totalPv += $realPv * intval($v);
+                        $totalRealPv += $realPv * intval($v);
+                        $remainPv = 0;
+                        $this->_remainPv += 0;
+                    }
+
                     $totalAmount += $realPrice * intval($v);
-                    $totalPv += $realPv * intval($v);
+                    $totalAmountStandard += $realPriceStandard * intval($v);
+
                     $this->_orderGoods[] = [
                         'GOODS_ID' => $goods['ID'],
-                        'PRICE' => $goods['SELL_PRICE'],
-                        'PV' => $goods['PRICE_PV'],
+                        'PRICE' => $goodsNature['SELL_PRICE'],
+                        'PV' => $currentPv, // $goods['PRICE_PV'],
                         'REAL_PRICE' => $realPrice,
                         'REAL_PV' => $realPv,
+                        'REMAIN_PV' => $remainPv,
                         'POINT' => $goods['POINT'],
                         'BUY_NUMS' => intval($v),
                         'SKU_CODE' => $goods['GOODS_NO'],
                         'GOODS_TITLE' => $goods['GOODS_NAME'],
-                        'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
-                        'TAX_RATE' => $goods['TAX_RATE'],
                         'CATEGORY_TYPE' => $goods['CATEGORY_TYPE'],
-                        'PAY_TYPE' => $this->payType ?? '',
-                        'EMAIL' => $this->email ?? '',
+                        'PAY_TYPE' => $this->payType,
+                        'EMAIL' => $this->email,
+                        'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
                         'REAL_STANDARD_PRICE' => $realPriceStandard,
-                        'EXCHANGE_RATE' => $exchangeRate,
+                        'EXCHANGE_RATE' => $currencyRate,
+                        'TAX_RATE' => $goodsNature['TAX_RATE'],
                     ];
                 }
                 if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
@@ -907,12 +944,28 @@ class OrderForm extends Model
                 }
             }
         }
+
+        // 运费模板
+        $freeTemplate = FreeTemplate::getByCountryId($user['COUNTRY_ID']);
+        // 运费
+        $freight = $freeTemplate['freight'] ?? 0;
+        // 普通商品免运费阈值
+        $freeShipping = $freeTemplate['free_shipping'] ?? 0;
+
         $this->_decAmount = $totalAmount;
         $this->_decPv = $totalPv;
-        $this->_freight = ($totalAmount>=300) ? 0 : 15;
+        $this->_realPv = $totalRealPv;
+        $this->_freight = ($totalAmount >= $freeShipping) ? 0 : $freight;
+        if($this->_address['PROVINCE']==1){
+            $this->_freight = 0;
+        }
 
         $this->_payAmount = $this->_decAmount + $this->_freight;
 
+        $this->_decAmountStandard = $totalAmountStandard;
+        $this->_standardAmount = $this->_decAmountStandard + $this->_freight;
+
+
         $db = \Yii::$app->db;
         $transaction = $db->beginTransaction();
         try {