Просмотр исходного кода

Merge branch 'feature/2703-biopure-ultra-3'

theo 2 лет назад
Родитель
Сommit
a67d2767ef

+ 5 - 3
common/messages/en-US/app.php

@@ -28,6 +28,8 @@ return [
     'insufficientInventory' => 'Insufficient inventory',
     'soldOut' => 'Sold out',
     'productsDoesNotExists' => 'Products does not exists!',
+    'allowOnlyOne' => 'Only 1 can be purchased at a time',
+    'canNotBuy' => 'Please pay in EPP order',
     'productsDoesSoldOut' => 'Products has sold out!',
     'cashDoesNotAdequate' => '余额不足,无法购买商品',
     'exchangePointDoesNotAdequate' => '兑换积分不足,无法购买商品',
@@ -200,8 +202,8 @@ return [
     'reportFormatIncorrect' => 'The format of the report data is incorrect',
     'memberNumberCanNotContainChineseCharacters' => 'Member number cannot contain Chinese characters',
     'pleaseSelectTheEntryLevel' => 'Please select the entry level',
-    'totalBVCanNotLessThanSelectedBV' => 'The total BV of self selected goods cannot be less than the BV of the selected entry level',
-    'totalBVCanNotLessThanNextSelectedLevelBV' => 'The total BV of self selected goods cannot exceed the BV value of the next level under the selected level',
+    'totalBVCanNotLessThanSelectedBV' => 'Please choose the correct Entry Level.',
+    'totalBVCanNotLessThanNextSelectedLevelBV' => 'Please choose the correct Entry Level.',
     'incorrectEntryType' => 'Incorrect entry type',
     'MembershipNumberFilledInitialPurchase' => 'Membership number must be filled in for initial purchase',
     'fillTheInstructorNumberTheMember' => 'For the first purchase, you must fill in the instructor number of the member',
@@ -304,4 +306,4 @@ return [
     'dataDoesNotExists' => 'The data does not exist',
 
 
-];
+];

+ 2 - 0
common/messages/zh-CN/app.php

@@ -28,6 +28,8 @@ return [
     'insufficientInventory' => '库存不足',
     'soldOut' => '已下架',
     'productsDoesNotExists' => '商品不存在',
+    'allowOnlyOne' => '分期商品每次只可购买1个',
+    'canNotBuy' => '分期商品请按顺序购买',
     'productsDoesSoldOut' => '商品已下架',
     'cashDoesNotAdequate' => '余额不足,无法购买商品',
     'exchangePointDoesNotAdequate' => '兑换积分不足,无法购买商品',

+ 7 - 7
common/models/DeclarationLevel.php

@@ -117,10 +117,10 @@ class DeclarationLevel extends \common\components\ActiveRecord
     // 获取下一级业绩数据
     public static function getNextDecPref($perf) {
         $data = static::find()
-        ->where('PERF>:PERF', 
+        ->where('PERF>:PERF',
             [
-                'PERF'=>$perf, 
-                
+                'PERF'=>$perf,
+
             ]
         )
         ->orderBy('PERF ASC')
@@ -133,10 +133,10 @@ class DeclarationLevel extends \common\components\ActiveRecord
 
     public static function getNextAll($perf){
         $data = static::find()
-        ->where('PERF>:PERF', 
+        ->where('PERF>:PERF',
             [
-                'PERF'=>$perf, 
-                
+                'PERF'=>$perf,
+
             ]
         )
         ->indexBy('ID')
@@ -257,4 +257,4 @@ class DeclarationLevel extends \common\components\ActiveRecord
         }
         return $data;
     }
-}
+}

+ 55 - 0
common/models/Instalment.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%ORDER}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 用户ID
+ * @property string $ORDER_TYPE 订单类型:BD, FX
+ * @property string $STAGE 分期阶段
+ * @property int $UPDATE_TIME 修改时间
+ */
+class Instalment extends \common\components\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%INSTALMENT}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+        ];
+    }
+
+    /**
+     * @param $userId
+     * @return integer
+     */
+    public static function getStage($userId) {
+        $user = static::findOneAsArray("USER_ID = :USER_ID", [':USER_ID' => $userId]);
+        if(!$user){
+            return 0;
+        }
+        return $user['STAGE'];
+    }
+
+    public static function getInfo($userId) {
+        $userInfo = static::findOneAsArray("USER_ID = :USER_ID", [':USER_ID' => $userId]);
+        if(!$userInfo){
+            return [
+            ];
+        }
+        return $userInfo;
+    }
+}

