会员等级经验问题

问题描述

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

修复方法

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

相关推荐
岁月宁静4 分钟前
一、《从零手撸 Agent》 我用 10 行代码跑通了第一次大模型调用(顺便踩了 4 个坑)
前端·python·agent
guanguan0_06 分钟前
用 AI 做技术方案评审:输入 3 个方案,输出对比矩阵 + 推荐理由
javascript·人工智能·矩阵·ai编程
geovindu8 分钟前
CSharp: State Pattern
开发语言·后端·c#·.net·状态模式·行为模式
IT小白杨13 分钟前
TikTok小店防封号浏览器实战:2026年多店铺环境隔离与账号安全运营技术解析
开发语言·数据库·安全·php·chrome devtools·指纹浏览器
Patrick在香港13 分钟前
Python 拉取 C&SD 官方 API:香港 2022 年已跨过“超老龄线“,而抚养比正在爬回 1961
android·c语言·python·数据分析·时序数据库·数据可视化·香港
2601_9669496518 分钟前
Python 量化开发为什么适合使用金融数据 SDK?从数据获取到策略研究的工程化实践
开发语言·python·数据分析·量化交易·股票数据·quantdash
万年咸鱼20 分钟前
Java ArrayList 详解:原理、用法与实战
java·开发语言·windows
计算机魔术师22 分钟前
Fable 5.1 来了,智能体任务成本降 45%——Anthropic 这次为何降价这么狠
前端
Csvn23 分钟前
现代 CSS 新特性深度:container query、:has()、@scope 与 subgrid
前端
长友cy24 分钟前
Qt官方示例Application源码阅读
开发语言·qt