Authored by 郝肖肖

'newsale-ctx'

... ... @@ -11,7 +11,6 @@ const helpers = global.yoho.helpers;
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
class DetailModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ...
... ... @@ -44,8 +44,7 @@ const index = (req, res, next) => {
// 唤起 APP 的路径
res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.top100","params":{"page":"0"}}';
newsaleModel.getHotRank(codeKey).then((result) => {
req.ctx(newsaleModel).getHotRank(codeKey).then((result) => {
res.render('newsale/hotrank', {
module: 'product',
page: 'hot-rank',
... ... @@ -68,8 +67,7 @@ const selectHotrank = (req, res, next) => {
let yhChannel = (req.query.gender && yhchannels[req.query.gender]) ||
(req.cookies._Channel && channels[req.cookies._Channel]) || 1;
newsaleModel.selectHotrank(yhChannel, sort, tab_id, limit, page, notab).then((result) => {
req.ctx(newsaleModel).selectHotrank(yhChannel, sort, tab_id, limit, page, notab).then((result) => {
res.render('newsale/hotlist', {
layout: false,
tabs: result.tabs,
... ...
... ... @@ -2,134 +2,142 @@
const utils = '../../../utils';
const productNameProcess = require(`${utils}/product-name-process`);
const api = global.yoho.API;
const _ = require('lodash');
const serviceAPI = global.yoho.ServiceAPI;
const logger = global.yoho.logger;
const getHotRank = (codeKey) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: codeKey
}, {
cache: true
}).then((result) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getHotRank(codeKey) {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: codeKey
},
param: {
cache: true
}
}).then((result) => {
if (result && result.code === 200) {
let formData = {};
if (result && result.code === 200) {
let formData = {};
if (result.data[0].data.length === 1) {
formData.url = result.data[0].data[0].url;
formData.img = result.data[0].data[0].src;
} else {
let list = [];
if (result.data[0].data.length === 1) {
formData.url = result.data[0].data[0].url;
formData.img = result.data[0].data[0].src;
} else {
let list = [];
_.forEach(result.data[0].data, function(val) {
list.push({
url: val.url,
img: val.src
_.forEach(result.data[0].data, function(val) {
list.push({
url: val.url,
img: val.src
});
});
});
formData.list = list;
formData.list = list;
}
return formData;
} else {
logger.error('getHotRank data return code is not 200');
return {};
}
return formData;
} else {
logger.error('getHotRank data return code is not 200');
return {};
}
});
};
});
}
const selectHotrank = (yhChannel, sort, tabId, limit, page, notab) => {
let param = {
method: 'app.search.top',
yh_channel: yhChannel,
page: page,
limit: limit
};
selectHotrank(yhChannel, sort, tabId, limit, page, notab) {
let param = {
method: 'app.search.top',
yh_channel: yhChannel,
page: page,
limit: limit
};
if (sort) {
param.sort = sort;
}
if (sort) {
param.sort = sort;
}
if (tabId) {
param.tab_id = tabId;
}
if (tabId) {
param.tab_id = tabId;
}
return api.get('', param, {
cache: true
}).then((result) => {
return this.get({
data: param,
param: {
cache: true
}
}).then((result) => {
if (result && result.code === 200 && result.data.product_list) {
if (result && result.code === 200 && result.data.product_list) {
let formData = {};
let formData = {};
if (notab && parseInt(notab, 10) === 0 && result.data.tabs) {
let tabs = [];
if (notab && parseInt(notab, 10) === 0 && result.data.tabs) {
let tabs = [];
_.forEach(result.data.tabs, function(val, index) {
let obj = {};
_.forEach(result.data.tabs, function(val, index) {
let obj = {};
if (index === 0) {
obj = _.assign(obj, {
focus: true
});
}
if (index === 0) {
obj = _.assign(obj, {
focus: true
title: val,
dataId: index
});
}
obj = _.assign(obj, {
title: val,
dataId: index
tabs.push(obj);
});
tabs.push(obj);
});
formData.tabs = tabs;
}
formData.tabs = tabs;
}
if (result.data.product_list && result.data.product_list.length !== 0) {
if (result.data.product_list && result.data.product_list.length !== 0) {
let goods = [];
let goods = [];
_.forEach(result.data.product_list, function(data, index) {
let one = {};
_.forEach(result.data.product_list, function(data, index) {
let one = {};
if (data === null || !data.product_skn || !data.goods_list[0]) {
return false;
}
if (data === null || !data.product_skn || !data.goods_list[0]) {
return false;
}
if (data.cn_alphabet) {
data.cn_alphabet = productNameProcess(data.cn_alphabet);
}
if (data.cn_alphabet) {
data.cn_alphabet = productNameProcess(data.cn_alphabet);
}
one = _.assign(one, {
url: '/product/' + data.product_skn + '.html', // 商品url改版
thumb: data.default_images,
rank: limit * (page - 1) + index + 1,
name: data.product_name,
salePrice: data.sales_price
});
if (data.sales_phrase) {
one = _.assign(one, {
sales_phrase: data.sales_phrase
url: '/product/' + data.product_skn + '.html', // 商品url改版
thumb: data.default_images,
rank: limit * (page - 1) + index + 1,
name: data.product_name,
salePrice: data.sales_price
});
}
goods.push(one);
});
formData.goods = goods;
}
if (data.sales_phrase) {
one = _.assign(one, {
sales_phrase: data.sales_phrase
});
}
goods.push(one);
});
return formData;
} else {
return {};
}
formData.goods = goods;
}
});
};
return formData;
} else {
return {};
}
module.exports = {
getHotRank,
selectHotrank
});
}
};
... ...