|
|
'use strict';
|
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const _ = require('lodash');
|
|
|
const utils = '../../../utils';
|
|
|
const productNameProcess = require(`${utils}/product-name-process`);
|
|
|
|
|
|
class storeHome extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
getPreferenceData(data) {
|
|
|
let dest = {
|
|
|
goods: []
|
|
|
};
|
|
|
|
|
|
let list = data.data || {};
|
|
|
|
|
|
_.forEach(list && list.product_list, value => {
|
|
|
|
|
|
if (!value.product_skn || !value.goods_list || !value.goods_list.length) {
|
|
|
return;
|
|
|
}
|
|
|
value.goodsId = value.goods_list && value.goods_list[0] && value.goods_list[0].goods_id;
|
|
|
|
|
|
if (value.cn_alphabet) {
|
|
|
value.cn_alphabet = productNameProcess(value.cn_alphabet);
|
|
|
}
|
|
|
|
|
|
let goods = {
|
|
|
product_skn: value.product_skn,
|
|
|
product_name: value.product_name,
|
|
|
default_images: value.default_images,
|
|
|
is_soon_sold_out: value.is_soon_sold_out === 'Y',
|
|
|
url: helpers.urlFormat(`/product/${value.product_skn}.html`), // 商品url改版
|
|
|
market_price: value.market_price === value.sales_price ? false : value.market_price,
|
|
|
sales_price: value.sales_price
|
|
|
};
|
|
|
|
|
|
let tags = {};
|
|
|
|
|
|
_.forEach(value.tags, tag => {
|
|
|
tags[tag] = true;
|
|
|
});
|
|
|
|
|
|
goods.tags = tags;
|
|
|
goods.similar = true;
|
|
|
|
|
|
if (tags.is_solded === true) {
|
|
|
goods.is_solded = true;
|
|
|
}
|
|
|
|
|
|
dest.goods.push(goods);
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
dest.code = data.code;
|
|
|
dest.rec_id = list.rec_id;
|
|
|
dest.message = data.message;
|
|
|
|
|
|
return dest;
|
|
|
}
|
|
|
|
|
|
getRecommend(params) {
|
|
|
let options = {
|
|
|
data: {
|
|
|
method: 'app.home.newPreference',
|
|
|
yh_channel: params.yh_channel,
|
|
|
udid: params.udid,
|
|
|
limit: params.limit,
|
|
|
rec_pos: params.rec_pos,
|
|
|
uid: params.uid,
|
|
|
client_id: params.client_id,
|
|
|
page: params.page
|
|
|
}
|
|
|
};
|
|
|
|
|
|
return this.get(options).then(result => {
|
|
|
return this.getPreferenceData(result);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = storeHome; |
...
|
...
|
|