Authored by lijing

会员页优化

@@ -155,10 +155,12 @@ exports.grade = (req, res, next) => { @@ -155,10 +155,12 @@ exports.grade = (req, res, next) => {
155 pageFooter: true 155 pageFooter: true
156 }; 156 };
157 157
158 - indexModel.getGrade({ 158 + let param = {
159 uid: req.user.uid, 159 uid: req.user.uid,
160 channel: req.query.channel || 1 160 channel: req.query.channel || 1
161 - }).then((result) => { 161 + };
  162 +
  163 + indexModel.getGrade(param).then((result) => {
162 res.render('vip-grade/vip-grade', Object.assign(result, responseData)); 164 res.render('vip-grade/vip-grade', Object.assign(result, responseData));
163 }).catch(next); 165 }).catch(next);
164 166
@@ -185,10 +187,12 @@ exports.preferential = (req, res, next) => { @@ -185,10 +187,12 @@ exports.preferential = (req, res, next) => {
185 pageFooter: true 187 pageFooter: true
186 }; 188 };
187 189
188 - indexModel.getPreferential({ 190 + let param = {
189 uid: req.user.uid, 191 uid: req.user.uid,
190 channel: req.query.channel || 1 192 channel: req.query.channel || 1
191 - }).then((result) => { 193 + };
  194 +
  195 + indexModel.getPreferential(param).then((result) => {
192 res.render('vip-grade/privilege', Object.assign(result, responseData)); 196 res.render('vip-grade/privilege', Object.assign(result, responseData));
193 }).catch(next); 197 }).catch(next);
194 198
@@ -220,7 +220,7 @@ const delRecord = (uid, skn) => { @@ -220,7 +220,7 @@ const delRecord = (uid, skn) => {
220 * 会员等级 220 * 会员等级
221 * @param params 221 * @param params
222 */ 222 */
223 -const getGradeGrade = (channel, uid) => { 223 +const getGradeGrade = (uid, channel) => {
224 return api.get('', { 224 return api.get('', {
225 method: 'app.passport.vip', 225 method: 'app.passport.vip',
226 uid: uid, 226 uid: uid,
@@ -228,108 +228,119 @@ const getGradeGrade = (channel, uid) => { @@ -228,108 +228,119 @@ const getGradeGrade = (channel, uid) => {
228 }, {code: 200}); 228 }, {code: 200});
229 }; 229 };
230 230
231 -const getGradeUser = (channel, uid) => {  
232 - if (uid) {  
233 - return api.get('', {  
234 - method: 'app.passport.profile',  
235 - uid: uid,  
236 - channel: channel || 1  
237 - }, {code: 200});  
238 - } 231 +const getGradeUser = (uid, channel) => {
  232 + return api.get('', {
  233 + method: 'app.passport.profile',
  234 + uid: uid,
  235 + channel: channel || 1
  236 + }, {code: 200});
239 }; 237 };
240 238
241 -const getGrade = (channel, uid) => { 239 +const getGrade = (param) => {
  240 + if (param.uid) {
  241 + return api.all([
  242 + getGradeGrade(param.uid, param.channel),
  243 + getGradeUser(param.uid, param.channel)
  244 + ]).then((result) => {
242 245
243 - return api.all([  
244 - getGradeGrade(channel, uid),  
245 - getGradeUser(channel, uid)  
246 - ]).then((result) => { 246 + let resu = {
  247 + vipGrade: []
  248 + };
247 249
248 - let resu = {  
249 - vipGrade: []  
250 - }; 250 + let enp = {};
251 251
252 - let enp = {}; 252 + let obj = {
  253 + privilege: []
  254 + };
253 255
254 - let obj = {  
255 - privilege: []  
256 - }; 256 + if (result[0] && result[0].data) {
257 257
258 - if (result[0] && result[0].data) { 258 + _.forEach(result[0].data.enjoy_preferential, function(val) {
259 259
260 - _.forEach(result[0].data.enjoy_preferential, function(val) { 260 + enp = {
  261 + description: val.description,
  262 + pic: val.pic,
  263 + title: val.title
  264 + };
261 265
262 - enp = {  
263 - description: val.description,  
264 - pic: val.pic,  
265 - title: val.title  
266 - }; 266 + obj.privilege.push(enp);
267 267
268 - obj.privilege.push(enp); 268 + });
269 269
270 - }); 270 + switch (result[0].data.current_vip_level) {
  271 + case '0':// 普通会员
  272 + obj = _.assign(obj, {
  273 + vip0: true
  274 + });
  275 + break;
  276 + case '1':// 银卡会员
  277 + obj = _.assign(obj, {
  278 + vip1: true
  279 + });
  280 + break;
  281 + case '2':// 金卡会员
  282 + obj = _.assign(obj, {
  283 + vip2: true
  284 + });
  285 + break;
  286 + case '3':// 白金会员
  287 + obj = _.assign(obj, {
  288 + vip3: true
  289 + });
  290 + break;
  291 + default :
271 292
272 - switch (result[0].data.current_vip_level) {  
273 - case '0':// 普通会员  
274 - obj = _.assign(obj, {  
275 - vip0: true  
276 - });  
277 - break;  
278 - case '1':// 银卡会员  
279 - obj = _.assign(obj, {  
280 - vip1: true  
281 - });  
282 - break;  
283 - case '2':// 金卡会员 293 + }
  294 +
  295 + let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2);
  296 +
  297 + obj = _.assign(obj, {
  298 + costOfThisYear: result[0].data.current_year_cost,
  299 + sumCost: result[0].data.current_total_cost,
  300 + allUrl: helpers.urlFormat('/home/preferential'),
  301 + costGap: upg
  302 + });
  303 +
  304 + if (result[0].data.next_need_cost === 0) {
  305 + // 当vip等级升至顶级时,进度条满格
284 obj = _.assign(obj, { 306 obj = _.assign(obj, {
285 - vip2: true 307 + percent: 100
286 }); 308 });
287 - break;  
288 - case '3':// 白金会员 309 + } else {
  310 +
  311 + let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2);
  312 +
289 obj = _.assign(obj, { 313 obj = _.assign(obj, {
290 - vip3: true 314 + percent: perf
291 }); 315 });
292 - break;  
293 - default :  
294 -  
295 - }  
296 316
297 - let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2); 317 + }
298 318
299 - obj = _.assign(obj, {  
300 - costOfThisYear: result[0].data.current_year_cost,  
301 - sumCost: result[0].data.current_total_cost,  
302 - allUrl: helpers.urlFormat('/home/preferential'),  
303 - costGap: upg  
304 - }); 319 + }
305 320
306 - if (result[0].data.next_need_cost === 0) {  
307 - // 当vip等级升至顶级时,进度条满格 321 + if (result[0] && result[0].data) {
308 obj = _.assign(obj, { 322 obj = _.assign(obj, {
309 - percent: 100 323 + name: result[1].data.nickname
310 }); 324 });
311 - } else {  
312 -  
313 - let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2); 325 + }
314 326
315 - obj = _.assign(obj, {  
316 - percent: perf  
317 - }); 327 + resu.vipGrade.push(obj);
318 328
319 - } 329 + return resu;
  330 + });
  331 + } else {
  332 + return api.get('', {
320 333
321 - } 334 + }).then(() => {
322 335
323 - if (result[0] && result[0].data) {  
324 - obj = _.assign(obj, {  
325 - name: result[1].data.nickname  
326 - });  
327 - } 336 + let resu = {
  337 + vipGrade: []
  338 + };
328 339
329 - resu.vipGrade.push(obj); 340 + return resu;
  341 + });
330 342
331 - return resu;  
332 - }); 343 + }
333 }; 344 };
334 345
335 /** 346 /**
@@ -49,7 +49,7 @@ router.get('/cancelOrder', orderDetailController.cancelOrder); // 取消订单 @@ -49,7 +49,7 @@ router.get('/cancelOrder', orderDetailController.cancelOrder); // 取消订单
49 router.get('/', homeController.index); // 个人中心首页 49 router.get('/', homeController.index); // 个人中心首页
50 router.get('/mydetails', homeController.myDetails); // 个人基本资料页面 50 router.get('/mydetails', homeController.myDetails); // 个人基本资料页面
51 51
52 -router.get('/grade', homeController.grade); // 会员等级页 52 +router.get('/grade', auth, homeController.grade); // 会员等级页
53 router.get('/privilege', homeController.preferential); // 会员特权列表页 53 router.get('/privilege', homeController.preferential); // 会员特权列表页
54 54
55 router.get('/mycurrency', currencyController.myCurrency); // yoho币总数 55 router.get('/mycurrency', currencyController.myCurrency); // yoho币总数