detail.js
3.05 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
/**
*
* @author: Aiden Xu<aiden.xu@yoho.cn>
* @date: 2016/07/19
*/
'use strict';
// const _ = require('lodash');
// const helpers = global.yoho.helpers;
const api = global.yoho.API;
const _ = require('lodash');
/**
* 商品详情
*/
const component = {
index(req, res) {
const pid = req.params[0], goodsId = req.params[1];
res.render('detail', {
module: 'product',
page: 'detail',
pid: pid,
goodsId: goodsId
});
},
product(req, res, next) {
const pid = req.params[0];// , goodsId = req.params[1];
let params = {
productId: _.toString(pid),
method: 'h5.product.data' // TODO replace this to 'app.product.data'
};
api.get('', params).then(result => {
res.json(result);
}).catch(next);
},
intro(req, res, next) {
let params = {
method: 'h5.product.intro', // TODO replace this to 'app.product.intro'
productskn: req.query.skn,
udid: 'f528764d624db129b32c21fbca0cb8d6'
};
api.get('', params).then(result => {
res.json(result);
}).catch(next);
},
/**
* 加入购物车接口
*
*/
addToCart(req, res, next) {
let params = {
method: 'app.Shopping.add',
product_sku: req.body.productSku, // 商品SKU
buy_number: req.body.buyNumber, // 购买数量
goods_type: req.body.goodsType || 0, // 商品类型,0表示普通商品,1表示加价购商品
edit_product_sku: req.body.isEdit || 0, // 是否是编辑商品SKU,0表示不是编辑
selected: 'Y',
promotion_id: req.body.promotionId || null, // 促销id,默认null(加价购有关)
uid: req.user.uid || null, // TODO: fix uid
shopping_key: global.yoho.cookie.getShoppingKey(req)
};
api.get('', params).then(result => {
res.json(result);
}).catch(next);
},
getFavorite(req, res, next) {
api.get('', {}).then(result => {
res.json(result);
}).catch(next);
},
/**
* 收藏
*
* @param req
* @param res
* @param next
*/
addFavorite(req, res, next) {
let params = {
method: 'app.Shopping.addfavorite',
product_sku_list: req.body.sku,
uid: req.user.uid || 8050378 // TODO: fix this hard coded uid
};
api.get('', params).then(result => {
res.json(result);
}).catch(next);
},
/**
* 获取购物车数量
*
* @param req
* @param res
* @param next
*/
getCartCount: (req, res, next) => {
let params = {
method: 'app.Shopping.count',
shopping_key: global.yoho.cookie.getShoppingKey(req),
uid: req.user.uid || 0 // TODO fix uid
};
api.get('', params).then(result => {
res.json(result);
}).catch(next);
}
};
module.exports = component;