root hace 3 años
padre
commit
4eef98517f

+ 34 - 0
common/models/DeclarationLevel.php

@@ -104,11 +104,45 @@ class DeclarationLevel extends \common\components\ActiveRecord
 
     // 获取最大的业绩信息
     public static function getMaxDecPref() {
+        
         $data = static::find()->where('1=1')->orderBy('PERF DESC')->indexBy('ID')->asArray()->one();
 
         return $data;
     }
 
+    // 获取下一级业绩数据
+    public static function getNextDecPref($perf) {
+        $data = static::find()
+        ->where('PERF>:PERF', 
+            [
+                'PERF'=>$perf, 
+                
+            ]
+        )
+        ->orderBy('PERF ASC')
+        ->indexBy('ID')
+        ->asArray()
+        ->one();
+
+        return $data;
+    }
+
+    public static function getNextAll($perf){
+        $data = static::find()
+        ->where('PERF>:PERF', 
+            [
+                'PERF'=>$perf, 
+                
+            ]
+        )
+        ->indexBy('ID')
+        ->orderBy('SORT ASC')
+        ->asArray()
+        ->all();
+
+        return $data;
+    }
+
     /**
      * @return array|\yii\db\ActiveRecord[]
      */

+ 52 - 0
common/models/OriginDecPv.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%ORIGIN_DEC_PV}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property int $TYPE 报单类型
+ * @property string $INSERT_USER_ID 首购会员ID
+ * @property string $DEC_AMOUNT 报单金额
+ * @property string $DEC_PV 报单PV
+ * @property int $PERIOD_NUM 报单期数
+ * @property int $STATUS 状态
+ * @property int $CREATED_AT 创建时间
+ */
+class OriginDecPv extends \common\components\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%ORIGIN_DEC_PV}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'DEC_PV', 'ACTION_TYPE'], 'required'],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'DEC_PV' => '报单PV值',
+            'ACTION_TYPE' => '操作类型默认0无操作  1为增加  2为减少',
+        ];
+    }
+}

+ 64 - 0
common/models/UpgradeType.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%UPGRADE_TYPE}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property int $TYPE 报单类型
+ * @property string $INSERT_USER_ID 首购会员ID
+ * @property string $DEC_AMOUNT 报单金额
+ * @property string $DEC_PV 报单PV
+ * @property int $PERIOD_NUM 报单期数
+ * @property int $STATUS 状态
+ * @property int $CREATED_AT 创建时间
+ */
+class UpgradeType extends \common\components\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%UPGRADE_TYPE}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['OBSERVE_NAME', 'SORTS', 'IS_STATUS', 'NATION_ID','OBSERVE_TYPE','CREATE_AT'], 'required'],
+            [['OBSERVE_TYPE', 'NATION_ID', 'IS_STATUS', 'CREATED_AT'], 'integer'],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'OBSERVE_NAME' => '升级方式名称',
+            'SORTS' => '排序',
+            'IS_STATUS' => '状态0为默认启用  1为禁用 ',
+            'NATION_ID' => '国家id',
+            'OBSERVE_TYPE' => '升级类型 1为补差额升级类型  2为全额升级类型',
+            'CREATE_AT' => '创建时间'
+        ];
+    }
+
+    // 根据类型获取升级方式
+    public static function getOneByType($type) {
+        $result = UpgradeType::findOneAsArray('OBSERVE_TYPE=:OBSERVE_TYPE  AND IS_STATUS=0', [':OBSERVE_TYPE'=>$type]);
+        
+        return $result;
+    }
+}

+ 55 - 2
common/models/User.php

@@ -337,9 +337,62 @@ class User extends \common\components\ActiveRecord
         }
     }
 
