会员等级经验问题

问题描述

会员从一级完成任务升级到二级以后,一级显示还差经验,这里差的其实是二级到三级的经验,如下图所示

修复方法

1、前端需要修改:

路径:/pages/users/user_vip/index.vue

方便复制:

v-if="item.lack_exp_num==0"

Copy

item.lack_exp_num

Copy

progressValue(item, index) { 
 let width = 100;
 let num = item.exp_num - parseFloat(item.lack_exp_num) 
 width = (num / item.exp_num)*100
 return { 
    'width': `${width}%`,
     'background-color': item.color, 
    };
 },

Copy

2、后端需要修改:

方便复制:

public function getUserLevelInfo(int $uid)
    {
        $data = ['user' => [], 'level_info' => [], 'level_list' => [], 'task' => []];
        //商城会员是否开启
        if (!sys_config('member_func_status')) {
            return $data;
        }
        /** @var UserServices $userServices */
        $userServices = app()->make(UserServices::class);
        $user = $userServices->getUserInfo($uid);
        if (!$user) {
            throw new ValidateException('没有此会员');
        }
        /** @var StoreCouponUserServices $storeCoupon */
        $storeCoupon = app()->make(StoreCouponUserServices::class);
        $user['couponCount'] = $storeCoupon->getUserValidCouponCount((int)$uid);
        $data['user'] = $user;
        /** @var SystemUserLevelServices $systemUserLevel */
        $systemUserLevel = app()->make(SystemUserLevelServices::class);
        $levelList = $systemUserLevel->getList(['is_del' => 0, 'is_show' => 1]);
        $i = 0;
        foreach ($levelList as &$level) {
            $level['next_exp_num'] = $levelList[$i + 1]['exp_num'] ?? $level['exp_num'];
            $level['image'] = set_file_url($level['image']);
            $level['icon'] = set_file_url($level['icon']);
            $i++;
        }
        $data['level_list'] = $levelList;
        $levelInfo = $this->getUerLevelInfoByUid($uid);
        if (!$levelInfo) {//不存在等级 展示最低等级
            /** @var SystemUserLevelServices $systemUserLevel */
            $systemUserLevel = app()->make(SystemUserLevelServices::class);
            $alllevelInfo = $systemUserLevel->getList([['is_del', '=', 0], ['is_show', '=', 1]], 'id,name,icon,grade', 1, 1);
            $levelInfo = $alllevelInfo[0] ?? [];
            if ($levelInfo) {
                $levelInfo['id'] = 0;
            }
        }
        if ($levelInfo) {
            $levelInfo['vip'] = true;
            $levelInfo['vip_id'] = $levelInfo['id'];
            $levelInfo['vip_icon'] = $levelInfo['icon'];
            $levelInfo['vip_name'] = $levelInfo['name'];
        }
        $data['level_info'] = $levelInfo;
        $i = 0;
        foreach ($levelList as &$level) {
            if ($level['grade'] < $levelInfo['grade']) {
                $level['next_exp_num'] = $levelList[$i + 1]['exp_num'] ?? $level['exp_num'];
                $level['lack_exp_num'] = 0;
            } else {
                $level['next_exp_num'] = $level['exp_num'];
                if ($user['exp'] > $level['exp_num']) {
                    $level['lack_exp_num'] = 0;
                } else {
                    $level['lack_exp_num'] = bcsub((string)$level['exp_num'], (string)$user['exp'], 0);
                }
            }


            $level['image'] = set_file_url($level['image']);
            $level['icon'] = set_file_url($level['icon']);
            $i++;
        }
        $data['level_list'] = $levelList;


        $data['level_info']['exp'] = $user['exp'] ?? 0;


        /** @var UserBillServices $userBillservices */
        $userBillservices = app()->make(UserBillServices::class);
        $data['level_info']['today_exp'] = $userBillservices->getExpSum($uid, 'today');
        $task = [];
        /** @var UserSignServices $userSignServices */
        $userSignServices = app()->make(UserSignServices::class);
        $task['sign_count'] = $userSignServices->getSignSumDay($uid);
        $config = SystemConfigService::more(['sign_give_exp', 'order_give_exp', 'invite_user_exp']);
        $task['sign'] = $config['sign_give_exp'] ?? 0;
        $task['order'] = $config['order_give_exp'] ?? 0;
        $task['invite'] = $config['invite_user_exp'] ?? 0;
        $data['task'] = $task;


        //检测升级
        UserLevelJob::dispatch([$uid]);
        return $data;
    }

Copy

3、改完前端需要重新打包小程序、h5,后端要重启swoole

相关推荐
ekskef_sef30 分钟前
32岁前端干了8年,是继续做前端开发,还是转其它工作
前端
飞飞-躺着更舒服36 分钟前
【QT】实现电子飞行显示器(改进版)
开发语言·qt
武昌库里写JAVA1 小时前
Java成长之路(一)--SpringBoot基础学习--SpringBoot代码测试
java·开发语言·spring boot·学习·课程设计
sunshine6411 小时前
【CSS】实现tag选中对钩样式
前端·css·css3
真滴book理喻1 小时前
Vue(四)
前端·javascript·vue.js
蜜獾云1 小时前
npm淘宝镜像
前端·npm·node.js
dz88i81 小时前
修改npm镜像源
前端·npm·node.js
Jiaberrr1 小时前
解锁 GitBook 的奥秘:从入门到精通之旅
前端·gitbook
ZSYP-S1 小时前
Day 15:Spring 框架基础
java·开发语言·数据结构·后端·spring
yuanbenshidiaos2 小时前
c++------------------函数
开发语言·c++