Authored by yyq

Merge branch 'release/5.3' of git.yoho.cn:fe/yohobuy-node into release/5.3

/**
* 获取资源位 banner广告 controller
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/11/30
*/
'use strict';
const getBannerModel = require('../models/getBanner');
const helpers = global.yoho.helpers;
const index = (req, res, next) => {
let contentCode = req.query.content_code || '';
let width = req.query.width || '';
let height = req.query.height || '';
getBannerModel.getResource(contentCode).then(data => {
let banner = '';
if (data.data) {
// 获取banner数据
let result = data.data[0];
if (result && result.data) {
if (result.template_name === 'single_image') {
banner = result.data[0];
} else if (result.template_name === 'single_name_image') {
banner = result.data;
}
if (banner) {
if (!width || !height) {
width = 2600;
height = 60;
}
}
banner.src = helpers.image(banner.src, width, height, 2);
banner.url = banner.url;
}
}
res.jsonp({
code: banner ? 200 : 400,
data: banner
});
}).catch(next);
};
module.exports = {
index
};
... ...
/**
* 获取资源位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 helpers = global.yoho.helpers;
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;
Object.assign(userInfo, {
// 个人资料
profileName: _.get(profile, 'profile_name', ''),
headIco: !_.get(profile, 'head_ico') ? helpers.image(_.get(profile, 'head_ico'), 63, 63) : '',
// VIP信息
curYearCost: _.get(profile, 'vip_info.curYearCost', 0),
nextLevel: _.get(profile, 'vip_info.next_level', 0),
nextVipTitle: _.get(profile, 'vip_info.nextVipTitle', 0),
nextVipNeedCost: _.get(profile, 'vip_info.nextVipNeedCost', 0),
// 升级百分比
curYearCostPer: userInfo.nextVipNeedCost ? Math.round(profile.curYearCost / profile.nextVipNeedCost * 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
};
... ...
/**
* getBanner model
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/11/30
*/
'use strict';
const serviceApi = global.yoho.ServiceAPI;
const URL_OPERATIONS_RESOURCE_GET = 'operations/api/v5/resource/get';
/**
* 获取资源数据
*
* @string content_code
* @return array
*/
const getResource = content_code => { //eslint-disable-line
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
content_code: content_code
}, {cache: true});
};
module.exports = {
getResource
};
... ...
/**
* getBanner model
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/12/01
*/
'use strict';
const api = global.yoho.API;
const config = global.yoho.config;
/**
* 获取用户信息
* @param uid
* @return string
*/
const getUserProfile = uid => {
let params = {
method: 'app.passport.profile',
uid: uid
};
return api.get('', params, config.apiCache);
};
/**
* 获取用户信息
* @param uid
* @return string
*/
const getUserInfoNum = uid => {
let params = {
method: 'app.home.getInfoNum',
uid: uid
};
return api.get('', params, config.apiCache);
};
module.exports = {
getUserProfile,
getUserInfoNum
};
... ...
... ... @@ -15,6 +15,8 @@ var multipartMiddleware = multipart();
const rvCtrl = require(`${cRoot}/recent-view`);
const uploadCtrl = require(`${cRoot}/upload`);
const erp2goods = require(`${cRoot}/erp2goods`);
const getBanner = require(`${cRoot}/getBanner`);
const passport = require(`${cRoot}/passport`);
router.get('/recentReview', rvCtrl.index); // 最近浏览
... ... @@ -22,4 +24,12 @@ router.post('/upload/image', multipartMiddleware, uploadCtrl.uploadImg);
router.get('/erp2goods', erp2goods.find);
router.get('/getbanner', getBanner.index);
router.get('/passport', passport.index);
module.exports = router;
... ...
... ... @@ -4,5 +4,5 @@
{{^}}
<i class="help-us-icon"></i>
{{/if}}
<span class="help-us-txt">客服电话:400-889-9646 08:00-22:30(周一至周日)</span>
</div>
\ No newline at end of file
<span class="help-us-txt">客服电话:400-889-9646 09:00-22:30(周一至周日)</span>
</div>
... ...