+ 40 - 5
common/models/forms/ApproachDeclarationForm.php

@@ -28,6 +28,7 @@ use common\models\User;
 use common\models\UserInfo;
 use common\models\UserNetwork;
 use common\models\UserRelation;
+use common\models\Instalment;
 use Yii;
 use yii\base\Exception;
 
@@ -648,6 +649,7 @@ class ApproachDeclarationForm extends Model
                     $totalAmount = 0;
                     $totalAmountStandard = 0;
                     $totalPv = 0;
+                    $hasInstalment = 0;
                     $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
                     foreach ($this->goodsNum as $k => $v) {
                         if ($v) {
@@ -674,10 +676,16 @@ class ApproachDeclarationForm extends Model
                                     'TAX_RATE' => $goods['TAX_RATE'],
                                 ];
                             }
+                            if($goods['INSTALMENT']>0){
+                                $hasInstalment = $goods['INSTALMENT'];
+                            }
                         }
                     }
-                    if ($totalPv < $decLevel['PERF']) {
-                        throw new Exception(Yii::t('app', 'totalBVCanNotLessThanSelectedBV'));
+                    if($totalPv<$decLevel['PERF']){
+                        if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
+                        }else{
+                            throw new Exception(Yii::t('app', 'totalBVCanNotLessThanSelectedBV'));
+                        }
                     }
                     foreach ($decLevelConfig as $key => $val) {
                         if ($totalPv >= $val['PERF']) {
@@ -685,7 +693,10 @@ class ApproachDeclarationForm extends Model
                         }
                     }
                     if ($this->decLv != $toDecLevel) {
-                        throw new Exception(Yii::t('app', 'totalBVCanNotLessThanNextSelectedLevelBV'));
+                        if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
+                        }else{
+                            throw new Exception(Yii::t('app', 'totalBVCanNotLessThanNextSelectedLevelBV'));
+                        }
                     }
                     $this->_decAmount = $totalAmount;
                     $this->_decPv = $totalPv;
@@ -693,7 +704,7 @@ class ApproachDeclarationForm extends Model
                     $this->_standardAmount = $this->_decAmountStandard;
                 }
 
-                if (!($this->addUser($allData))) {
+                if (!($zcResult = $this->addUser($allData))) {
                     throw new Exception(Form::formatErrorsForApi($this->_userForm->getErrors()));
                 }
 
@@ -701,7 +712,11 @@ class ApproachDeclarationForm extends Model
                 if (!$decResult) {
                     throw new Exception(Form::formatErrorsForApi($decResult->getErrors()));
                 }
-
+                if($hasInstalment){
+                    if(!($instalmentResult = $this->insertInstalment($zcResult))) {
+                        throw new Exception(Form::formatErrorsForApi('h'));
+                    }
+                }
                 return $decResult;
             } catch (\Exception $e) {
 //                throw new Exception(Form::formatErrorsForApi($e->getFile() . ' ' . $e->getLine() . ' ' . $e->getMessage()));
@@ -923,4 +938,24 @@ class ApproachDeclarationForm extends Model
         return true;
     }
 
+    /**
+     * 添加会员分期付款记录
+     * @param $allData
+     * @return bool|UserInfo|null
+     * @throws \yii\db\Exception
+     */
+    public function insertInstalment($zcResult){
+        // 增加会员分期付款记录
+        $instalment = new Instalment();
+        $instalment->USER_ID = $zcResult->USER_ID;
+        $instalment->STAGE = 1;
+        $instalment->ORDER_TYPE = 'BD';
+        $instalment->UPDATE_TIME = time();
+
+        if (!$instalment->save()) {
+            throw new Exception(Form::formatErrorsForApi($instalment->getErrors()));
+        }
+        return $instalment;
+    }
+
 }

+ 8 - 0
common/models/forms/ApproachDeclarationLoopForm.php

@@ -146,6 +146,14 @@ class ApproachDeclarationLoopForm extends Model
                         if (!$goods) {
                             throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
                         }
