...
|
...
|
@@ -9,6 +9,20 @@ const helpers = global.yoho.helpers; |
|
|
|
|
|
const OrderService = require('./orders-service');
|
|
|
const IndexApi = require('./index-api');
|
|
|
const UserApi = require('./user-api');
|
|
|
const MsgApi = require('./message');
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
const cache = global.yoho.cache;
|
|
|
const cachePreKey = 'HOME_INDEX_';
|
|
|
const defaultAvatar = '//img10.static.yhbimg.com/headimg/' +
|
|
|
'2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
|
|
|
|
|
|
|
|
|
const numbersKey = {
|
|
|
pending: 'pengding',
|
|
|
unread: 'unread',
|
|
|
needComment: 'needComment'
|
|
|
};
|
|
|
|
|
|
const CHANNEL_NUM = {
|
|
|
boys: 1,
|
...
|
...
|
@@ -164,7 +178,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
_footerBanner() {
|
|
|
const CODE = '20110609-152143';
|
|
|
|
|
|
return new IndexApi(this.ctx).getByNodeContent(CODE).then(banner => {
|
|
|
return new IndexApi(this.ctx).getByNodeContent(CODE, {}, {cache: 86400}).then(banner => {
|
|
|
return _.get(banner, 'data', '').replace(/http:\/\//g, '//');
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -176,6 +190,126 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
return new OrderService(this.ctx).closeReason();
|
|
|
}
|
|
|
|
|
|
// 个人中心首页 异步获取新品上架数据
|
|
|
async newArrive() {
|
|
|
let arriveCaceKey = `${cachePreKey}arrive`;
|
|
|
let arrive = await cache.get(arriveCaceKey);
|
|
|
|
|
|
if (!arrive) {
|
|
|
let arriveOrigin = await new IndexApi(this.ctx).newArrival();
|
|
|
|
|
|
arrive = this._handleProduct(_.get(arriveOrigin, 'data.product_list', []));
|
|
|
if (!_.isEmpty(arrive)) {
|
|
|
cache.set(arriveCaceKey, arrive, 3600);
|
|
|
}
|
|
|
} else {
|
|
|
arrive = JSON.parse(arrive);
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(arrive);
|
|
|
}
|
|
|
|
|
|
// 推荐数据
|
|
|
async recommend(uid, udid, channelNum) {
|
|
|
let recommendCaceKey = `${cachePreKey}recommend`;
|
|
|
let recommend = await cache.get(recommendCaceKey);
|
|
|
|
|
|
if (!recommend) {
|
|
|
let recommendOrigin = await new IndexApi(this.ctx).recommend(channelNum, uid, udid, '100004', 30);
|
|
|
|
|
|
recommend = this._handleProduct(_.get(recommendOrigin, 'data.product_list', []));
|
|
|
if (!_.isEmpty(recommend)) {
|
|
|
cache.set(recommendCaceKey, recommend, 3600);
|
|
|
}
|
|
|
} else {
|
|
|
recommend = JSON.parse(recommend);
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(recommend);
|
|
|
}
|
|
|
|
|
|
// 个人中心首页 异步获取品牌数据
|
|
|
async brands() {
|
|
|
let brandsCaceKey = `${cachePreKey}brands`;
|
|
|
let brand = await cache.get(brandsCaceKey);
|
|
|
|
|
|
if (!brand) {
|
|
|
let brandOrigin = await new IndexApi(this.ctx).guessBrand();
|
|
|
|
|
|
brand = this._handleBrand(_.get(brandOrigin, 'data', []), 6);
|
|
|
if (!_.isEmpty(brand)) {
|
|
|
cache.set(brandsCaceKey, brand, 86400);
|
|
|
}
|
|
|
} else {
|
|
|
brand = JSON.parse(brand);
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(brand);
|
|
|
}
|
|
|
|
|
|
// 个人中心异步查询我的消息和头像
|
|
|
async newsAvatar(uid) {
|
|
|
let result = await Promise.props(
|
|
|
{
|
|
|
profile: new UserApi(this.ctx).getUserInfo(uid),
|
|
|
msg: new MsgApi(this.ctx).unreadTotal(uid)
|
|
|
}
|
|
|
);
|
|
|
let avatar = helpers.image(_.get(result, 'profile.data.head_ico', ''), 100, 100) || defaultAvatar;
|
|
|
let msgCount = _.get(result, 'msg.data.total', 0);
|
|
|
|
|
|
return Promise.resolve({avatar: avatar, msg: msgCount});
|
|
|
}
|
|
|
|
|
|
// 首页顶部数量
|
|
|
async numbers(uid, udid) {
|
|
|
let result = {};
|
|
|
let numbers = await Promise.props({
|
|
|
pending: new IndexApi(this.ctx).pendingOrderCount(uid), // 待处理订单
|
|
|
unread: new IndexApi(this.ctx).unreadMessageCount(uid, udid), // 未读消息
|
|
|
needComment: new IndexApi(this.ctx).needCommentCount(uid) // 待评论商品
|
|
|
});
|
|
|
|
|
|
result[numbersKey.pending] = _.get(numbers, 'pending.data.count', 0);
|
|
|
result[numbersKey.unread] = _.get(numbers, 'unread.data.inbox_total', 0);
|
|
|
result[numbersKey.needComment] = _.get(numbers, 'needComment.data', 0);
|
|
|
|
|
|
return Promise.resolve(result);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 个人中心首页同步数据
|
|
|
async indexNew(uid, udid, channel, isStudent) {
|
|
|
let indexData = await Promise.props({
|
|
|
header: headerModel.requestHeaderData(channel),
|
|
|
recentOrder: this._recentOrder(uid),
|
|
|
footerBanner: this._footerBanner(),
|
|
|
reason: this._cancelReason()
|
|
|
});
|
|
|
|
|
|
return Object.assign(
|
|
|
{
|
|
|
content: {
|
|
|
content: {
|
|
|
messages: [
|
|
|
{href: helpers.urlFormat('/home/orders'), name: '待处理订单', id: numbersKey.pending, count: 0},
|
|
|
{href: helpers.urlFormat('/home/message'), name: '未读消息', id: numbersKey.unread, count: 0},
|
|
|
{href: helpers.urlFormat('/home/comment'), name: '待评论商品',
|
|
|
id: numbersKey.needComment, count: 0}
|
|
|
],
|
|
|
certifiedName: +isStudent ? '学生身份已验证' : '身份验证',
|
|
|
certifiedUrl: helpers.urlFormat('/product/students/'),
|
|
|
latestOrders: Object.assign(indexData.recentOrder, {cancelReason: indexData.reason})
|
|
|
},
|
|
|
banner: indexData.footerBanner
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
header: indexData.header
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
index(uid, udid, channel, isStudent) {
|
|
|
let that = this;
|
|
|
|
...
|
...
|
|