sale.js
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-20 17:55:34
*/
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const api = new API();
const _ = require('lodash');
/**
* 处理 sale 首页原始数据
* @param {Object} origin [原始数据]
* @return {Object} [结果]
*/
const handleSaleIndexData = (origin) => {
var dest = {};
dest = origin;
return dest;
};
/**
* 处理商品列表数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleGoodsListData = (origin) => {
var goods = [];
if (!_.isEmpty(origin.product_list)) {
_.forEach(origin.product_list, function(value) {
let oneGoods = {};
oneGoods.tags = value.tags;
oneGoods.thumb = value.default_images;
oneGoods.url = '/product/pro_' + value.product_id + '_' + value.goods_list[0].goods_id + '/' +
value.cn_alphabet + '.html';
oneGoods.goodsList = value.goods_list;
oneGoods.name = value.product_name;
oneGoods.brand = {};
oneGoods.brand.url = value.brand_domain + '.SUB_DOMAIN'; // 待处理
oneGoods.brand.name = value.brand_name;
oneGoods.marketPrice = value.market_price;
goods.push(oneGoods);
});
}
return goods;
};
/**
* 处理分类筛选数据
* @return {[type]} [description]
*/
const handleSaleSortData = (origin) => {
var leftContent = {};
leftContent.allDiscount = {};
leftContent.allDiscount.list = [];
_.forEach(origin, function(value) {
let category = {};
category.name = value.sort_name;
leftContent.allDiscount.list.push(category);
});
return leftContent;
};
/**
* 返回商品列表 promise 对象
* @return {[type]} [description]
*/
const getSaleGoodsList = () => {
return api.get('', sign.apiSign({
method: 'app.search.sales',
limit: 5,
order: 's_t_desc',
page: 1,
productSize: '384x511',
yh_channel: 1
}));
};
/**
* 获取分类信息 promise 对象
* @return {[type]} [description]
*/
const getSortList = () => {
return api.get('', sign.apiSign({
method: 'app.sale.getBreakingSort',
yh_channel: 1
}));
};
/**
* 获取 Sale 首页数据
* @return {[type]} [description]
*/
exports.getSaleIndexDate = () => {
return api.get('', sign.apiSign({
method: 'app.activity.get',
sort: 2,
plateform: 2
})).then(result => {
return handleSaleIndexData(result);
});
};
/**
* 获取页面全部信息
* @return {[type]} [description]
*/
exports.getSaleData = () => {
return api.all([getSortList(), getSaleGoodsList()]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.leftContent = handleSaleSortData(result[0].data);
}
if (result[1].code === 200) {
finalResult.goods = handleSaleGoodsListData(result[1].data);
}
return finalResult;
});
};