+                        if($goods['INSTALMENT']>0){ // 分期的商品
+                            if($value['goodsNum'][$i]>1){ // 只能购买一个
+                                throw new Exception(Yii::t('app', 'allowOnlyOne'));
+                            }
+                        }
+                        if($goods['INSTALMENT']>1){ // 不允许购买“非第一期”的商品
+                            throw new Exception(Yii::t('app', 'canNotBuy'));
+                        }
                         if ($goods['STATUS'] == 1 ){
                             if($goods['STORE_NUMS'] >= $value['goodsNum'][$i]) {
                                 // 减库存

+ 27 - 0
common/models/forms/ApproachOrderForm.php

@@ -26,6 +26,7 @@ use common\models\Region;
 use common\models\ShopGoods;
 use common\models\User;
 use common\models\UserNetwork;
+use common\models\Instalment;
 use Yii;
 use yii\base\Exception;
 
@@ -410,6 +411,7 @@ class ApproachOrderForm extends Model
         $totalPv = 0;
         $totalAmountStandard = 0;
         $goodsType = ShopGoods::GOODS_TYPE;
+        $hasInstalment = 0;
         $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
         foreach ($this->goodsNum as $k => $v) {
             if ($v) {
@@ -452,6 +454,21 @@ class ApproachOrderForm extends Model
                         'EXCHANGE_RATE' => $exchangeRate,
                     ];
                 }
+                if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
+                    if($v>1){ // 不可以购买多个
+                        throw new Exception(Yii::t('app', 'allowOnlyOne'));
+                    }
+                    $loginUserId = \Yii::$app->user->id;
+                    $userStage = Instalment::getStage($loginUserId);
+                    if ($userStage==0 || $userStage == 3){
+
+                    }else{
+                        if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
+                            throw new Exception(Yii::t('app', 'canNotBuy'));
+                        }
+                    }
+                    $hasInstalment = $goods['INSTALMENT'];
+                }
             }
         }
 
@@ -479,6 +496,16 @@ class ApproachOrderForm extends Model
             if (!$orderResult = $this->addOrder()) {
                 throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
             }
+            if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
+                $instalmentModel = Instalment::findOne(['USER_ID'=>$loginUserId]);
+                if(!$instalmentModel) {
+                    $instalmentModel = new Instalment();
+                }
+                $instalmentModel->USER_ID = $loginUserId;
+                $instalmentModel->STAGE = $hasInstalment;
+                $instalmentModel->UPDATE_TIME = time();
+                $instalmentModel->save();
+            }
 
             $transaction->commit();
 

+ 41 - 2
common/models/forms/DeclarationForm.php

@@ -25,6 +25,7 @@ use common\models\User;
 use common\models\UserInfo;
 use common\models\UserNetwork;
 use common\models\UserRelation;
+use common\models\Instalment;
 use Yii;
 use yii\base\Exception;
 
@@ -669,6 +670,7 @@ class DeclarationForm extends Model
                 $totalAmount = 0;
                 $totalAmountStandard = 0;
                 $totalPv = 0;
+                $hasInstalment = 0;
                 $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
                 foreach ($this->goodsNum as $k => $v) {
                     if ($v) {
@@ -703,17 +705,29 @@ class DeclarationForm extends Model
                             }
                             $data->update();
                         }
+                        if($goods['INSTALMENT']>0){
+                            $hasInstalment = $goods['INSTALMENT'];
+                        }
                     }
                 }
                 if($totalPv<$decLevel['PERF']){
-                    throw new Exception(Yii::t('app', 'totalBVCanNotLessThanSelectedBV'));
+                    if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
+                    }else{
+                        throw new Exception(Yii::t('app', 'totalBVCanNotLessThanSelectedBV'));
+                    }
                 }
                 foreach ($decLevelConfig as $key=>$val){
                     if($totalPv>=$val['PERF']){
                         $toDecLevel = $key;
                     }
                 }
-                if($this->decLv!=$toDecLevel){
+                if ($this->decLv != $toDecLevel) {
+                    if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'Elite'){
+                    }else{
+                        throw new Exception(Yii::t('app', 'totalBVCanNotLessThanNextSelectedLevelBV'));
+                    }
+                }
+                if ($hasInstalment && $decLevel['LEVEL_NAME'] == 'BA'){
                     throw new Exception(Yii::t('app', 'totalBVCanNotLessThanNextSelectedLevelBV'));
                 }
                 $this->_decAmount = $totalAmount;
