Kaynağa Gözat

bugfix: EK-1569: 报单时无法使用PayStack支付.

kevinElken 8 ay önce
ebeveyn
işleme
516d6b79d4
1 değiştirilmiş dosya ile 46 ekleme ve 17 silme
  1. 46 17
      common/models/forms/ApproachReconsumeOrderForm.php

+ 46 - 17
common/models/forms/ApproachReconsumeOrderForm.php

@@ -63,12 +63,14 @@ class ApproachReconsumeOrderForm extends Model
     public $lgaName;
     public $cityName;
     public $county;
+    public $exchangeRate;
     public $detailaddress;
 
     private $_address;
     private $_decAmount;
     private $_decPv;
     private $_freight;
+    private $_realPv;
     private $_payAmount;
     private $_orderGoods;
     private $_standardAmount;
@@ -647,52 +649,79 @@ class ApproachReconsumeOrderForm extends Model
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
 
         $userId = \Yii::$app->user->id;
+        $user = User::getEnCodeInfo(\Yii::$app->user->id);
 
         $userName = Info::getUserNameByUserId($userId);
         $userRealName = Info::getUserRealNameByUserId($userId);
         $userMobile = Info::getUserMobileByUserId($userId);
         $userEmail = Info::getUserEmailByUserId($userId);
-        $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
+        $country = Countries::getById($user['COUNTRY_ID']);
+
         // 加入订单信息
-        $warehouse = '01';
-        $_hasPV = $this->_decPv;
+        if ($this->_address['PROVINCE'] != 1) {
+            $warehouse = Region::getWarehouseByCode($this->_address['PROVINCE']);//仓库
+            if (!$warehouse) {
+                throw new Exception(Yii::t('app', 'deliveryTemporarilyNotSupported'));
+            }
+        }else{
+            $warehouse = '01';
+        }
+        $_hasPV = in_array($this->payType, ['exchange', 'tourism_points', 'garage_points']) ? 0 : $this->_decPv;
+        $_hasRealPV = in_array($this->payType, ['exchange', 'tourism_points', 'garage_points']) ? 0 : $this->_realPv;
 
         $ordNo = $this->_generateSn();
         $orderModel = new ApproachReconsumeOrder();
-        $orderModel->SN = 'OS' . $ordNo;
-        $orderModel->DEC_SN = 'DS' . $ordNo;
+        $orderModel->SN = 'OS'.$ordNo;
+        $orderModel->DEC_SN = 'DS'.$ordNo;
         $orderModel->ORDER_TYPE = $this->type;
         $orderModel->USER_ID = $userId;
         $orderModel->USER_NAME = $userName;
+        $orderModel->DEC_USER_ID = $this->decUserName;;
         $orderModel->ORDER_AMOUNT = $this->_decAmount;
         $orderModel->PV = $_hasPV;
         $orderModel->PAY_AMOUNT = $this->_payAmount;
-        $orderModel->PAY_PV = $_hasPV; // 兑换积分不能算业绩
-        $orderModel->PAY_AT = 0;
+        $orderModel->PAY_PV = $this->payType == 'prp' ? 0 : $_hasRealPV; // 兑换积分不能算业绩
+        $orderModel->REMAIN_PV = $this->payType == 'prp' ? 0 : $this->_remainPv;
+        $orderModel->PAY_AT = Date::nowTime();
         $orderModel->PAY_TYPE = $this->payType;
         $orderModel->PERIOD_NUM = $nowPeriodNum;
         $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
         $orderModel->FREIGHT = $this->_freight;
         $orderModel->PAY_FREIGHT = $this->_freight;
-        $orderModel->CONSIGNEE = $this->consignee;
-        $orderModel->MOBILE = $this->acceptMobile;
-        $orderModel->PROVINCE = $this->province[0];
-        $orderModel->LGA_NAME = $this->lgaName;
-        $orderModel->CITY_NAME = $this->cityName;
-        $orderModel->ADDRESS = $this->detailaddress;
-
+        $orderModel->CONSIGNEE = $this->_address['CONSIGNEE'];
+        $orderModel->MOBILE = $this->_address['MOBILE'];
+        $orderModel->PROVINCE = $this->_address['PROVINCE'];
+//        $orderModel->CITY = $this->_address['CITY'];
+//        $orderModel->COUNTY = $this->_address['COUNTY'];
+        $orderModel->LGA_NAME = $this->_address['LGA_NAME'];
+        $orderModel->CITY_NAME = $this->_address['CITY_NAME'];
+        $orderModel->ADDRESS = $this->_address['ADDRESS'];
         $orderModel->FRONT_REMARK = $this->remark;
         $orderModel->WAREHOUSE = $warehouse;
-        $orderModel->STATUS = \Yii::$app->params['orderStatus']['notPaid']['value'];
+        $orderModel->STATUS = \Yii::$app->params['orderStatus']['paid']['value'];
         $orderModel->CREATED_AT = Date::nowTime();
         $orderModel->CREATE_USER = $userName;
-        $orderModel->EMAIL = $userEmail?$userEmail:$userName.'@elken.net';
+        $orderModel->EMAIL = $userEmail ?? '';
         $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
         $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
-        $orderModel->EXCHANGE_RATE = $exchangeRate;
+        $orderModel->EXCHANGE_RATE = $this->exchangeRate;
+        $orderModel->COUNTRY_ID = $user['COUNTRY_ID'];
+        $orderModel->CURRENCY_ID = $country['LOCAL_CURRENCY_ID'] ?? 0;
+        if($this->_address['PROVINCE']==1){
+            $orderModel->EXPRESS_TYPE = 1;
+            $orderModel->CONSIGNEE = $userRealName;
+            $orderModel->MOBILE = $userMobile;
+            $orderModel->PROVINCE = 1;
+            $orderModel->CITY = 1;
+            $orderModel->COUNTY = 1;
+            $orderModel->LGA_NAME = $this->_address['LGA_NAME'];
+            $orderModel->CITY_NAME = $this->_address['CITY_NAME'];
+            $orderModel->ADDRESS = 'Self Pick-up';
+        }
         if(!$orderModel->save()){
             throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
         }
+
         // 加入商品到订单商品表
         foreach($this->_orderGoods as $key=>$value) {
             $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;