kevin 1 год назад
Родитель
Сommit
9178943ad2

+ 52 - 50
common/models/forms/ApproachDeclarationUpgradeForm.php

@@ -64,7 +64,9 @@ class ApproachDeclarationUpgradeForm extends Model
     private $_standardAmount;
     private $_decAmountStandard;
     public $period;
-    
+    public $instalment;
+    public $isMax;
+    public $maxLv;
     const TYPE_ZC = 'ZC';
     private $_userForm = null;
     // 全部的安置网上级
@@ -77,7 +79,7 @@ class ApproachDeclarationUpgradeForm extends Model
     {
         return [
             [['remark','type','decLv','decWay','packageId','goodsId', 'goodsNum', 'insertUserName','consignee','acceptMobile','province',/*'city','county',*/'lgaName','cityName','address','nowPerf','nextPerf'], 'trim'],
-            [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile'], 'required'],
+            [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile', 'isMax'], 'required'],
             [['decUserName'], 'issetDec'], // 必须是报单中心
             [['decWay'], 'hasProduct'],// 必须选择商品
             [['decLv'], 'alreadyMaxDec'], //判断要升级用户是否已经是最高级
@@ -118,43 +120,36 @@ class ApproachDeclarationUpgradeForm extends Model
         $hasInstalment = 0;
         // 首购单
         if($this->type == self::TYPE_ZC){
-            //报单商品及PV判断
-            $decLevelConfig = Cache::getDecLevelConfig();
-            $decLevel = $decLevelConfig[$this->decLv];
-            $toDecLevel = $this->decLv;
-            if(!$this->decLv){
-                throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'), 400);
-            }
             $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
             $userId = $baseInfo['ID'];
-            $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
-            if ($userDecPvSum != $this->nowPerf) {
-                throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'), 400);
-            }
+
             // 获取用户是否是观察期
             $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
             $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
             $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
             $diffPerf = $isObserve ? $this->nowPerf : 0; // 观察期内升级要加上用户累计的PV,全额则基础PV为0,全额购买
             if ($this->decWay != 2) {
-                throw new Exception(Yii::t('app', 'upgradeMethodIncorrect'), 400);
+                throw new Exception(Yii::t('app', 'upgradeMethodIncorrect'));
             }
-            if($this->decWay==1) {
-                // 先不加套餐升级方式
-                // $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
-                // $this->_decAmount = $decPackage['AMOUNT'];
-                // $this->_decPv = $decPackage['PV'];
-                // $this->_orderGoods[] = [
-                //     'GOODS_ID' => $this->packageId,
-                //     'PRICE' => $this->_decAmount,
-                //     'REAL_PRICE' => $this->_decAmount,
-                //     'PV' => $this->_decPv,
-                //     'REAL_PV' => $this->_decPv,
-                //     'BUY_NUMS' => 1,
-                //     'SKU_CODE' => $decPackage['PACKAGE_NO'],
-                //     'GOODS_TITLE' => $decPackage['PACKAGE_NAME']
-                // ];
-            } else {
+
+            $decLevel = [];
+            $toDecLevel = $this->isMax ? $this->maxLv : '';
+            if (!$this->isMax) {
+                //报单商品及PV判断
+                $decLevelConfig = Cache::getDecLevelConfig();
+                $decLevel = $decLevelConfig[$this->decLv];
+                $toDecLevel = $this->decLv;
+                if(!$this->decLv){
+                    throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'));
+                }
+
+                $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
+                if ($userDecPvSum != $this->nowPerf) {
+                    throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'));
+                }
+            }
+
+            {
                 $ids = $this->goodsId;
                 $totalAmount = 0;
                 $totalAmountStandard = 0;
@@ -216,21 +211,23 @@ class ApproachDeclarationUpgradeForm extends Model
                         }
                     }
                 }
-                // 这里特殊是用户原报单PV之和+用户购买的商品总PV
-                $checkPv = $totalPv + $diffPerf;
-                if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
-                    $allData['hasInstalment'] = 1;
-                }else if($checkPv < $decLevel['PERF']) {
-                    throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
-                }
-                foreach ($decLevelConfig as $key=>$val){
-                    if($checkPv>=$val['PERF']){
-                        $toDecLevel = $key;
+
+                if (!$this->isMax) {
+                    // 这里特殊是用户原报单PV之和+用户购买的商品总PV
+                    $checkPv = $totalPv + $diffPerf;
+                    if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
+                        $allData['hasInstalment'] = 1;
+                    }else if($checkPv < $decLevel['PERF']) {
+                        throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
+                    }
+
+                    // 会员已有PV+本次订单PV 不能多于 下一个级别所需PV
+                    $nextDecLv = DeclarationLevel::getNextDecLv($toDecLevel);
+                    if ($nextDecLv && ($checkPv >= $nextDecLv['PERF'])) {
+                        throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
                     }
                 }
-                if($this->decLv!=$toDecLevel){
-                    throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
-                }
+
                 $this->_decAmount = $totalAmount;
                 $this->_decPv = $totalPv;
                 $this->_decAmountStandard = $totalAmountStandard;
@@ -443,6 +440,7 @@ class ApproachDeclarationUpgradeForm extends Model
             return false;
         }
         if ($this->decWay!=1 && empty($this->goodsId)) {
+            $this->instalment = ShopGoods::findAllAsArray('INSTALMENT > 0 AND ID IN(' . implode(',', $this->goodsId) . ')');
             $this->addError($attribute, 'Purchase product upgrade, please select product');//购买商品升级,请选择商品'
             return false;
         }
@@ -452,13 +450,17 @@ class ApproachDeclarationUpgradeForm extends Model
 
     // 判断要升级的会员,是否已是最高级别
     public function alreadyMaxDec($attribute) {
-        $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
-        $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
-        $maxPerfInfo = DeclarationLevel::getMaxDecPref(); 
-        $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
-        if ($maxDecId == $userDecId) {
-            $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
-            return false;
+        // 如果商品是分期商品,则不判断是否已经顶级
+        if (!$this->instalment || !$this->isMax) {
+            $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
+            $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
+            $maxPerfInfo = DeclarationLevel::getMaxDecPref();
+            $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
+            $this->maxLv = $maxPerfInfo['ID'];
+            if ($maxDecId == $userDecId) {
+                $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
+                return false;
+            }
         }
 
         return true;

+ 50 - 47
common/models/forms/DeclarationUpgradeForm.php

@@ -61,6 +61,9 @@ class DeclarationUpgradeForm extends Model
     private $_standardAmount;
     private $_decAmountStandard;
     public $period;
+    public $instalment;
+    public $isMax;
+    public $maxLv;
 
     const TYPE_ZC = 'ZC';
     private $_userForm = null;
@@ -74,7 +77,7 @@ class DeclarationUpgradeForm extends Model
     {
         return [
             [['remark','type','decLv','decWay','packageId','goodsId', 'goodsNum', 'insertUserName','consignee','acceptMobile','province',/*'city','county',*/'lgaName','cityName','address','nowPerf','nextPerf'], 'trim'],
-            [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile'], 'required'],
+            [['type','decLv','decWay','insertUserName','nowPerf','province',/*'city','county',*/'address','acceptMobile', 'isMax'], 'required'],
             [['decUserName'], 'issetDec'], // 必须是报单中心
             [['decWay'], 'hasProduct'],// 必须选择商品
             [['decLv'], 'alreadyMaxDec'], //判断要升级用户是否已经是最高级
@@ -117,19 +120,9 @@ class DeclarationUpgradeForm extends Model
         $hasInstalment = 0;
         // 首购单
         if($this->type == self::TYPE_ZC){
-            //报单商品及PV判断
-            $decLevelConfig = Cache::getDecLevelConfig();
-            $decLevel = $decLevelConfig[$this->decLv];
-            $toDecLevel = $this->decLv;
-            if(!$this->decLv){
-                throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'));
-            }
             $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
             $userId = $baseInfo['ID'];
-            $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
-            if ($userDecPvSum != $this->nowPerf) {
-                throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'));
-            }
+
             // 获取用户是否是观察期
             $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
             $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
@@ -138,22 +131,25 @@ class DeclarationUpgradeForm extends Model
             if ($this->decWay != 2) {
                 throw new Exception(Yii::t('app', 'upgradeMethodIncorrect'));
             }
-            if($this->decWay==1) {
-                // 先不加套餐升级方式
-                // $decPackage = DeclarationPackage::findOneAsArray('ID=:ID', [':ID'=>$this->packageId]);
-                // $this->_decAmount = $decPackage['AMOUNT'];
-                // $this->_decPv = $decPackage['PV'];
-                // $this->_orderGoods[] = [
-                //     'GOODS_ID' => $this->packageId,
-                //     'PRICE' => $this->_decAmount,
-                //     'REAL_PRICE' => $this->_decAmount,
-                //     'PV' => $this->_decPv,
-                //     'REAL_PV' => $this->_decPv,
-                //     'BUY_NUMS' => 1,
-                //     'SKU_CODE' => $decPackage['PACKAGE_NO'],
-                //     'GOODS_TITLE' => $decPackage['PACKAGE_NAME']
-                // ];
-            } else {
+
+            $decLevel = [];
+            $toDecLevel = $this->isMax ? $this->maxLv : '';
+            if (!$this->isMax) {
+                //报单商品及PV判断
+                $decLevelConfig = Cache::getDecLevelConfig();
+                $decLevel = $decLevelConfig[$this->decLv];
+                $toDecLevel = $this->decLv;
+                if(!$this->decLv){
+                    throw new Exception(Yii::t('app', 'pleaseSelectUpgradeLevel'));
+                }
+
+                $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
+                if ($userDecPvSum != $this->nowPerf) {
+                    throw new Exception(Yii::t('app', 'checkPerformanceOfUpgradedMember'));
+                }
+            }
+
+            {
                 $ids = $this->goodsId;
                 $totalAmount = 0;
                 $totalAmountStandard = 0;
@@ -218,19 +214,20 @@ class DeclarationUpgradeForm extends Model
                     }
                 }
 
-                // 这里特殊是用户原报单PV之和+用户购买的商品总PV
-                $checkPv = $totalPv + $diffPerf;
-                if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
-                    $allData['hasInstalment'] = 1;
-                }else if($checkPv < $decLevel['PERF']) {
-                    throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
-                }
+                if (!$this->isMax) {
+                    // 这里特殊是用户原报单PV之和+用户购买的商品总PV
+                    $checkPv = $totalPv + $diffPerf;
+                    if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
+                        $allData['hasInstalment'] = 1;
+                    }else if($checkPv < $decLevel['PERF']) {
+                        throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
+                    }
 
-                // 会员已有PV+本次订单PV 不能多于 下一个级别所需PV
-                $nextDecLv = DeclarationLevel::getNextDecLv($toDecLevel);
-                LoggerTool::debug(['Ats', $nextDecLv, $checkPv]);
-                if ($nextDecLv && ($checkPv >= $nextDecLv['PERF'])) {
-                    throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
+                    // 会员已有PV+本次订单PV 不能多于 下一个级别所需PV
+                    $nextDecLv = DeclarationLevel::getNextDecLv($toDecLevel);
+                    if ($nextDecLv && ($checkPv >= $nextDecLv['PERF'])) {
+                        throw new Exception(Yii::t('app', 'totalPvExceedPv'), 400);
+                    }
                 }
 
                 $this->_decAmount = $totalAmount;
@@ -238,6 +235,7 @@ class DeclarationUpgradeForm extends Model
                 $this->_decAmountStandard = $totalAmountStandard;
                 $this->_standardAmount = $this->_decAmountStandard;
             }
+
             //看现金余额是否充足
             if (Cash::getAvailableBalance($loginUserId) < $this->_decAmount){
                 throw new Exception(Yii::t('app', 'applicantCashShort'), 400);
@@ -470,6 +468,7 @@ class DeclarationUpgradeForm extends Model
             return false;
         }
         if ($this->decWay!=1 && empty($this->goodsId)) {
+            $this->instalment = ShopGoods::findAllAsArray('INSTALMENT > 0 AND ID IN(' . implode(',', $this->goodsId) . ')');
             $this->addError($attribute, 'Purchase product upgrade, please select product');//购买商品升级,请选择商品'
             return false;
         }
@@ -479,13 +478,17 @@ class DeclarationUpgradeForm extends Model
 
     // 判断要升级的会员,是否已是最高级别
     public function alreadyMaxDec($attribute) {
-        $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
-        $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
-        $maxPerfInfo = DeclarationLevel::getMaxDecPref();
-        $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
-        if ($maxDecId == $userDecId) {
-            $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
-            return false;
+        // 如果商品是分期商品,则不判断是否已经顶级
+        if (!$this->instalment || !$this->isMax) {
+            $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
+            $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
+            $maxPerfInfo = DeclarationLevel::getMaxDecPref();
+            $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
+            $this->maxLv = $maxPerfInfo['ID'];
+            if ($maxDecId == $userDecId) {
+                $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
+                return false;
+            }
         }
 
         return true;