@@ -733,6 +747,11 @@ class DeclarationForm extends Model
             if(!($decResult = $this->addDecOrder())) {
                 throw new Exception(Form::formatErrorsForApi($decResult->getErrors()));
             }
+            if($hasInstalment){
+                if(!($instalmentResult = $this->insertInstalment($zcResult))) {
+                    throw new Exception(Form::formatErrorsForApi('h'));
+                }
+            }
         }
         return true;
     }
@@ -957,4 +976,24 @@ class DeclarationForm extends Model
         return true;
     }
 
+    /**
+     * 添加会员分期付款记录
+     * @param $allData
+     * @return bool|UserInfo|null
+     * @throws \yii\db\Exception
+     */
+    public function insertInstalment($zcResult){
+        // 增加会员分期付款记录
+        $instalment = new Instalment();
+        $instalment->USER_ID = $zcResult->USER_ID;
+        $instalment->STAGE = 1;
+        $instalment->ORDER_TYPE = 'BD';
+        $instalment->UPDATE_TIME = time();
+
+        if (!$instalment->save()) {
+            throw new Exception(Form::formatErrorsForApi($instalment->getErrors()));
+        }
+        return $instalment;
+    }
+
 }

+ 8 - 1
common/models/forms/DeclarationLoopForm.php

