passport.js
3.13 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
/**
* 获取资源位controller
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/12/01
*/
'use strict';
const _ = require('lodash');
const Promise = require('bluebird');
const co = Promise.coroutine;
const fp = require('lodash/fp');
const helpers = global.yoho.helpers;
// NOTE: 这里修改了图片质量的参数
helpers.image = _.flow(helpers.image, fp.replace(/\/quality\/\d*$/, '/quality/90'));
const passportModel = require('../models/passport');
const index = (req, res, next) => {
return co(function *() {
// 是否调用个人信息数字接口
let userInfo = {};
let uid = req.user.uid;
if (uid) {
// 获取个人信息VIP资料
let profile = yield passportModel.getUserProfile(uid).then(ret => {
if (ret && ret.code === 200) {
return ret.data;
}
return null;
});
let userNum = yield passportModel.getUserInfoNum(uid).then(ret => {
if (ret && ret.code === 200) {
return ret.data;
}
});
// 个人信息调用失败返回
if (profile) {
userInfo.result = 1;
console.log(profile);
let curYearCost = parseInt(_.get(profile, 'vip_info.curYearCost', 0)); //eslint-disable-line
let nextVipNeedCost = parseInt(_.get(profile, 'vip_info.nextVipNeedCost', 0)); //eslint-disable-line
Object.assign(userInfo, {
// 个人资料
profileName: _.get(profile, 'profile_name', ''),
headIco: _.get(profile, 'head_ico') ? helpers.image(_.get(profile, 'head_ico'), 63, 63) : '',
curTitle: _.get(profile, 'vip_info.title', 0),
// VIP信息
curYearCost: curYearCost,
nextLevel: _.get(profile, 'vip_info.next_level', 0),
nextVipTitle: _.get(profile, 'vip_info.nextVipTitle', 0),
nextVipNeedCost: nextVipNeedCost,
// 升级百分比
curYearCostPer: nextVipNeedCost ?
Math.round(curYearCost / (nextVipNeedCost + curYearCost) * 100) : 0,
// 待处理订单
order: _.get(userNum, 'wait_pay_num + wait_cargo_num + send_cargo_num', 0),
// 我的收藏
favorite: _.get(userNum, 'brand_favorite_total', 0),
// 我的优惠券
coupon: _.get(userNum, 'coupon_num', 0),
// 我的有货币
coin: _.get(userNum, 'yoho_coin_num', 0),
// 我的退换货
return: _.get(userNum, 'refund_exchange_num', 0)
});
return res.jsonp({
code: 200,
data: userInfo
});
}
}
return res.jsonp({
code: 400,
data: '',
message: '加载失败'
});
})().catch(next);
};
module.exports = {
index
};