root vor 3 Jahren
Ursprung
Commit
65d05c4871

+ 88 - 74
common/models/forms/DeclarationUpgradeForm.php

@@ -207,86 +207,92 @@ class DeclarationUpgradeForm extends Model
         if(!$warehouse){
             throw new Exception('地区暂时不支持配送,具体联系客服');
         }
+        
         $upgradeType = $isObserve ? 1 : 2; // 1补差  2全额
         $periodObj = Period::instance();
         $nowPeriodNum = $periodObj->getNowPeriodNum();
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
         $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
         // 加入报单信息
-        $decOrderModel = new DecOrder();
-        $decOrderModel->DEC_SN = 'DS'.$ord;
-        $decOrderModel->ORDER_SN = 'OS'.$ord;
-        $decOrderModel->TYPE = $this->type;
-        $decOrderModel->USER_ID = \Yii::$app->user->id; // 报单人
-        $decOrderModel->TO_USER_ID = $this->_insertUserId; // 被报单人
-        $decOrderModel->DEC_AMOUNT = $this->_decAmount;
-        $decOrderModel->DEC_PV = $this->_decPv;
-        $decOrderModel->PERIOD_NUM = $nowPeriodNum;
-        $decOrderModel->CALC_MONTH = $nowCalcMonth;
-        $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
-        $decOrderModel->PAID_WALLET = 'cash';
-        $decOrderModel->CON_USER_ID = $insertConId;
-        $decOrderModel->REC_USER_ID = $insertRecId;
-        $decOrderModel->DEC_ID = $this->_decId;
-        $decOrderModel->IS_DEL = 0;
-        $decOrderModel->DETAIL_TYPE = 2;
-        $decOrderModel->CREATED_AT = Date::nowTime();
-        $decOrderModel->UPGRADE_TYPE = $upgradeType;
-        $decOrderModel->REMARK = $remark;
-        if(!$decOrderModel->save()){
-            throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
-        }
+        $db = \Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $decOrderModel = new DecOrder();
+            $decOrderModel->DEC_SN = 'DS'.$ord;
+            $decOrderModel->ORDER_SN = 'OS'.$ord;
+            $decOrderModel->TYPE = $this->type;
+            $decOrderModel->USER_ID = \Yii::$app->user->id; // 报单人
+            $decOrderModel->TO_USER_ID = $this->_insertUserId; // 被报单人
+            $decOrderModel->DEC_AMOUNT = $this->_decAmount;
+            $decOrderModel->DEC_PV = $this->_decPv;
+            $decOrderModel->PERIOD_NUM = $nowPeriodNum;
+            $decOrderModel->CALC_MONTH = $nowCalcMonth;
+            $decOrderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
+            $decOrderModel->PAID_WALLET = 'cash';
+            $decOrderModel->CON_USER_ID = $insertConId;
+            $decOrderModel->REC_USER_ID = $insertRecId;
+            $decOrderModel->DEC_ID = $this->_decId;
+            $decOrderModel->IS_DEL = 0;
+            $decOrderModel->DETAIL_TYPE = 2;
+            $decOrderModel->CREATED_AT = Date::nowTime();
+            $decOrderModel->UPGRADE_TYPE = $upgradeType;
+            $decOrderModel->REMARK = $remark;
+            if(!$decOrderModel->save()){
+                $transaction->rollBack();
+                throw new Exception(Form::formatErrorsForApi($decOrderModel->getErrors()));
+            }
 
