cart.js
12.7 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/**
* 购物车模型 model
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
var Promise = require('bluebird');
var _ = require('lodash');
const api = global.yoho.API;
// const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
// const sign = require(`${global.library}/sign`);
// const logger = require(`${global.library}/logger`);
// const headerModel = require('../../../doraemon/models/header');
// var api = new ServiceAPI();
// 获取预售商品
const getPreSaleProducts = () => {
return Promise.resolve({
preSalePros: [{
gender: '1',
tags: '[Object]',
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: '[Object]',
isAdvance: 'N',
productId: 286135,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S11GeBenHaGen',
productSkn: 51160998,
shelveTime: 1455616165,
vip2Price: 359.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 小方领长袖衬衫【哥本哈根】',
brandId: 1007,
defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 29,
storageNum: 29,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51160998,
thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286135_367985/ALLENOVE95S11GeBenHaGen.html',
brandUrl: '//allenove.yohobuy.com',
orderNum: 1, // 购买数量
numIsValid: true, // 库存是否正常
isValid: true // 是否没有实效
}]
});
};
// 获取普通商品
const getNormalProducts = () => {
return Promise.resolve({
commonPros: [{ gender: '1',
tags: '[Object]',
status: 1,
smallSortId: 115,
vip1Price: 284.05,
isGlobal: 'N',
vip3Price: 263.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: [Object],
isAdvance: 'N',
productId: 286141,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S14WeiYeNa',
productSkn: 51161001,
shelveTime: 1455616165,
vip2Price: 269.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 翼型领长袖衬衫【维也纳】',
brandId: 1007,
defaultImages: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 21,
storageNum: 21,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 299,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51161001,
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286141_367991/ALLENOVE95S14WeiYeNa.html',
brandUrl: '//allenove.yohobuy.com',
orderNum: 2, // 购买数量
numIsValid: true, // 库存是否正常
isValid: true, // 是否没有实效
selectColor: '蓝',
selectSize: 'M'
}, { gender: '1',
tags: '[Object]',
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: '[Object]',
isAdvance: 'N',
productId: 286143,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S20BaSaiLuoNa',
productSkn: 51161002,
shelveTime: 1455616165,
vip2Price: 359.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Foobar',
maxSortId: 1,
productName: 'Foobar 纽扣领绅士长袖衬衫【巴塞罗那】',
brandId: 1007,
defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 25,
storageNum: 25,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51161002,
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286143_367993/ALLENOVE95S20BaSaiLuoNa.html',
brandUrl: '//allenove.yohobuy.com',
orderNum: 1, // 购买数量
numIsValid: false, // 库存是否正常
isValid: true // 是否没有实效
},
{ gender: '1',
tags: [Object],
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: [Object],
isAdvance: 'N',
productId: 286169,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S09BiSa',
productSkn: 51161015,
shelveTime: 1455616145,
vip2Price: 359.1,
editTime: 1455616145,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 高支牛津休闲长袖衬衫【比萨】',
brandId: 1007,
defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 27,
storageNum: 27,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51161015,
thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286169_368019/ALLENOVE95S09BiSa.html',
brandUrl: '//allenove.yohobuy.com',
orderNum: 2, // 购买数量
numIsValid: true, // 库存是否正常
isValid: true // 是否没有实效
}]
});
};
// 获取失效商品
const getInvalidProducts = () => {
return Promise.resolve({
invalidPros: [{ gender: '1',
tags: ['Object'],
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: ['Object'],
isAdvance: 'N',
productId: 286139,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S13PuLuoWangSi',
productSkn: 51161000,
shelveTime: 1455616165,
vip2Price: 359.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 复古圆领长袖衬衫【普罗旺斯】',
brandId: 1007,
defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 12,
storageNum: 12,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51161000,
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286139_367989/ALLENOVE95S13PuLuoWangSi.html',
brandUrl: '//allenove.yohobuy.com',
orderNum: 1, // 购买数量
numIsValid: true, // 库存是否正常
isValid: false // 是否没有实效
}]
});
};
// 获取购物车信息
const getCartInfo = () => {
return Promise.all([
getPreSaleProducts(),
getNormalProducts(),
getInvalidProducts()
]);
};
/*
* 加入购物车
* @function addToCart
* @param { String } productSku 商品SKU
* @param { Number } buyNumber 购买商品数量
* @param { Number } goodType 商品类型,0表示普通商品,1表示加价购商品
* @param { Number } isEdit 是否是编辑商品SKU,0表示不是编辑
* @param { Number } uid 用户UID,可以不传
* @param { String } shoppingKey 未登录用户唯一识别码,可以不传
* @return { Array } 加入购物车接口返回的数据
*/
const addToCart = (options) => {
const productSku = options.productSku;
const buyNumber = options.buyNumber;
const goodType = options.goodType || 0;
const isEdit = options.isEdit || 0;
const uid = options.uid;
const shoppingKey = options.shoppingKey;
let params = {
method: 'app.Shopping.add',
product_sku: productSku,
buy_number: buyNumber,
goods_type: goodType,
edit_product_sku: isEdit,
selected: 'Y',
promotion_id: null
};
if (uid) {
_.merge(params, {
uid: uid
});
}
if (shoppingKey) {
_.merge(params, {
shoppingKey: shoppingKey
});
}
return api.get('', params);
};
/*
* 获取购物车数据
* @function getCartData
* @param { Number } uid 用户UID,可以不传
* @param { String } shoppingKey 未登录用户唯一识别码,客户端从cookie中获取
* @return { Object }
* {
* advance_cart_data: { // 预售商品
* gift_list: [], // 赠品
* goods_list: [] // 商品列表
* off_shelves_goods_list: [], // 下架商品, 失效商品
* price_gift: [], // 加价购商品
* promotion_info: [], // 促销信息
* shopping_cart_data: [], // 商品价格计算相关信息
* sold_out_goods_list: [] // 售罄商品
* },
* ordinary_cart_data: { // 普通商品
* gift_list: [],
* goods_list: [],
* off_shelves_goods_list: [],
* price_gift: [],
* promotion_info: [],
* shopping_cart_data: [],
* sold_out_goods_list: []
* },
* md5: '...',
* message: '...'
* }
*/
const getCartData = (shoppingKey, uid) => {
let params = {
method: 'app.Shopping.cart'
};
if (shoppingKey) {
_.merge(params, {
shopping_key: shoppingKey
});
}
if (uid) {
_.merge(params, {
uid: uid
});
}
return api.get('', params);
};
/*
* 移入收藏夹
* @function transferToFavorite
* @param { Number } uid 用户UID
* @param { String } sku 商品sku列表
* @param { Boolean } hasPromotion 是否有促销ID, 默认值是false
* @return { Array }
*/
const transferToFavorite = (uid, sku, hasPromotion) => {
let method = hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite';
let params = { method };
_.merge(params, {
product_sku_list: sku,
uid // 用户必须登录吗 TODO
});
return api.get('', params);
};
module.exports = {
addToCart,
getCartData,
getCartInfo,
transferToFavorite
};