|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const ROOTPATH = '../../../';
|
|
|
const contentCodeConfig = require(`${ROOTPATH}config/content-code`);
|
|
|
const productProcess = require(`${ROOTPATH}utils/product-process`);
|
|
|
|
|
|
class TideModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
tideCategory(params) {
|
|
|
return Promise.all([
|
|
|
this.getResource(Object.assign({
|
|
|
content_code: contentCodeConfig.tide.category
|
|
|
}, params)),
|
|
|
this.crmRecommendSort(params)
|
|
|
]).then(res => {
|
|
|
let tide = {
|
|
|
resource: _.get(res[0], 'data', []),
|
|
|
contents: []
|
|
|
};
|
|
|
let sindex = _.findIndex(tide.resource, {template_name: 'image_list'});
|
|
|
|
|
|
if (sindex > -1) {
|
|
|
tide.resource[sindex].title = '# 精彩活动 #';
|
|
|
}
|
|
|
|
|
|
_.each(_.get(res[1], 'data', []), (item, index) => {
|
|
|
item.sortInfo = item.sortInfo || {};
|
|
|
|
|
|
let goods = productProcess.processProductList(item.productList || [], {
|
|
|
isApp: params.isApp,
|
|
|
showSimilar: false
|
|
|
});
|
|
|
let tdata = {
|
|
|
sortInfo: Object.assign({}, item.sortInfo, {
|
|
|
url: helpers.urlFormat(`/list/mi${item.sortInfo.itemId}`, {
|
|
|
'openby:yohobuy': `{"action":"go.list","params":{"misort":"${item.sortInfo.itemId}"}}`
|
|
|
})
|
|
|
}),
|
|
|
goods: goods
|
|
|
};
|
|
|
|
|
|
if (index === 0) {
|
|
|
tdata.title = '# 潮品推介 #';
|
|
|
} else {
|
|
|
tdata.borderTop = true;
|
|
|
}
|
|
|
|
|
|
tide.contents.push(tdata);
|
|
|
});
|
|
|
|
|
|
return tide;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 促购个性化3个品类商品推荐
|
|
|
crmRecommendSort(params) {
|
|
|
return this.get({
|
|
|
data: Object.assign({
|
|
|
method: 'app.product.crmRecommend.sort'
|
|
|
}, params)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 促购个性化店铺商品推荐(1个店铺+店铺下6个商品)
|
|
|
crmRecommendShopSix(params) {
|
|
|
return this.get({
|
|
|
data: Object.assign({
|
|
|
method: 'app.product.crmRecommend.shopSix'
|
|
|
}, params)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 促购个性化店铺推荐(9个店铺)
|
|
|
crmRecommendShop(params) {
|
|
|
return this.get({
|
|
|
data: Object.assign({
|
|
|
method: 'app.product.crmRecommend.shop'
|
|
|
}, params)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 促购个性化店铺推荐(30个商品)
|
|
|
crmRecommendProduct(params) {
|
|
|
return this.get({
|
|
|
data: Object.assign({
|
|
|
method: 'app.product.crmRecommend.product'
|
|
|
}, params)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
tideShop(params) {
|
|
|
return Promise.all([
|
|
|
this.getResource(Object.assign({
|
|
|
content_code: contentCodeConfig.tide.brand
|
|
|
}, params)),
|
|
|
this.crmRecommendShopSix(params),
|
|
|
this.crmRecommendShop(params),
|
|
|
this.crmRecommendProduct(params)
|
|
|
]).then(res => {
|
|
|
let tide = {
|
|
|
resource: _.get(res[0], 'data', []),
|
|
|
brands: [],
|
|
|
shopInfo: [],
|
|
|
contents: []
|
|
|
};
|
|
|
let sindex = _.findIndex(tide.resource, {template_name: 'image_list'});
|
|
|
|
|
|
if (sindex > -1) {
|
|
|
tide.resource[sindex].title = '# 精彩活动 #';
|
|
|
}
|
|
|
|
|
|
let shopInfo = _.get(res[1], 'data.shopInfo', {});
|
|
|
|
|
|
if (shopInfo.shopId) {
|
|
|
shopInfo.url = helpers.urlFormat(`/shop/${shopInfo.shopDomain}-${shopInfo.shopId}.html`, {
|
|
|
'openby:yohobuy': `{"action":"go.shop","params":{"shop_id":"${shopInfo.shopId}","shop_template_type":"${shopInfo.shopTemplateType}","shop_name":"${shopInfo.shopName}"}}` //eslint-disable-line
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (shopInfo.shopId || _.get(res[1], 'data.productList', []).length) {
|
|
|
tide.shopInfo.push({
|
|
|
title: '# 为你精选 #',
|
|
|
shopInfo: shopInfo,
|
|
|
goods: productProcess.processProductList(_.get(res[1], 'data.productList', []), {
|
|
|
isApp: params.isApp,
|
|
|
showSimilar: false
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.each(_.get(res[2], 'data', []), (item) => {
|
|
|
tide.brands.push(Object.assign({}, item, {
|
|
|
url: helpers.urlFormat(`/shop/${item.shopDomain}-${item.shopId}.html`, {
|
|
|
'openby:yohobuy': `{"action":"go.shop","params":{"shop_id":"${item.shopId}","shop_template_type":"${item.shopTemplateType}","shop_name":"${item.shopName}"}}` //eslint-disable-line
|
|
|
})
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
if (_.get(res[3], 'data', []).length) {
|
|
|
tide.contents.push({
|
|
|
title: '# 潮品推介 #',
|
|
|
goods: productProcess.processProductList(_.get(res[3], 'data', []), {
|
|
|
isApp: params.isApp,
|
|
|
showSimilar: false
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return tide;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
getResource(params) {
|
|
|
return this.get({
|
|
|
url: 'operations/api/v5/resource/get',
|
|
|
data: Object.assign({
|
|
|
platform: 'iphone'
|
|
|
}, params),
|
|
|
api: global.yoho.ServiceAPI,
|
|
|
param: {cache: true}
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = TideModel; |
...
|
...
|
|