-        $orderModel = new Order();
-        $orderModel->SN = 'OS'.$ord;
-        $orderModel->DEC_SN = 'DS'.$ord;
-        $orderModel->ORDER_TYPE = $this->type;
-        $orderModel->USER_ID = $this->_insertUserId;
-        $orderModel->USER_NAME = $this->insertUserName; // 要升级的用户
-        $orderModel->ORDER_AMOUNT = $this->_decAmount;
-        $orderModel->PV = $this->_decPv;
-        $orderModel->PAY_AMOUNT = $this->_decAmount;
-        $orderModel->PAY_PV = $this->_decPv;
-        $orderModel->PAY_AT = Date::nowTime();
-        $orderModel->PAY_TYPE = 'cash';
-        $orderModel->PERIOD_NUM = $nowPeriodNum;
-        $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
-        $orderModel->FREIGHT = 0;
-        $orderModel->PAY_FREIGHT = 0;
-        $orderModel->CONSIGNEE = $this->consignee;
-        $orderModel->MOBILE = $this->acceptMobile;
-        $orderModel->PROVINCE = $this->province;
-        $orderModel->CITY = $this->city;
-        $orderModel->COUNTY = intval($this->county) ?? 0;
-        $orderModel->ADDRESS = $this->address;
-        $orderModel->WAREHOUSE = $warehouse;
-        $orderModel->STATUS = 1;
-        $orderModel->CREATED_AT = Date::nowTime();
-        $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
-        if(!$orderModel->save()){
-            throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
-        }
-        // 加入商品到订单商品表
-        foreach($this->_orderGoods as $key=>$value){
-            $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
-            $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
-        }
-        OrderGoods::batchInsert($this->_orderGoods);
-        //写入收货地址信息
-        $addressModel = new ReceiveAddress();
-        $addressModel->USER_ID = $this->_insertUserId;
-        $addressModel->USER_NAME = $this->insertUserName;
-        $addressModel->CONSIGNEE = $this->consignee;
-        $addressModel->MOBILE = $this->acceptMobile;
-        $addressModel->PROVINCE = $this->province;
-        $addressModel->CITY = $this->city;
-        $addressModel->COUNTY = intval($this->county) ?? 0;
-        $addressModel->ADDRESS = $this->address;
-        $addressModel->IS_DEFAULT = 0;
-        if(!$addressModel->save()){
-            throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
-        }
-        try{
+            $orderModel = new Order();
+            $orderModel->SN = 'OS'.$ord;
+            $orderModel->DEC_SN = 'DS'.$ord;
+            $orderModel->ORDER_TYPE = $this->type;
+            $orderModel->USER_ID = $this->_insertUserId;
+            $orderModel->USER_NAME = $this->insertUserName; // 要升级的用户
+            $orderModel->ORDER_AMOUNT = $this->_decAmount;
+            $orderModel->PV = $this->_decPv;
+            $orderModel->PAY_AMOUNT = $this->_decAmount;
+            $orderModel->PAY_PV = $this->_decPv;
+            $orderModel->PAY_AT = Date::nowTime();
+            $orderModel->PAY_TYPE = 'cash';
+            $orderModel->PERIOD_NUM = $nowPeriodNum;
+            $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
+            $orderModel->FREIGHT = 0;
+            $orderModel->PAY_FREIGHT = 0;
+            $orderModel->CONSIGNEE = $this->consignee;
+            $orderModel->MOBILE = $this->acceptMobile;
+            $orderModel->PROVINCE = $this->province;
+            $orderModel->CITY = $this->city;
+            $orderModel->COUNTY = intval($this->county) ?? 0;
+            $orderModel->ADDRESS = $this->address;
+            $orderModel->WAREHOUSE = $warehouse;
+            $orderModel->STATUS = 1;
+            $orderModel->CREATED_AT = Date::nowTime();
+            $orderModel->CREATE_USER = Info::getUserNameByUserId(\Yii::$app->user->id);
+            if(!$orderModel->save()){
+                $transaction->rollBack();
+                throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
+            }
+            // 加入商品到订单商品表
+            foreach($this->_orderGoods as $key=>$value){
+                $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
+                $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
+            }
+            OrderGoods::batchInsert($this->_orderGoods);
+            //写入收货地址信息
+            $addressModel = new ReceiveAddress();
+            $addressModel->USER_ID = $this->_insertUserId;
+            $addressModel->USER_NAME = $this->insertUserName;
+            $addressModel->CONSIGNEE = $this->consignee;
+            $addressModel->MOBILE = $this->acceptMobile;
+            $addressModel->PROVINCE = $this->province;
+            $addressModel->CITY = $this->city;
+            $addressModel->COUNTY = intval($this->county) ?? 0;
+            $addressModel->ADDRESS = $this->address;
+            $addressModel->IS_DEFAULT = 0;
+            if(!$addressModel->save()){
+                $transaction->rollBack();
+                throw new Exception(Form::formatErrorsForApi($addressModel->getErrors()));
+            }
             // 扣报单人现金钱包
             Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_decAmount), ['REMARK' =>'为'.$this->insertUserName.'升级报单']);
             // 为被升级人进行升级操作
@@ -300,9 +306,17 @@ class DeclarationUpgradeForm extends Model
                 'lvPv' => $this->_decPv
             ];
             $modifyDecLv = $decLevelLog->frontendChange($decLog);
-        } catch (Exception $e) {
+            $transaction->commit();
+        } catch(Exception $e) {
+            file_put_contents('err_upgrade_txt.txt', var_export([
+                'err' => $e->getMessage()
+            ],true));
+            $transaction->rollBack();
             throw new Exception($e->getMessage());
+            
+            return false;
         }
+
         return $modifyDecLv;
     }
 

+ 3 - 0
frontendApi/modules/v1/controllers/UserController.php

@@ -208,6 +208,9 @@ class UserController extends BaseController {
     public function actionUpgradeInfo() {
         $userNumber = \Yii::$app->request->request('userName');
         $baseInfo = Info::baseInfoZhByUserName($userNumber);
+        if ($baseInfo['STATUS'] != 1) {
+            return static::notice('非激活用户,请联系客服',400);
+        }
         // 1. 如果是最高级别,则只显示用户基本信息
         // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
         $userId = $baseInfo['ID'];