feature.js
7.22 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const yasProcess = require('../../../utils/yas-process');
class featureModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_getProductBySkns(productObj, ctx) {
return this.get({
data: {
productSkn: productObj.defaultSkns,
method: 'h5.product.batch'
},
param: {
cache: true
}
}).then((result) => {
productObj.defaultPros = [];
if (result && result.data && result.data.product_list && result.code === 200) {
result.data.product_list.forEach(function(val) {
var obj = {
producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${yasProcess.getPname(ctx.req)}","from_page_param":"${_.get(ctx,'req.url', '')}"}}`, // eslint-disable-line
productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'), // eslint-disable-line
productname: val.product_name,
vipprice: val.vip_price,
saleprice: val.sales_price,
marketprice: val.sales_price === val.market_price ? '' : val.market_price,
brandname: val.brand_name,
product_skn: val.product_skn
};
if (val.shop_id) {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type || "1"},"is_red_shop":${val.is_red_shop || 1}}}`; // eslint-disable-line
} else {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line
}
productObj.defaultPros.push(obj);
});
}
});
}
/**
* 获取店铺组店铺数据
*/
_getShopGroup(shopRawData) {
// 个性化店铺组,前端去查询
if (shopRawData.searchCondition) {
shopRawData.individuation = true;
return Promise.resolve();
}
// 固定店铺组
return this.get({
data: {
method: 'app.shops.batchGetShops',
shop_ids: shopRawData.defaultShopIds
}
}).then(result => {
let renderData = _.get(result, 'data', []);
_.forEach(renderData, shop => {
let displayStyle = _.get(shopRawData, 'displayStyle', '0');
shop.picture = displayStyle === '0' ? shop.pic_popular : shop.shop_logo;
shop.href = `//m.yohobuy.com/product/shop?domain=${shop.shop_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${shop.shops_id},"shop_template_type":${shop.shop_template_type || "1"},"is_red_shop":${shop.is_red_shop || 1}}}`; // eslint-disable-line
});
shopRawData.renderData = renderData;
});
}
index(params) {
const self = this;
return Promise.coroutine(function*() {
if (!params.code) {
return Promise.resolve({});
}
let data,
sknsArr = [];
let shopGroups = [];
if (params.type === 'preview') { // 开发/预览模式
data = yield api.get('', {
method: 'app.activity.template.ignoreCache',
activity_id: params.code
});
} else {
data = yield api.get('', { // 生产模式
method: 'app.activity.template',
activity_id: params.code
}, {
cache: true
});
}
if (!data) {
return;
}
data = data.data;
if (data && data.floors) {
data.floors.forEach(f => {
if (f.component && f.component[0] &&
f.component[0].type === 'productGroup' && f.component[0].defaultSkns) {
sknsArr.push(self._getProductBySkns(f.component[0], self.ctx));
f.component[0].newStyle = _.get(f, 'component[0].newStyle') === '1';
}
if (f.component && f.component[0] &&
f.component[0].type === 'productGroup' && f.component[0].favourite_prds_enable === '1') {
f.component[0].searchCondition = Object.assign({
maybeLike: '1',
limit: '60'
}, f.component[0].searchCondition || {});
f.component[0].newStyle = _.get(f, 'component[0].newStyle') === '1';
}
// 新增店铺组
if (_.get(f, 'component[0].type') === 'shopGroup') {
shopGroups.push(self._getShopGroup(f.component[0]));
}
if (_.get(f, 'type') === 'bottombar') {
f.height = _.get(f, 'param.height') / 20;
}
_.forEach(f.component, component => {
if (component.url && component.url.indexOf('go.productDetail') !== -1) {
component.url = yasProcess.addParamsToGoodsHref({
href: component.url,
fromPageName: yasProcess.getPname(_.get(self, 'ctx.req', {})),
fromPageParam: _.get(self, 'ctx.req.path', '')
});
}
if (component.persenal_enable === '1') {
f.hide = true; // 个性化券楼层先不展示,前端异步查询到的时候,再展示
}
});
});
}
if (sknsArr.length) {
yield Promise.all(sknsArr);
}
if (shopGroups.length) {
yield Promise.all(shopGroups);
}
return data;
})();
}
/**
* 领取优惠券
*/
couponSend(uid, token) {
let data = {
method: 'app.coupons.couponsSend',
uid: uid,
coupon_send_token: token
};
if (/:/.test(token)) {
let [couponId, personCouponId] = token.split(':');
data = {
method: 'app.promotion.getACoupon',
uid: uid,
couponId: couponId,
personCouponId: personCouponId
};
}
return this.get({data}).then(result => {
if (!result) {
result.code = 404;
result.message = '出错啦~';
}
return result;
});
}
}
module.exports = featureModel;