会员等级经验问题
问题描述
会员从一级完成任务升级到二级以后,一级显示还差经验,这里差的其实是二级到三级的经验,如下图所示
修复方法
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
原文地址:https://blog.csdn.net/weixin_52673410/article/details/143918283
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!