Przeglądaj źródła

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

zhangl 1 rok temu
rodzic
commit
dbef7a239e
1 zmienionych plików z 16 dodań i 18 usunięć
  1. 16 18
      common/models/forms/OrderForm.php

+ 16 - 18
common/models/forms/OrderForm.php

@@ -7,6 +7,7 @@ use common\components\Model;
 use common\helpers\Form;
 use common\helpers\LoggerTool;
 use common\helpers\PayStack;
+use common\helpers\Tool;
 use common\helpers\user\Balance;
 use common\helpers\user\Cash;
 use common\helpers\user\Info;
@@ -956,9 +957,6 @@ class OrderForm extends Model
         $this->_decPv = $totalPv;
         $this->_realPv = $totalRealPv;
         $this->_freight = ($totalAmount >= $freeShipping) ? 0 : $freight;
-        if($this->_address['PROVINCE']==1){
-            $this->_freight = 0;
-        }
 
         $this->_payAmount = $this->_decAmount + $this->_freight;
 
@@ -980,22 +978,15 @@ class OrderForm extends Model
                     throw new Exception($this->userName . Yii::t('app', 'doesNotYourSubMemberCanNotReconsume'));
                 }
             }
-            //判断用户余额是否充足
-            if($this->payType=='cash') {
-                if (Cash::getAvailableBalance($loginUserId) < $this->_payAmount) {
-                    throw new Exception(Yii::t('app', 'cashDoesNotAdequate'));
-                }
-            }else{
-                if ($this->_payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
-                    throw new Exception(Yii::t('app', 'exchangePointDoesNotAdequate'));
-                }
+
+            //看现金余额是否充足
+            $decCash = Cash::getAvailableBalance($loginUserId);
+            // 转换后的余额
+            $localCash = Tool::convertAmount($decCash, $decUserCurrencyRate, $currencyRate);
+            if ($localCash < $this->_decAmount){
+                throw new Exception(Yii::t('app', 'applicantCashShort'), 400);
             }
 
-			/**
-             * 2022-04-28
-             * York
-             * 支付后减少库存
-             */
             foreach ($this->goodsNum as $k => $v){
                 if ($v){
                     $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
@@ -1058,7 +1049,9 @@ class OrderForm extends Model
         $loginUserName = Info::getUserNameByUserId($loginUserId);
         //订单会员Id
         $userId = Info::getUserIdByUserName($this->userName);
+        $countryId = Info::getUserCountryByUserId($userId);
         $email = Info::getEmailByUserId($this->userName);
+        $country = Countries::getById($countryId);
 
         // 加入订单信息
 //        if($this->province!=1){
@@ -1098,7 +1091,12 @@ class OrderForm extends Model
         $orderModel->STATUS = 1;
         $orderModel->CREATED_AT = Date::nowTime();
         $orderModel->CREATE_USER = $loginUserName;
-        $orderModel->EMAIL = $email;
+        $orderModel->EMAIL = $email ?? '';
+        $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
+        $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
+        $orderModel->EXCHANGE_RATE = $this->exchangeRate;
+        $orderModel->COUNTRY_ID = $countryId;
+        $orderModel->CURRENCY_ID = $country['LOCAL_CURRENCY_ID'] ?? 0;
         if(!$orderModel->save()){
             throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
         }