@@ -117,7 +117,6 @@ class DeclarationLoopForm extends Model
             $model->scenario = $this->scenario;
             $model->allData = $this->data;
             foreach ($this->data as $value){
-				
 				/**
                  * 2022-04-29
                  * York
@@ -141,6 +140,14 @@ class DeclarationLoopForm extends Model
                         if (!$goods) {
                             throw new Exception(Yii::t('app', 'productsDoesSoldOut'));
                         }
+                        if($goods['INSTALMENT']>0){ // 分期的商品
+                            if($value['goodsNum'][$i]>1){ // 只能购买一个
+                                throw new Exception(Yii::t('app', 'allowOnlyOne'));
+                            }
+                        }
+                        if($goods['INSTALMENT']>1){ // 不允许购买“非第一期”的商品
+                            throw new Exception(Yii::t('app', 'canNotBuy'));
+                        }
                         if ($goods['STATUS'] == 1 ){
                             if($goods['STORE_NUMS'] < $value['goodsNum'][$i]){
                                 throw new Exception($goods['GOODS_NAME'] . Yii::t('app', 'insufficientInventory'));

+ 39 - 7
common/models/forms/DeclarationUpgradeForm.php

@@ -22,6 +22,7 @@ use common\models\ShopGoods;
 use common\models\User;
 use common\models\UserInfo;
 use common\models\UserNetwork;
+use common\models\Instalment;
 use Yii;
 use yii\base\Exception;
 
@@ -58,7 +59,7 @@ class DeclarationUpgradeForm extends Model
     private $_orderGoods;
     private $_standardAmount;
     private $_decAmountStandard;
-    
+
     const TYPE_ZC = 'ZC';
     private $_userForm = null;
     // 全部的安置网上级
@@ -154,6 +155,7 @@ class DeclarationUpgradeForm extends Model
                 $totalAmount = 0;
                 $totalAmountStandard = 0;
                 $totalPv = 0;
+                $hasInstalment = 0;
                 $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
                 foreach ($this->goodsNum as $k => $v) {
                     if ($v) {
@@ -183,11 +185,30 @@ class DeclarationUpgradeForm extends Model
                                 'TAX_RATE' => $goods['TAX_RATE'],
                             ];
                         }
+                        if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
+                            if($v>1){ // 不可以购买多个
+                                throw new Exception(Yii::t('app', 'allowOnlyOne'));
+                            }
+
+                            $userStage = Instalment::getStage($userId);
+                            $userInstalmentInfo = Instalment::getInfo($userId);
+                            if (!$userInstalmentInfo){ // 如果没有分期付款记录
+                                throw new Exception(Yii::t('app', 'canNotBuy'));
+                            } else if ($userInstalmentInfo['ORDER_TYPE']!='BD' || $userStage == 3) { // 如果分期付款记录中,不是报单,或已是3
+                                throw new Exception(Yii::t('app', 'canNotBuy'));
+                            }
+                            if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
+                                throw new Exception(Yii::t('app', 'canNotBuy'));
+                            }
+                            $hasInstalment = $goods['INSTALMENT'];
+                        }
                     }
                 }
                 // 这里特殊是用户原报单PV之和+用户购买的商品总PV
                 $checkPv = $totalPv + $diffPerf;
-                if($checkPv < $decLevel['PERF']) {
+                if ($hasInstalment){ // 如果买了分期付款商品,则不判断总pv
+                    $allData['hasInstalment'] = 1;
+                }else if($checkPv < $decLevel['PERF']) {
                     throw new Exception(Yii::t('app', 'totalPVLessThan'), 400);
                 }
                 foreach ($decLevelConfig as $key=>$val){
@@ -214,6 +235,17 @@ class DeclarationUpgradeForm extends Model
             if(!($decResult = $this->addDecOrder($insertConId,$insertRecId, $baseInfo['DEC_LV'],$isObserve,$this->remark))) {
                 throw new Exception(Yii::t('app', 'failed'), 400);
             }
+            if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
+                $instalmentModel = Instalment::findOne(['USER_ID'=>$userId]);
+                if(!$instalmentModel) {
+                    $instalmentModel = new Instalment();
+                }
+                $instalmentModel->USER_ID = $userId;
+                $instalmentModel->STAGE = $hasInstalment;
+                $instalmentModel->ORDER_TYPE = 'BD';
+                $instalmentModel->UPDATE_TIME = time();
+                $instalmentModel->save();
+            }
         }
         return true;
     }
@@ -300,7 +332,7 @@ class DeclarationUpgradeForm extends Model
                 $transaction->rollBack();
                 throw new Exception(Form::formatErrorsForApi($orderModel->getErrors()));
             }
-			
+
             /**
              * 2022-05-10
              * York
@@ -377,7 +409,7 @@ class DeclarationUpgradeForm extends Model
         } catch(Exception $e) {
             $transaction->rollBack();
             throw new Exception($e->getMessage());
-            
+
             return false;
         }
 
@@ -431,7 +463,7 @@ class DeclarationUpgradeForm extends Model
     public function alreadyMaxDec($attribute) {
         $baseInfo = Info::baseInfoZhByUserName($this->insertUserName);
         $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
-        $maxPerfInfo = DeclarationLevel::getMaxDecPref(); 
+        $maxPerfInfo = DeclarationLevel::getMaxDecPref();
         $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
         if ($maxDecId == $userDecId) {
             $this->addError($attribute, 'It is already the highest level and no upgrade is required');//已是最高级别,无需升级
@@ -467,7 +499,7 @@ class DeclarationUpgradeForm extends Model
             }
         }
         unset($allParentUserIds);
-        
+
         return true;
     }
 
@@ -501,4 +533,4 @@ class DeclarationUpgradeForm extends Model
     //     return true;
     // }
 
-}
+}

+ 33 - 0
common/models/forms/OrderForm.php

@@ -11,6 +11,7 @@ use common\helpers\user\Cash;
 use common\helpers\user\Info;
 use common\libs\logging\operate\AdminOperate;
 use common\models\DealType;
+use common\models\Instalment;
 use common\models\Order;
 use common\models\OrderGoods;
 use common\models\Period;
@@ -463,6 +464,7 @@ class OrderForm extends Model
         $totalAmountStandard = 0;
         $goodsType = ShopGoods::GOODS_TYPE;
         $this->_remainPv = 0;
+        $hasInstalment = 0;
         $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
         foreach ($this->goodsNum as $k => $v) {
             if ($v) {
@@ -530,6 +532,26 @@ class OrderForm extends Model
                         'TAX_RATE' => $goods['TAX_RATE'],
                     ];
                 }
+                if($goods['INSTALMENT']>0){ // 如果有分期付款商品,检查用户的分期付款状态
+                    if($v>1){ // 不可以购买多个
+                        throw new Exception(Yii::t('app', 'allowOnlyOne'));
+                    }
+                    $loginUserId = \Yii::$app->user->id;
+                    $userStage = Instalment::getStage($loginUserId);
+                    $userInstalmentInfo = Instalment::getInfo($loginUserId);
+
+                    if ($userStage != 3){
+                        if($userInstalmentInfo){
+                            if($userInstalmentInfo['STAGE']>0 && $userInstalmentInfo['ORDER_TYPE']!='FX'){
+                                throw new Exception(Yii::t('app', 'canNotBuy'));
+                            }
+                        }
+                        if($userStage + 1 != $goods['INSTALMENT']){ // 若用户分期阶段+1不等于商品的分期阶段,则报异常
+                            throw new Exception(Yii::t('app', 'canNotBuy'));
+                        }
+                    }
+                    $hasInstalment = $goods['INSTALMENT'];
+                }
             }
         }
 
@@ -595,6 +617,17 @@ class OrderForm extends Model
             if (!$orderResult = $this->addOrder()) {
                 throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
             }
+            if ($hasInstalment){ // 如果有分期付款的商品,写入信息至分期付款表
+                $instalmentModel = Instalment::findOne(['USER_ID'=>$loginUserId]);
+                if(!$instalmentModel) {
+                    $instalmentModel = new Instalment();
+                }
+                $instalmentModel->USER_ID = $loginUserId;
+                $instalmentModel->STAGE = $hasInstalment;
+                $instalmentModel->ORDER_TYPE = 'FX';
+                $instalmentModel->UPDATE_TIME = time();
+                $instalmentModel->save();
+            }
 
             $transaction->commit();
 

+ 4 - 1
common/models/forms/UserForm.php

@@ -242,7 +242,10 @@ class UserForm extends Model
         // 获取排序为2的报单级别
         $decLevel = DeclarationLevel::getLevelFromSort(1);
         if($this->zcPv < $decLevel['PERF']){
-            $this->addError($attribute, '注册'.$this->userName.'时,注册PV低于最低级别要求,不能报首购单');
+            if($this->allData['hasInstalment'] && $this->zcPv + 30 >= $decLevel['PERF']){
+            }else{
+                $this->addError($attribute, '注册'.$this->userName.'时,注册PV低于最低级别要求,不能报首购单');
+            }
         }
     }
 

+ 15 - 7
frontendApi/modules/v1/controllers/UserController.php

@@ -28,6 +28,7 @@ use common\models\forms\BaDeclarationLoopForm;
 use common\models\forms\UploadForm;
 use common\models\forms\UserBindForm;
 use common\models\forms\UserForm;
+use common\models\Instalment;
 use common\models\OpenBank;
 use common\models\ReceiveAddress;
 use common\models\Region;
@@ -239,7 +240,7 @@ class UserController extends BaseController {
         // 获取系统中的DEC 报单级别配置
         $decConfig = Cache::getDecLevelConfig();
         $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
-        $maxPerfInfo = DeclarationLevel::getMaxDecPref(); 
+        $maxPerfInfo = DeclarationLevel::getMaxDecPref();
         $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
         $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
         $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
@@ -258,7 +259,7 @@ class UserController extends BaseController {
             'IS_OBSERVE' => $isObserve, // 是否是观察期  true为是观察期
             'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
         ];
-        
+
         // 如果是最高级别了,则无需升级
         if ($isMax) {
             return static::notice(['baseInfo' => $userInfo]);
@@ -286,15 +287,22 @@ class UserController extends BaseController {
             $userInfo['NEXT_PERF'] =  $nextLevelPerf;
             // 用户可选择的级别列表
             $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
+            // 如果用户正处于报单分期中,则可以升级到Elite
+            $userInstalmentInfo = Instalment::getInfo($userId);
+            if($userInstalmentInfo){
+                if ($userInstalmentInfo['ORDER_TYPE']=='BD' && $userInstalmentInfo['STAGE'] < 3){
+                    $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll(12);// 用户可选择的级别列表
+                }
+            }
             // 循环列表,补充升级所需要的补差
             foreach ($userInfo['LEVEL_LIST'] as &$v) {
                 $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
-            }   
+            }
         }
-        
+
         return static::notice(['baseInfo' => $userInfo]);
     }
-    
+
     // 会员升级管理
     public function actionUpgrade() {
         $isSwitchUpgrade = Config::find()
@@ -642,7 +650,7 @@ class UserController extends BaseController {
         }
         return static::notice(Yii::t('app', 'illegalRequest'), 400);
     }
-    
+
     /**
      * BA报单管理
      */
@@ -744,4 +752,4 @@ class UserController extends BaseController {
             return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
         }
     }
-}
+}