Authored by zhangxiaoru

channel 频道

... ... @@ -28,7 +28,7 @@ let _renderData = {
* @return {[type]}
*/
let _channelPage = (req, res, data) => {
return channelModel.getChannelData({
return req.ctx(channelModel).getChannelData({
gender: data.gender,
uid: req.user.uid,
limit: 6// 首屏先获取前6个楼层,其余用ajax获取
... ... @@ -70,9 +70,9 @@ let _channelPage = (req, res, data) => {
/**
* 获取首页频道其余楼层
*/
let getResourceContent = (req, res, next) => {
exports.getResourceContent = (req, res, next) => {
return channelModel.getChannelResource({
return req.ctx(channelModel).getChannelResource({
gender: req.query.gender,
uid: req.user.uid,
}).then(result => {
... ... @@ -91,8 +91,8 @@ let getResourceContent = (req, res, next) => {
/**
* 频道选择页
*/
let index = (req, res, next) => {
channelModel.getChannelSwitchData().then((result) => {
exports.index = (req, res, next) => {
req.ctx(channelModel).getChannelSwitchData().then((result) => {
res.render('channel-index', {
module: 'channel',
page: 'index',
... ... @@ -115,7 +115,7 @@ let index = (req, res, next) => {
* @param {Function} next
* @return {Function}
*/
let switchChannel = (req, res, next) => {
exports.switchChannel = (req, res, next) => {
let channel = req.yoho.channel;
// 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页
... ... @@ -131,7 +131,7 @@ let switchChannel = (req, res, next) => {
/**
* 男生首页
*/
let boys = (req, res, next) => {
exports.boys = (req, res, next) => {
_channelPage(req, res, {
gender: 'boys',
... ... @@ -144,7 +144,7 @@ let boys = (req, res, next) => {
/**
* 女生首页
*/
let girls = (req, res, next) => {
exports.girls = (req, res, next) => {
_channelPage(req, res, {
gender: 'girls',
... ... @@ -158,7 +158,7 @@ let girls = (req, res, next) => {
* 潮童首页
*/
let kids = (req, res, next) => {
exports.kids = (req, res, next) => {
_channelPage(req, res, {
gender: 'kids',
... ... @@ -171,7 +171,7 @@ let kids = (req, res, next) => {
/**
* 创意生活首页
*/
let lifestyle = (req, res, next) => {
exports.lifestyle = (req, res, next) => {
_channelPage(req, res, {
gender: 'lifestyle',
... ... @@ -187,10 +187,10 @@ let lifestyle = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let bottomBanner = (req, res, next) => {
exports.bottomBanner = (req, res, next) => {
let gender = req.query.gender || 'boys';
channelModel.getBottomBannerData(gender).then(result => {
req.ctx(channelModel).getBottomBannerData(gender).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -198,8 +198,8 @@ let bottomBanner = (req, res, next) => {
/**
* 店铺推荐收藏状态人数
*/
let shopRecom = (req, res, next) => {
channelModel.shopRecom({
exports.shopRecom = (req, res, next) => {
req.ctx(channelModel).shopRecom({
shopIds: req.body.shopIds || '',
uid: req.user.uid || 0,
}).then(result => {
... ... @@ -210,7 +210,7 @@ let shopRecom = (req, res, next) => {
/**
* 获取用户vip信息
*/
let userVip = (req, res, next) => {
exports.userVip = (req, res, next) => {
let uid = req.user.uid;
if (!uid) {
... ... @@ -219,7 +219,7 @@ let userVip = (req, res, next) => {
msg: '未登录'
});
} else {
homeModel.getGradeGrade(uid, req.query.channel || 1).then(result => {
req.ctx(homeModel).getGradeGrade(uid, req.query.channel || 1).then(result => {
if (result.code === 200) {
res.json({
code: 200,
... ... @@ -233,18 +233,4 @@ let userVip = (req, res, next) => {
}
}).catch(next);
}
};
module.exports = {
switchChannel,
index,
boys,
girls,
kids,
lifestyle,
bottomBanner,
shopRecom,
userVip,
getResourceContent
};
... ...
... ... @@ -56,281 +56,279 @@ const channelList = [{
entitle: 'LIFESTYLE'
}];
/**
* 获取二级菜单顶部颜色
* @param {[string]} choosed
* @return {[string]}
*/
const _getSidebarColor = (choosed) => {
let color = false;
if (choosed === 'girls') {
color = '#FF88AE';
} else if (choosed === 'kids') {
color = '#7ad9f9';
} else if (choosed === 'lifestyle') {
color = '#4f4138';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return color;
};
/**
* 处理侧边栏数据
* @param {[array]} list
* @return {[array]}
*/
const _processSideBar = (list, choosed) => {
const formatData = [];
let offset = 0; // 分割数组用到的游标
list = list || [];
_.forEach(list, (item, i) => {
if (item.sub) {
item.sub.unshift({
sort_name: item.sort_name,
sort_name_en: item.sort_name_en,
back: true,
isSelect: false,
bgColor: _getSidebarColor(choosed)
});
}
// 如果有分隔符,分割数组
if (item.separative_sign === 'Y') {
formatData.push(list.slice(offset, i));
offset = i;
/**
* 获取二级菜单顶部颜色
* @param {[string]} choosed
* @return {[string]}
*/
_getSidebarColor(choosed) {
let color = false;
if (choosed === 'girls') {
color = '#FF88AE';
} else if (choosed === 'kids') {
color = '#7ad9f9';
} else if (choosed === 'lifestyle') {
color = '#4f4138';
}
});
// 数组被分割剩余的部分
formatData.push(list.slice(offset));
return formatData;
};
/**
* 获取频道页面资源位
* @param {[object]} gender
* @return {[type]}
*/
const getChannelResource = (params) => {
params.gender = params.gender || 'boys';
params.limit = params.limit || 30;
params = Object.assign(params, {
gender: genderData[params.gender] || '1,2,3',
content_code: contentCode[params.gender], // eslint-disable-line
page: 1
});
if (!params.uid) {
params.new_device = true; // eslint-disable-line
return color;
}
params.new_device = true;
return api.get('operations/api/v5/resource/home', params, {
cache: true
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
/**
* 处理侧边栏数据
* @param {[array]} list
* @return {[array]}
*/
_processSideBar(list, choosed) {
const formatData = [];
let offset = 0; // 分割数组用到的游标
list = list || [];
_.forEach(list, (item, i) => {
if (item.sub) {
item.sub.unshift({
sort_name: item.sort_name,
sort_name_en: item.sort_name_en,
back: true,
isSelect: false,
bgColor: this._getSidebarColor(choosed)
});
}
return resourcesProcess(result.data.list);
} else {
logger.error('index resouce is not 200');
return result;
}
});
};
/**
* 获取左侧边栏数据
* @param {[string]} choosed
* @return {[object]}
*/
const _getLeftNav = (choosed) => {
choosed = choosed || 'all';
return api.get('operations/api/v6/category/getCategory', {}, {
cache: true
}).then(result => {
// console.log(result)
if (result && result.code === 200) {
return _processSideBar(result.data, choosed);
} else {
logger.error('sidebar code is not 200');
return result;
}
});
};
// 如果有分隔符,分割数组
if (item.separative_sign === 'Y') {
formatData.push(list.slice(offset, i));
offset = i;
}
});
/**
* 获取热门搜索
**/
const _getSearchIndex = (params) => {
let channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
if (params.gender && channels[params.gender]) {
params.yh_channel = channels[params.gender];
delete params.gender;
// 数组被分割剩余的部分
formatData.push(list.slice(offset));
return formatData;
}
return API.get('', _.assign({
method: 'app.search.getTerms'
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('Hot Search return code is not 200');
return {};
/**
* 获取频道页面资源位
* @param {[object]} gender
* @return {[type]}
*/
getChannelResource(params) {
params.gender = params.gender || 'boys';
params.limit = params.limit || 30;
params = Object.assign(params, {
gender: genderData[params.gender] || '1,2,3',
content_code: contentCode[params.gender], // eslint-disable-line
page: 1
});
if (!params.uid) {
params.new_device = true; // eslint-disable-line
}
});
};
/**
* 获取频道选择页数据
* @return {[type]}
*/
const _getChannelList = () => {
return api.get('operations/api/v5/entrance/getEntrance', {}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
const list = {};
list.channelList = [];
list.yohood = {};
result.data.list = result.data.list || [];
_.forEach(result.data.list, function(item) {
let id = _.toNumber(item.id);
const channel = channelList[id - 1];
if (channel) {
list.channelList.push(channel);
}
params.new_device = true;
if (id === 5) {
list.yohood.showYohood = true;
list.yohood.yohoodHref = 'http://www.yohood.cn';
return api.get('operations/api/v5/resource/home', params, {
cache: true
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
}
return resourcesProcess(result.data.list);
} else {
logger.error('index resouce is not 200');
return result;
}
});
}
if (id === 6) {
list.double11 = {};
list.double11.href = item.url;
}
});
/**
* 获取左侧边栏数据
* @param {[string]} choosed
* @return {[object]}
*/
_getLeftNav(choosed) {
choosed = choosed || 'all';
return Object.keys(list).length ? list : {
channelList: channelList
};
} else {
logger.error('channel select code is not 200');
return {
channelList: channelList
};
}
});
};
return api.get('operations/api/v6/category/getCategory', {}, {
cache: true
}).then(result => {
// console.log(result)
if (result && result.code === 200) {
return this._processSideBar(result.data, choosed);
} else {
logger.error('sidebar code is not 200');
return result;
}
});
}
/**
* 获取频道选择页 背景
* @return {[type]}
*/
const _getChannelBg = () => {
return api.get('operations/api/v5/resource/get', {
content_code: contentCode.index
}, {
cache: true
}).then(result => {
if (result && result.code === 200) {
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
} else {
logger.error('channel select background code is not 200');
return {
src: ''
};
/**
* 获取热门搜索
**/
_getSearchIndex(params) {
let channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
if (params.gender && channels[params.gender]) {
params.yh_channel = channels[params.gender];
delete params.gender;
}
});
};
/**
* 获取频道选择页面数据
* @param {[string]} gender
* @return {[type]}
*/
let getChannelSwitchData = () => {
return Promise.all([_getChannelList(), _getChannelBg()]);
};
/**
* 获取频道页面数据
* @param {[object]} params
* @return {[object]}
*/
let getChannelData = (params) => {
var channelData = {};
let navGender = _.cloneDeep(params.gender);
return Promise.all([getChannelResource(params), _getLeftNav(navGender), _getSearchIndex({
gender: navGender,
uid: params.uid,
})]).then((data) => {
channelData.content = data[0] || []; // 资源位数据
channelData.sideNav = data[1] || []; // 侧边栏数据
channelData.defaultTerms = (data[2] && data[2].defaultTerms && data[2].defaultTerms.length) ?
data[2].defaultTerms[0].content : '搜索商品、品牌';
return channelData;
});
};
return API.get('', _.assign({
method: 'app.search.getTerms'
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('Hot Search return code is not 200');
return {};
}
});
}
/**
* 获取频道页底部 bannel 数据
* @param {[string]} gender
* @return {[type]}
*/
let getBottomBannerData = (gender) => {
gender = gender || 'boys';
/**
* 获取频道选择页数据
* @return {[type]}
*/
_getChannelList() {
return api.get('operations/api/v5/entrance/getEntrance', {}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
const list = {};
list.channelList = [];
list.yohood = {};
result.data.list = result.data.list || [];
_.forEach(result.data.list, function(item) {
let id = _.toNumber(item.id);
const channel = channelList[id - 1];
if (channel) {
list.channelList.push(channel);
}
if (id === 5) {
list.yohood.showYohood = true;
list.yohood.yohoodHref = 'http://www.yohood.cn';
}
if (id === 6) {
list.double11 = {};
list.double11.href = item.url;
}
});
return Object.keys(list).length ? list : {
channelList: channelList
};
} else {
logger.error('channel select code is not 200');
return {
channelList: channelList
};
}
});
}
if (gender === 'boys' || gender === 'girls') {
/**
* 获取频道选择页 背景
* @return {[type]}
*/
_getChannelBg() {
return api.get('operations/api/v5/resource/get', {
content_code: bottomBannerCode[gender] // eslint-disable-line
content_code: contentCode.index
}, {
cache: true
}).then(result => {
if (result && result.code === 200) {
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
} else {
logger.error('channel select background code is not 200');
return {
src: ''
};
}
});
}
return Promise.resolve({
code: 400,
data: '',
message: '参数错误'
});
};
/**
* 获取店铺推荐收藏和人数
*/
let shopRecom = (params) => {
return API.get('', {
method: 'app.shops.floorNewInfo',
shop_ids: params.shopIds,
uid: params.uid,
});
};
/**
* 获取频道选择页面数据
* @param {[string]} gender
* @return {[type]}
*/
getChannelSwitchData() {
return Promise.all([this._getChannelList(), this._getChannelBg()]);
}
module.exports = {
getChannelData,
getChannelResource,
getChannelSwitchData,
getBottomBannerData,
shopRecom,
/**
* 获取频道页面数据
* @param {[object]} params
* @return {[object]}
*/
getChannelData(params) {
var channelData = {};
let navGender = _.cloneDeep(params.gender);
return Promise.all([this.getChannelResource(params), this._getLeftNav(navGender), this._getSearchIndex({
gender: navGender,
uid: params.uid,
})]).then((data) => {
channelData.content = data[0] || []; // 资源位数据
channelData.sideNav = data[1] || []; // 侧边栏数据
channelData.defaultTerms = (data[2] && data[2].defaultTerms && data[2].defaultTerms.length) ?
data[2].defaultTerms[0].content : '搜索商品、品牌';
return channelData;
});
}
/**
* 获取频道页底部 bannel 数据
* @param {[string]} gender
* @return {[type]}
*/
getBottomBannerData(gender) {
gender = gender || 'boys';
if (gender === 'boys' || gender === 'girls') {
return api.get('operations/api/v5/resource/get', {
content_code: bottomBannerCode[gender] // eslint-disable-line
}, {
cache: true
});
}
return Promise.resolve({
code: 400,
data: '',
message: '参数错误'
});
}
/**
* 获取店铺推荐收藏和人数
*/
shopRecom(params) {
return API.get('', {
method: 'app.shops.floorNewInfo',
shop_ids: params.shopIds,
uid: params.uid,
});
}
};
... ...
... ... @@ -30,7 +30,7 @@ exports.index = (req, res, next) => {
// 唤起 APP 的路径
res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy= {"action":"go.mine"}';
indexModel.index(params).then(result => {
req.ctx(indexModel).index(params).then(result => {
if (result) {
res.render('home', Object.assign(result, {
... ... @@ -72,7 +72,7 @@ exports.myDetails = (req, res, next) => {
let uid = req.user.uid;
indexModel.myDetails(uid).then(result => {
req.ctx(indexModel).myDetails(uid).then(result => {
res.render('personal-details', Object.assign(responseData, result));
}).catch(next);
};
... ... @@ -108,7 +108,7 @@ exports.record = (req, res, next) => {
localCss: true
};
indexModel.recordContent(uid, udid, page, limit).then((result) => {
req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
if (result && result.browseRecord && result.browseRecord.length > 0) {
responseData.browseRecord = result.browseRecord;
... ... @@ -137,7 +137,7 @@ exports.recordContent = (req, res, next) => {
let limit = 10;
indexModel.recordContent(uid, udid, page, limit).then((result) => {
req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
if (result.browseRecord && result.browseRecord.length === 0) {
res.json(false);
... ... @@ -160,7 +160,7 @@ exports.delRecord = (req, res, next) => {
let skn = req.query.skn || 0;
indexModel.delRecord(uid, skn).then((result) => {
req.ctx(indexModel).delRecord(uid, skn).then((result) => {
res.json({
code: result.code,
message: result.message
... ... @@ -195,7 +195,7 @@ exports.grade = (req, res, next) => {
channel: req.query.channel || 1
};
indexModel.getGrade(param).then((result) => {
req.ctx(indexModel).getGrade(param).then((result) => {
res.render('vip-grade/vip-grade', Object.assign(result, responseData));
}).catch(next);
... ... @@ -228,7 +228,7 @@ exports.preferential = (req, res, next) => {
channel: req.query.channel || 1
};
indexModel.getPreferential(param).then((result) => {
req.ctx(indexModel).getPreferential(param).then((result) => {
res.render('vip-grade/privilege', Object.assign(result, responseData));
}).catch(next);
... ...
... ... @@ -16,499 +16,492 @@ const service = global.yoho.ServiceAPI;
const utils = '../../../utils';
const resourcesProcess = require(`${utils}/resources-process`);
/**
* 个人详情数据
*/
const _userData = (params) => {
if (params.uid) {
return api.get('', {
method: 'app.passport.profile',
uid: params.uid
}, {
code: 200
});
} else {
return Promise.resolve({});
}
};
/**
* 获取个人中心公告有关数据
*/
const _noticeData = () => {
return api.get('', {
method: 'app.resources.getNotices'
}, {
code: 200
});
};
/**
* 收藏数量接口
* @param params
* @returns {*|Promise.<TResult>}
*/
const _favoriteData = (params) => {
if (params.uid) {
return singleAPI.get('favorite', {
method: 'app.favorite.getFavoriteCount',
uid: params.uid
}, {
code: 200
});
} else {
return false;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
};
/**
* 个人中心页面优惠券,收藏的商品等的数目数据
*/
const _infoNum = (params) => {
if (params.uid) {
return api.get('', {
method: 'app.home.getInfoNum',
uid: params.uid,
udid: params.udid
}, {
code: 200
});
} else {
return false;
/**
* 个人详情数据
*/
_userData(params) {
if (params.uid) {
return api.get('', {
method: 'app.passport.profile',
uid: params.uid
}, {
code: 200
});
} else {
return Promise.resolve({});
}
}
};
/**
* 从接口获取地址列表
* @param params
*/
const _getAddressData = (params) => {
if (params.uid) {
/**
* 获取个人中心公告有关数据
*/
_noticeData() {
return api.get('', {
method: 'app.address.gethidden',
uid: params.uid
method: 'app.resources.getNotices'
}, {
code: 200
});
} else {
return false;
}
};
// 资源位
const _getRes = () => {
return service.get('/operations/api/v5/resource/home', {
content_code: '5d05d443a557783b1489d328c127e9bf',
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
}
return resourcesProcess(result.data.list);
/**
* 收藏数量接口
* @param params
* @returns {*|Promise.<TResult>}
*/
_favoriteData(params) {
if (params.uid) {
return singleAPI.get('favorite', {
method: 'app.favorite.getFavoriteCount',
uid: params.uid
}, {
code: 200
});
} else {
return result;
return false;
}
});
};
// 潮流口令
const _getCode = (uid) => {
if (uid) {
return api.get('', {
method: 'app.invitecode.my',
uid: uid
}, {
code: 200
});
} else {
return Promise.resolve({});
}
};
const _getTrendPop = (contentCode) => {
return service.get('operations/api/v5/resource/get', {
content_code: contentCode,
}).then(result => {
if (result && result.code === 200 && result.data) {
return result.data[0];
/**
* 个人中心页面优惠券,收藏的商品等的数目数据
*/
_infoNum(params) {
if (params.uid) {
return api.get('', {
method: 'app.home.getInfoNum',
uid: params.uid,
udid: params.udid
}, {
code: 200
});
} else {
return result;
return false;
}
});
};
}
/**
* 个人中心首页
* @param params
* @returns {function()}
*/
const index = (params) => {
let finalResult = {
myIndexPage: true,
navHome: true,
pageFooter: true,
refundExchangeNum: 0,
commentTotal: 0,
cartUrl: helpers.urlFormat('/cart/index/index'),
signinUrl: helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/home')
}),
referUrl: helpers.urlFormat('/home'),
verifyUrl: helpers.urlFormat('/activity/student/register')
};
return api.all([
_userData(params),
_noticeData(),
_favoriteData(params),
_infoNum(params),
_getAddressData(params),
_getRes(),
_getCode(params.uid),
_getTrendPop(params.contentCode)
]).then(result => {
if (result[0] && result[0].data) {
Object.assign(finalResult, {
profileName: result[0].data.profile_name,
headIco: result[0].data.head_ico,
vipInfo: result[0].data.vip_info,
students: _.get(result[0].data, 'vip_info.is_student', 0) === 1,
trendWord: _.get(result[6].data, 'trendWord', false),
inviteCode: _.get(result[6].data, 'inviteCode', ''),
trendGuidePopUpDesc: _.get(result[6].data, 'trendGuidePopUpDesc', ''),
bannerSrc: _.get(result[7], 'data[0].src', '')
/**
* 从接口获取地址列表
* @param params
*/
_getAddressData(params) {
if (params.uid) {
return api.get('', {
method: 'app.address.gethidden',
uid: params.uid
}, {
code: 200
});
} else {
return false;
}
}
if (result[1] && result[1].data) {
Object.assign(finalResult, {
notice: result[1].data.list
});
}
// 资源位
_getRes() {
return service.get('/operations/api/v5/resource/home', {
content_code: '5d05d443a557783b1489d328c127e9bf',
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
}
return resourcesProcess(result.data.list);
} else {
return result;
}
});
}
if (result[2] && result[2].data) {
Object.assign(finalResult, {
productFavoriteTotal: _.get(result[2], 'data.product_favorite_total', '0')
// 潮流口令
_getCode(uid) {
if (uid) {
return api.get('', {
method: 'app.invitecode.my',
uid: uid
}, {
code: 200
});
} else {
Object.assign(finalResult, {
productFavoriteTotal: '0'
});
return Promise.resolve({});
}
}
if (result[3] && result[3].data) {
Object.assign(finalResult, {
refundExchangeNum: result[3].data.refund_exchange_num,
sendCargoNum: result[3].data.send_cargo_num,
waitCargoNum: result[3].data.wait_cargo_num,
waitPayNum: result[3].data.wait_pay_num,
yohoCoinNum: result[3].data.yoho_coin_num,
inboxTotal: result[3].data.inbox_total,
couponNum: result[3].data.coupon_num,
brandFavoriteTotal: _.get(result[3], 'data.brand_favorite_total', '0'),
productBrowse: _.get(result[3], 'data.product_browse', '0')
});
} else {
Object.assign(finalResult, {
brandFavoriteTotal: '0',
productBrowse: '0'
});
}
_getTrendPop(contentCode) {
return service.get('operations/api/v5/resource/get', {
content_code: contentCode,
}).then(result => {
if (result && result.code === 200 && result.data) {
return result.data[0];
} else {
return result;
}
});
}
if (result[4] && result[4].data) {
Object.assign(finalResult, {
addressNum: result[4].data.length
});
}
/**
* 个人中心首页
* @param params
* @returns {function()}
*/
index(params) {
let finalResult = {
myIndexPage: true,
navHome: true,
pageFooter: true,
refundExchangeNum: 0,
commentTotal: 0,
cartUrl: helpers.urlFormat('/cart/index/index'),
signinUrl: helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/home')
}),
referUrl: helpers.urlFormat('/home'),
verifyUrl: helpers.urlFormat('/activity/student/register')
};
if (result[5]) {
finalResult.content = result[5];
}
return api.all([
this._userData(params),
this._noticeData(),
this._favoriteData(params),
this._infoNum(params),
this._getAddressData(params),
this._getRes(),
this._getCode(params.uid),
this._getTrendPop(params.contentCode)
]).then(result => {
if (result[0] && result[0].data) {
Object.assign(finalResult, {
profileName: result[0].data.profile_name,
headIco: result[0].data.head_ico,
vipInfo: result[0].data.vip_info,
students: _.get(result[0].data, 'vip_info.is_student', 0) === 1,
trendWord: _.get(result[6].data, 'trendWord', false),
inviteCode: _.get(result[6].data, 'inviteCode', ''),
trendGuidePopUpDesc: _.get(result[6].data, 'trendGuidePopUpDesc', ''),
bannerSrc: _.get(result[7], 'data[0].src', '')
});
}
return finalResult;
});
};
if (result[1] && result[1].data) {
Object.assign(finalResult, {
notice: result[1].data.list
});
}
const _detailInfo = (uid) => {
return api.get('', {
method: 'app.passport.profile',
uid: uid
}, {
code: 200
});
};
if (result[2] && result[2].data) {
Object.assign(finalResult, {
productFavoriteTotal: _.get(result[2], 'data.product_favorite_total', '0')
});
} else {
Object.assign(finalResult, {
productFavoriteTotal: '0'
});
}
/**
* 个人基本资料
* @param params
*/
const myDetails = (uid) => {
if (uid) {
return api.all([_detailInfo(uid), _getCode(uid)]).then(result => {
if (result[0].data) {
result[0].data.gender = (result[0].data.gender === '1' ? '男' : '女');
result[0].data.qrcodeLink = helpers.urlFormat('/home/user/qrcode', {
token: _.get(result[0], 'data.uid', null) ?
crypto.encryption('yoho9646yoho9646', _.get(result, 'data.uid', null) + '') : '',
icon: _.get(result[0], 'data.head_ico', ''),
uname: _.get(result[0], 'data.nickname', ''),
vip: _.get(result[0], 'data.vip_info.cur_level')
if (result[3] && result[3].data) {
Object.assign(finalResult, {
refundExchangeNum: result[3].data.refund_exchange_num,
sendCargoNum: result[3].data.send_cargo_num,
waitCargoNum: result[3].data.wait_cargo_num,
waitPayNum: result[3].data.wait_pay_num,
yohoCoinNum: result[3].data.yoho_coin_num,
inboxTotal: result[3].data.inbox_total,
couponNum: result[3].data.coupon_num,
brandFavoriteTotal: _.get(result[3], 'data.brand_favorite_total', '0'),
productBrowse: _.get(result[3], 'data.product_browse', '0')
});
} else {
Object.assign(finalResult, {
brandFavoriteTotal: '0',
productBrowse: '0'
});
result[0].data.trendWord = _.get(result[1].data, 'trendWord', false);
result[0].data.inviteCode = _.get(result[1].data, 'inviteCode', false);
}
return result[0].data;
});
} else {
return Promise.resolve({});
}
};
if (result[4] && result[4].data) {
Object.assign(finalResult, {
addressNum: result[4].data.length
});
}
if (result[5]) {
finalResult.content = result[5];
}
return finalResult;
});
}
/**
* 浏览记录
* @param params
*/
const recordContent = (uid, udid, page, limit) => {
if (uid) {
_detailInfo(uid) {
return api.get('', {
method: 'app.browse.product',
uid: uid,
limit: limit,
page: page
method: 'app.passport.profile',
uid: uid
}, {
code: 200
}).then((result) => {
let resu = {};
if (result && result.code === 200) {
let list = result;
if (!result || page === '1' && result.data.total === 0) {
resu.walkwayUrl = helpers.urlFormat('/product/new');
resu.noRecord = true;
});
}
return resu;
/**
* 个人基本资料
* @param params
*/
myDetails(uid) {
if (uid) {
return api.all([this._detailInfo(uid), this._getCode(uid)]).then(result => {
if (result[0].data) {
result[0].data.gender = (result[0].data.gender === '1' ? '男' : '女');
result[0].data.qrcodeLink = helpers.urlFormat('/home/user/qrcode', {
token: _.get(result[0], 'data.uid', null) ?
crypto.encryption('yoho9646yoho9646', _.get(result, 'data.uid', null) + '') : '',
icon: _.get(result[0], 'data.head_ico', ''),
uname: _.get(result[0], 'data.nickname', ''),
vip: _.get(result[0], 'data.vip_info.cur_level')
});
result[0].data.trendWord = _.get(result[1].data, 'trendWord', false);
result[0].data.inviteCode = _.get(result[1].data, 'inviteCode', false);
}
if (list.data && list.data.product_list) {
resu = {
browseRecord: []
};
return result[0].data;
});
} else {
return Promise.resolve({});
}
}
_.forEach(list.data.product_list, function(val) {
let obj = {
productList: []
/**
* 浏览记录
* @param params
*/
recordContent(uid, udid, page, limit) {
if (uid) {
return api.get('', {
method: 'app.browse.product',
uid: uid,
limit: limit,
page: page
}, {
code: 200
}).then((result) => {
let resu = {};
if (result && result.code === 200) {
let list = result;
if (!result || page === '1' && result.data.total === 0) {
resu.walkwayUrl = helpers.urlFormat('/product/new');
resu.noRecord = true;
return resu;
}
if (list.data && list.data.product_list) {
resu = {
browseRecord: []
};
obj = _.assign(obj, {
product_name: val.product_name,
product_skn: val.product_skn,
storage: val.storage,
image: val.image,
link: '/product/' + val.product_skn + '.html', // 商品url改版
sales_price: val.sales_price,
market_price: (val.market_price - val.sales_price) > 0 ? val.market_price : false,
invalidGoods: val.status === 0
_.forEach(list.data.product_list, function(val) {
let obj = {
productList: []
};
obj = _.assign(obj, {
product_name: val.product_name,
product_skn: val.product_skn,
storage: val.storage,
image: val.image,
link: '/product/' + val.product_skn + '.html', // 商品url改版
sales_price: val.sales_price,
market_price: (val.market_price - val.sales_price) > 0 ? val.market_price : false,
invalidGoods: val.status === 0
});
resu.browseRecord.push(obj);
});
}
resu.browseRecord.push(obj);
});
return resu;
}
});
} else {
return false;
}
}
return resu;
}
/**
* 删除浏览记录
* @param params
*/
delRecord(uid, skn) {
return api.get('', {
method: 'app.browse.delete',
uid: uid,
skn: skn
});
} else {
return false;
}
};
/**
* 删除浏览记录
* @param params
*/
const delRecord = (uid, skn) => {
return api.get('', {
method: 'app.browse.delete',
uid: uid,
skn: skn
});
};
/**
* 会员等级
* @param params
*/
getGradeGrade(uid, channel) {
return api.get('', {
method: 'app.passport.vip',
uid: uid,
channel: channel || 1
}, {
code: 200
});
}
/**
* 会员等级
* @param params
*/
const getGradeGrade = (uid, channel) => {
return api.get('', {
method: 'app.passport.vip',
uid: uid,
channel: channel || 1
}, {
code: 200
});
};
getGradeUser(uid, channel) {
return api.get('', {
method: 'app.passport.profile',
uid: uid,
channel: channel || 1
}, {
code: 200
});
}
const getGradeUser = (uid, channel) => {
return api.get('', {
method: 'app.passport.profile',
uid: uid,
channel: channel || 1
}, {
code: 200
});
};
getGrade(param) {
if (param.uid) {
return api.all([
this.getGradeGrade(param.uid, param.channel),
this.getGradeUser(param.uid, param.channel)
]).then((result) => {
const getGrade = (param) => {
if (param.uid) {
return api.all([
getGradeGrade(param.uid, param.channel),
getGradeUser(param.uid, param.channel)
]).then((result) => {
let resu = {
vipGrade: []
};
let resu = {
vipGrade: []
};
let enp = {};
let enp = {};
let obj = {
privilege: []
};
let obj = {
privilege: []
};
if (result[0] && result[0].data) {
if (result[0] && result[0].data) {
_.forEach(result[0].data.enjoy_preferential, function(val) {
_.forEach(result[0].data.enjoy_preferential, function(val) {
enp = {
description: val.description,
pic: val.pic,
title: val.title,
href: val.id === 8
};
enp = {
description: val.description,
pic: val.pic,
title: val.title,
href: val.id === 8
};
obj.privilege.push(enp);
obj.privilege.push(enp);
});
});
switch (result[0].data.current_vip_level) {
case '0': // 普通会员
obj = _.assign(obj, {
vip0: true
});
break;
case '1': // 银卡会员
obj = _.assign(obj, {
vip1: true
});
break;
case '2': // 金卡会员
obj = _.assign(obj, {
vip2: true
});
break;
case '3': // 白金会员
obj = _.assign(obj, {
vip3: true
});
break;
default:
}
let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2);
switch (result[0].data.current_vip_level) {
case '0': // 普通会员
obj = _.assign(obj, {
vip0: true
});
break;
case '1': // 银卡会员
obj = _.assign(obj, {
vip1: true
});
break;
case '2': // 金卡会员
obj = _.assign(obj, {
vip2: true
});
break;
case '3': // 白金会员
obj = _.assign(obj, {
costOfThisYear: result[0].data.current_year_cost,
sumCost: result[0].data.current_total_cost,
allUrl: helpers.urlFormat('/home/privilege'),
costGap: upg
});
if (result[0].data.next_need_cost === 0 || result[0].data.next_need_cost === '') {
// 当vip等级升至顶级时,进度条满格
obj = _.assign(obj, {
vip3: true
percent: 100
});
break;
default:
} else {
}
let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2);
let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2);
obj = _.assign(obj, {
percent: perf
});
obj = _.assign(obj, {
costOfThisYear: result[0].data.current_year_cost,
sumCost: result[0].data.current_total_cost,
allUrl: helpers.urlFormat('/home/privilege'),
costGap: upg
});
}
if (result[0].data.next_need_cost === 0 || result[0].data.next_need_cost === '') {
// 当vip等级升至顶级时,进度条满格
obj = _.assign(obj, {
percent: 100
});
} else {
let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2);
}
if (result[0] && result[0].data) {
obj = _.assign(obj, {
percent: perf
name: result[1].data.nickname
});
}
}
if (result[0] && result[0].data) {
obj = _.assign(obj, {
name: result[1].data.nickname
});
}
resu.vipGrade.push(obj);
resu.vipGrade.push(obj);
return resu;
});
} else {
return Promise.resolve({});
return resu;
});
} else {
return Promise.resolve({});
}
}
};
/**
* 会员特权列表页
* @param params
*/
/**
* 会员特权列表页
* @param params
*/
getPreferential(params) {
const getPreferential = (params) => {
return api.get('', {
method: 'app.passport.getPrivilege',
uid: params.uid,
channel: params.channel || 1
}, {
code: 200
}).then((result) => {
let obj = {};
let resu = {
privilege: []
};
return api.get('', {
method: 'app.passport.getPrivilege',
uid: params.uid,
channel: params.channel || 1
}, {
code: 200
}).then((result) => {
_.forEach(result.data, function(val) {
let obj = {};
obj = {
description: val.description,
pic: val.pic,
title: val.title,
href: val.id === 8 ? '//m.yohobuy.com/activity/birthday' : _.get(val, 'actionParam', false)
let resu = {
privilege: []
};
resu.privilege.push(obj);
_.forEach(result.data, function(val) {
});
obj = {
description: val.description,
pic: val.pic,
title: val.title,
href: val.id === 8 ? '//m.yohobuy.com/activity/birthday' : _.get(val, 'actionParam', false)
};
return resu;
resu.privilege.push(obj);
});
};
});
return resu;
module.exports = {
index,
myDetails,
recordContent,
delRecord,
getGrade,
getPreferential,
getGradeGrade,
});
}
};
... ...