vip-service.js
4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const UserData = require('./user-data');
const _ = require('lodash');
const setPager = require(`${global.utils}/pager`).setPager;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
vipIndex(uid) {
let userDataModel = new UserData(this.ctx);
return userDataModel.getVIPInfoByUid(uid).then(vipInfo => {
let vip = {};
let data = {};
let scale = 1 / 3; // 分三等份
if (_.get(vipInfo, 'code', 400) !== 200) {
return vip;
}
data = vipInfo.data || {};
vip.level = parseInt(data.current_vip_level, 10) || 0;
vip.current_total_growth = parseInt(data.current_total_growth, 10) || 0;
vip.grades = [
{name: '普通会员', val: 0},
{name: '银卡会员', val: 800},
{name: '金卡会员', val: 3000},
{name: '白金会员', val: 7000}
];
// 还须要成长值
if (vip.grades[vip.level + 1]) {
vip.need_total_growth = vip.grades[vip.level + 1].val - vip.current_total_growth;
vip.need_total_growth = vip.need_total_growth > 0 ? vip.need_total_growth : 0;
}
// 进度条百分比
vip.current_total_percent = 1;
if (vip.current_total_growth <= vip.grades[1].val) {
vip.current_total_percent = (vip.current_total_growth * scale / vip.grades[1].val);
} else if (vip.current_total_growth <= vip.grades[2].val) {
vip.current_total_percent = (vip.current_total_growth * scale / vip.grades[2].val + scale);
} else if (vip.current_total_growth <= vip.grades[3].val) {
vip.current_total_percent = (vip.current_total_growth * scale / vip.grades[3].val + scale * 2);
}
vip.current_total_percent = (vip.current_total_percent * 100).toFixed(2);
vip.user_name = decodeURIComponent(this.ctx && this.ctx.req && this.ctx.req.user.name || '');
return vip;
});
}
getVipRecord(uid, params) {
let page = parseInt(params.page, 10) || 1;
let size = parseInt(params.size, 10) || 1;
let type = parseInt(params.type, 10) || 1;
let userDataModel = new UserData(this.ctx);
type = type > 0 && type < 3 ? type : 1;// 1 or 2
return userDataModel.getVipRecord({
uid: uid,
page: page,
size: size || 10,
type: type
}).then(d => {
let resData = {type: type};
if (d.code !== 200) {
return resData;
}
d.data = d.data || {};
let pagerList = setPager(_.get(d.data, 'pageSize', 1), Object.assign(params, {page: page}));
let total = _.get(d.data, 'total', 0);
resData.pager = Object.assign({
count: total,
curPage: total === 0 ? 0 : page,
totalPages: _.get(d.data, 'pageSize', 0)
}, pagerList);
if (type === 2) {
let liverData = [];
if (d.data.sliver_start_time) {
liverData.push({time: d.data.sliver_start_time, content: '普通升级银卡'});
}
if (d.data.gold_start_time) {
liverData.push({time: d.data.gold_start_time, content: '银卡升级金卡'});
}
if (d.data.whitegold_start_time) {
liverData.push({time: d.data.whitegold_start_time, content: '金卡升级白金'});
}
if (liverData.length) {
// 最多三条记录,默认显示分页数据
resData.pager = Object.assign({
count: 1,
curPage: 1,
totalPages: 1
});
}
resData.data = liverData;
return resData;
}
resData.data = d.data.data;
return resData;
});
}
};