-    // 判断用户是否是观察期
+    
+    /**
+     *  判断用户是否是观察期
+     *  观望期:自加入算起2个月
+     *  例子:2022年5月14日加入, 观望期至2022年7月31日。
+     *  true为是观察期用户  false为不是观察期用户
+     * @param $addAt 用户的加入时间
+     * @param $month 观察期月份限制 系统初始化为2个月
+     */
     public static function checkIsObserve($addAt, $month) {
-        
+        $appendMonth = date("Y-m", strtotime("first day of +$month month", $addAt)); // 指定月份
+        $lastDay = date("t", strtotime($appendMonth));  // 获取指定月的最后一天
+        $eTime = strtotime($appendMonth.'-'.$lastDay);
+
+        return $addAt < $eTime ? true : false;
+    }
+
+    // 获取用户报单PV总和
+    public static function sumDevPvByUserId($userId) {
+        $decOrderPv = DecOrder::find()
+        ->select('SUM(DEC_PV) AS PV_SUM')
+        ->where('USER_ID=:USER_ID', 
+            [
+                'USER_ID'=>$userId, 
+                
+            ]
+        )
+        ->asArray()
+        ->one();
+        $decOrderPv = isset($decOrderPv['PV_SUM']) ? $decOrderPv['PV_SUM'] : 0;
+        $orderDecPv = OrderDec::find()
+        ->select('SUM(PAY_PV) AS PV_SUM')
+        ->where('USER_ID=:USER_ID', 
+            [
+                'USER_ID'=>$userId, 
+                
+            ]
+        )
+        ->asArray()
+        ->one();
+        $orderDecPv = isset($orderDecPv['PV_SUM']) ? $orderDecPv['PV_SUM'] : 0;
+        // 还得加上用户在老系统中的所有报单PV之和
+        $originPv = OriginDecPv::find()
+        ->select('SUM(DEC_PV) AS PV_SUM')
+        ->where('USER_ID=:USER_ID', 
+            [
+                'USER_ID'=>$userId, 
+                
+            ]
+        )
+        ->asArray()
+        ->one();
+        $originPv = isset($originPv['PV_SUM']) ? $originPv['PV_SUM'] : 0;
+        $total = $orderDecPv + $decOrderPv + $originPv;
+
+        return $total;
     }
 
     /**

+ 46 - 33
frontendApi/modules/v1/controllers/UserController.php

@@ -23,6 +23,7 @@ use common\models\OpenBank;
 use common\models\ReceiveAddress;
 use common\models\Region;
 use common\models\ShopGoods;
+use common\models\UpgradeType;
 use common\models\User;
 use common\models\UserBind;
 use common\models\UserInfo;
@@ -211,49 +212,71 @@ class UserController extends BaseController {
         $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
         // 获取系统中的DEC 报单级别配置
         $decConfig = Cache::getDecLevelConfig();
-        $decInfo = $decConfig[$userDecId]; // 会员的级别具体信息
+        $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
         $maxPerfInfo = DeclarationLevel::getMaxDecPref(); 
-        $maxPerf = $maxPerfInfo['PERF']; // 级别配置中最高级别业绩
         $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
         $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
         $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
         $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
         // 如果用户已经是最高级别,则只展示用户信息
+        $isMax = false;
+        if ($maxDecId == $userDecId) {
+            $isMax = true;
+        }
         $userInfo = [
             'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
             'DEC_ID' => $userDecId, // 用户级别id
             'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
             'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
-            'IS_OBSERVE' => 1, // 是否是观察期
+            'IS_OBSERVE' => $isObserve, // 是否是观察期  true为是观察期
+            'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
         ];
-        if ($maxDecId == $userDecId) {
-            echo 11;exit;
+        // 如果是最高级别了,则无需升级
+        if ($isMax) {
+            return static::notice(['baseInfo' => $userInfo]);
         }
-        return static::notice(['baseInfo' => $baseInfo]);
+        $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
+        if (!$isMax) {
+            $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
+            // 如果总和pv不等于0 并且小于级别业绩
+            if ($userDecPvSum !=0 && ($userDecPvSum < $levelPerf)) {
+                return static::notice('请联系客服人员核对业绩',400);
+            }
+            // 下一级业绩
+            $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
+            // 如果总和超过了下一级业绩
+            if ($userDecPvSum !=0 && ($userDecPvSum >= $nextLevelPerf)) {
+                return static::notice('请联系客服人员核对业绩',400);
+            }
+            // 获取用户报单PV总和
+            $type = $isObserve ? 1 : 2;
+            $upgradeType = UpgradeType::getOneByType($type);
+            // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
+            $userInfo['UPGRADE_TYPE'] = $upgradeType;
+            $userInfo['NOW_PERF'] = $userDecPvSum;
+            $userInfo['NEXT_PERF'] =  $nextLevelPerf;
+            // 用户可选择的级别列表
+            $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);
+            // 循环列表,补充升级所需要的补差
+            foreach ($userInfo['LEVEL_LIST'] as &$v) {
+                // 如果pv是0,则pv默认为用户当前级别的pv值
+                $v['REPAIR_PV'] = $v['PERF'] - $userInfo['NOW_PERF'];
+            }
+            // 如果用户是金卡,默认一千有问题.必须是相当于当前的PV 如果是银卡 则分2次升级,订单PV实际上不够3000,因为是补差
+            
+        }
+        
+        return static::notice(['baseInfo' => $userInfo]);
     }
 
     // 会员升级管理
     public function actionUpgrade() {
-        // 生成随机码 , 初始化redis
-        $userName = Info::generateWebUserName('CQ',9);
-        $redis = \Yii::$app->redis;
-
         if (\Yii::$app->request->isPost) {
+            // 开始升级
             $formModel = new DeclarationLoopForm();
             $formModel->scenario = 'userDec';
             $post = \Yii::$app->request->post();
-
-            // 针对于会员编号的判断
-            $insertUserName = strtoupper($post['insertUserName']);
-            $getRedisUserName = $redis->get('key_'.$insertUserName);
-            if (!$getRedisUserName){
-                return static::notice('会员编号过期',400);
-            }
-            if ($insertUserName != $getRedisUserName){
-                return static::notice('会员编号不符合',400);
-            }
-
-            $post['insertUserName'] = $insertUserName;
+            var_dump($post);exit;
             $post['type'] = DeclarationForm::TYPE_ZC;
             $allData['data'][] = $post;
             if ($formModel->load($allData, '') && $formModel->add()) {
@@ -284,17 +307,7 @@ class UserController extends BaseController {
         $query_condition.= ")";
 
         $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
-
-        //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
-        // 所有开户行
-        $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
-        if (!$userName) {
-            return static::notice('会员编号生成失败', 400);
-        }
-        //随机码保存在redis中方便进行比对
-        $msg = $redis->setex('key_'.$userName , 1800 , $userName);
-
-        return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
+        return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods]);
     }
 
 

+ 82 - 78
frontendEle/src/views/user/upgrade.vue

@@ -2,7 +2,7 @@
     <div v-loading="loading">
         <div class="white-box">
             <el-form :model="form" ref="form"  label-width="250px" class="form-page">
-                <div class="hr-tip"><span>账号信息</span></div>
+                <div class="hr-tip"><span>会员信息</span></div>
                 <el-form-item label="会员编号" prop="insertUserName">
                     <el-input v-model="form.insertUserName" 
                     placeholder="请输入要升级的会员编号"
@@ -11,7 +11,42 @@
                     >
                     </el-input>
                 </el-form-item>
-                <el-form-item>
+                <el-form-item label="会员级别">
+                    <el-input v-model="form.userDecName" 
+                    disabled
+                    >
+                    </el-input>
+                </el-form-item>
+                <el-form-item label="会员姓名">
+                    <el-input v-model="form.userRealName" 
+                    disabled
+                    >
+                    </el-input>
+                </el-form-item>
+                <el-form-item label="加入日期">
+                    <el-input v-model="form.addAt" 
+                    disabled
+                    >
+                    </el-input>
+                </el-form-item>
+                <el-form-item v-if="!isMax" label="升级级别" prop="upgradeValue">
+                    <el-select v-model="form.upgradeValue" placeholder="请选择级别" @change="changeLevel">
+                        <el-option
+                        v-for="item in upgradeOption"
+                        :key="item.ID"
+                        :label="item.LEVEL_NAME"
+                        :value="{value:item.ID, diffPv:item.REPAIR_PV}">
+                        </el-option>
+                    </el-select>
+                </el-form-item>
+                <el-form-item v-if="!isMax" label="升级补差额">
+                    <el-input v-model="needDiffPv" 
+                    disabled
+                    >
+                    </el-input>
+                </el-form-item>
+
+                <el-form-item v-if="!isMax">
                     <template slot="label">
                         升级购买商品
                     </template>
@@ -85,10 +120,10 @@
                         </el-tab-pane>
                     </el-tabs>
                 </el-form-item>
-                <el-form-item label="备注">
+                <el-form-item v-if="!isMax" label="备注">
                     <el-input type="textarea" v-model="form.remark"></el-input>
                 </el-form-item>
-                <el-form-item>
+                <el-form-item v-if="!isMax">
                     <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">保存</el-button>
                 </el-form-item>
             </el-form>
@@ -124,15 +159,18 @@
 
         data() {
             return {
-                rules:{
-                    ruleTime:[
-                        {required: true, message: '请输入地点', trigger: 'blur'}
-                    ],
-                },
+                needDiffPv:'',
+                isMax:true,
+                upgradeOption:[],
+                toLevel:'',
                 currentRow:null,
                 decWay:'1',
                 regionData: store.state.regionInfo.regionData,
                 form: {
+                    upgradeValue:'',
+                    addAt:'',
+                    userRealName:'',
+                    userDecName:'',
                     remark:'',
                     realName:'',
                     decLv: '',
@@ -141,37 +179,18 @@
                     recUserName:'',
                     conUserName:'',
                     insertUserIdCard:'',
-                    consignee:'',
-                    acceptMobile:'',
-                    areaSelected: [],
-                    address: '',
-                    openBank:'',
-                    bankAddress: '',
-                    bankProvince: '',
-                    bankCity: '',
-                    bankCounty: '',
-                    bankNo: '',
-                    bankAreaSelected: [],
-                    password:'111111',
-                    payPassword:'111111',
-                    mobile:'',
                     packageId:'',
                     goodsId:[],
                     goodsNum:[],
                     province:'',
                     city:'',
                     county:'',
-
-
+                    
                 },
-                conRealName: '-',
-                recRealName: '-',
                 num: 1,
                 tableData:null,
                 tableDatas:null,
-                allOpenBank: null,
                 allDecPackage:{},
-                allDecLevel: baseInfo.decLevels(),
                 loading: false,
                 submitButtonStat: false,
                 submitButton:false,
@@ -188,33 +207,33 @@
             upgradeInfo() {
                 if (this.form.insertUserName) {
                     network.postData(`user/upgrade-info`,{userName:this.form.insertUserName}).then(response => {
-                        console.log(response)
-                    
+                        this.form.addAt=response.baseInfo.ADD_AT
+                        this.form.userRealName=response.baseInfo.REAL_NAME
+                        this.form.userDecName=response.baseInfo.DEC_NAME
+                        this.isMax = response.baseInfo.IS_MAX
+                        this.upgradeOption = response.baseInfo.LEVEL_LIST
                     })
                 }
             },
-
+            changeLevel(data) {
+                let { value,diffPv } = data
+                this.needDiffPv = diffPv
+                this.toLevel = value
+            },
             getSum(){
                 let sell_price_sum=0,price_pv_sum=0;
                 this.multipleSelection.map((item,index)=>{
-                    console.log(item)
                     sell_price_sum+=Number(item.SELL_PRICE)*item.goodsNum;
                     price_pv_sum+=Number(item.PRICE_PV)*item.goodsNum;
                 })
                 this.sell_price_sum=tool.formatPrice(sell_price_sum);
                 this.price_pv_sum=tool.formatPrice(price_pv_sum);
-                console.log(this.sell_price_sum,this.price_pv_sum)
             },
             getData () {
-
                 network.getData(`user/upgrade`).then(response => {
-                    console.log(response)
                     this.loading = false;
-                    // this.form.insertUserName = response.userName;
-                    this.allOpenBank = response.allOpenBank;
                     this.allDecPackage = response.allDecPackage;
                     this.allGoods = response.allGoods;
-                    console.log(this.allDecPackage);
                     let settingObj=this.allDecPackage;
                     let settingArr = Object.keys(settingObj).map(key => {
                         //console.log(key); //为每个键名
@@ -227,10 +246,6 @@
                         settingObj1[i].goodsNum= 1 ;
                     }
                      this.tableDatas=settingObj1;
-                    // this.tableDatas=this.allGoods.map(item=>{return {...item,goodsNum:1}});
-
-                    console.log(this.tableDatas);
-                    console.log(this.numList);
                 }).catch(() => {
                 });
             },
@@ -242,13 +257,6 @@
 
                 console.log(this.form.packageId)
             },
-            // handleSelectionChange(val) {
-            //     this.multipleSelection = val;
-            //     this.form.goodsId = this.multipleSelection.map(item => item.ID)
-            //     this.form.goodsNum = this.multipleSelection.map(item=>{
-            //         return item.goodsNum
-            //     })
-            // },
             handleSelectionChange(val) {
                 let idx = -1,num;
                 for(let i in this.tableDatas){
@@ -283,40 +291,33 @@
             })
             },
             onSubmit() {
+                if (!this.form.insertUserName) {
+                    this.$message({
+                        message: '请输入会员编号',
+                        type: 'error'
+                    })
+                    return false;
+                }
+                if (!this.toLevel) {
+                    this.$message({
+                        message: '请选择级别',
+                        type: 'error'
+                    })
+                    return false
+                }
+                
                 this.getGoods();
                 this.submitButtonStat = true
                 let path = 'user/upgrade'
                 let postData = {
-                    consignee: this.form.consignee,
-                    acceptMobile: this.form.acceptMobile,
-                    province: this.form.areaSelected[0] ? this.form.areaSelected[0] : '',
-                    city: this.form.areaSelected[1] ? this.form.areaSelected[1] : '',
-                    county: this.form.areaSelected[2] ? this.form.areaSelected[2] : '',
-                    address: this.form.address,
-                    insertUserName: this.form.insertUserName,
-                    decLv: this.form.decLv,
-                    realName: this.form.realName,
-                    decUserName: this.form.decUserName,
-                    conUserName: this.form.conUserName,
-                    recUserName: this.form.recUserName,
-                    insertUserIdCard: this.form.insertUserIdCard,
-                    openBank: this.form.openBank,
-                    bankAddress: this.form.bankAddress,
-                    mobile: this.form.mobile,
-
-                    bankProvince: this.form.bankAreaSelected[0] ? this.form.bankAreaSelected[0] : '',
-                    bankCity: this.form.bankAreaSelected[1] ? this.form.bankAreaSelected[1] : '',
-                    bankCounty: this.form.bankAreaSelected[2] ? this.form.bankAreaSelected[2] : '',
-
-
-                    bankNo: this.form.bankNo,
-                    password: this.form.password,
-                    payPassword: this.form.payPassword,
+                    upgradeUserName: this.form.insertUserName,
                     packageId: this.form.packageId,
                     goodsId: this.form.goodsId,
                     goodsNum: this.form.goodsNum,
-                    location: this.form.location,
-                    decWay:this.decWay
+                    decWay:this.decWay,
+                    upgradeLv:this.toLevel, // 用户想升级到什么级别
+                    upgradeUserName:this.form.insertUserName, // 要升级的用户的编号
+                    remark:this.form.remark
                 }
 
                 return network.postData(path, postData).then(response => {
@@ -326,7 +327,7 @@
                         type: 'success'
                     })
                     this.submitButtonStat = false
-                    this.$router.go(-1)
+                    //this.$router.go(-1)
                 }).catch(() => {
                     this.submitButtonStat = false
                 })
@@ -406,4 +407,7 @@
     .flex{
         display: flex;
     }
+    .form-page{
+        width:100% !important;
+    }
 </style>