|
@@ -14,6 +14,7 @@ exports.index = (req, res) => { |
|
@@ -14,6 +14,7 @@ exports.index = (req, res) => { |
14
|
const uid = req.user.uid || null;
|
14
|
const uid = req.user.uid || null;
|
15
|
|
15
|
|
16
|
cartModel.getCartData(shoppingKey, uid).then((result) => {
|
16
|
cartModel.getCartData(shoppingKey, uid).then((result) => {
|
|
|
17
|
+ // console.log(JSON.stringify(result, '', 4))
|
17
|
if (result.code === 200) {
|
18
|
if (result.code === 200) {
|
18
|
res.display('cart', _.merge({
|
19
|
res.display('cart', _.merge({
|
19
|
module: 'shopping',
|
20
|
module: 'shopping',
|
|
@@ -31,37 +32,6 @@ exports.index = (req, res) => { |
|
@@ -31,37 +32,6 @@ exports.index = (req, res) => { |
31
|
});
|
32
|
});
|
32
|
};
|
33
|
};
|
33
|
|
34
|
|
34
|
-// 检查库存
|
|
|
35
|
-exports.checkInventory = (req, res) => {
|
|
|
36
|
- let chkResult,
|
|
|
37
|
- invalidProIds = [],
|
|
|
38
|
- productId = req.query.productId,
|
|
|
39
|
- result = {};
|
|
|
40
|
-
|
|
|
41
|
- if (productId === 'ALL') {
|
|
|
42
|
- chkResult = false;
|
|
|
43
|
- invalidProIds.push('286143');
|
|
|
44
|
- } else {
|
|
|
45
|
- if (req.query.productId === '286143') {
|
|
|
46
|
- chkResult = false;
|
|
|
47
|
- } else {
|
|
|
48
|
- chkResult = true;
|
|
|
49
|
- }
|
|
|
50
|
- }
|
|
|
51
|
-
|
|
|
52
|
- if (invalidProIds.length) {
|
|
|
53
|
- _.merge(result, {
|
|
|
54
|
- invalidProIds: invalidProIds
|
|
|
55
|
- });
|
|
|
56
|
- }
|
|
|
57
|
-
|
|
|
58
|
- _.merge(result, {
|
|
|
59
|
- valid: chkResult
|
|
|
60
|
- });
|
|
|
61
|
-
|
|
|
62
|
- res.json(result);
|
|
|
63
|
-};
|
|
|
64
|
-
|
|
|
65
|
|
35
|
|
66
|
// 修改数量
|
36
|
// 修改数量
|
67
|
exports.changeProductNum = (req, res) => {
|
37
|
exports.changeProductNum = (req, res) => {
|
|
@@ -71,13 +41,15 @@ exports.changeProductNum = (req, res) => { |
|
@@ -71,13 +41,15 @@ exports.changeProductNum = (req, res) => { |
71
|
const uid = req.user.uid;
|
41
|
const uid = req.user.uid;
|
72
|
const shoppingKey = req.cookies._SPK;
|
42
|
const shoppingKey = req.cookies._SPK;
|
73
|
const sku = req.body.sku;
|
43
|
const sku = req.body.sku;
|
|
|
44
|
+ const goodTpye = req.body.goodType;
|
74
|
|
45
|
|
75
|
if (changeType === 'INCREASE') {
|
46
|
if (changeType === 'INCREASE') {
|
76
|
cartModel.modifyProductNum({
|
47
|
cartModel.modifyProductNum({
|
77
|
increaseNum: 1, // 默认是1
|
48
|
increaseNum: 1, // 默认是1
|
78
|
uid,
|
49
|
uid,
|
79
|
shoppingKey,
|
50
|
shoppingKey,
|
80
|
- sku
|
51
|
+ sku,
|
|
|
52
|
+ goodTpye
|
81
|
}).then(result => {
|
53
|
}).then(result => {
|
82
|
console.log('changeProductNum-INCREASE-result:', result);
|
54
|
console.log('changeProductNum-INCREASE-result:', result);
|
83
|
if (result.code === 200) {
|
55
|
if (result.code === 200) {
|
|
@@ -102,7 +74,8 @@ exports.changeProductNum = (req, res) => { |
|
@@ -102,7 +74,8 @@ exports.changeProductNum = (req, res) => { |
102
|
decreaseNum: 1, // 默认是1
|
74
|
decreaseNum: 1, // 默认是1
|
103
|
uid,
|
75
|
uid,
|
104
|
shoppingKey,
|
76
|
shoppingKey,
|
105
|
- sku
|
77
|
+ sku,
|
|
|
78
|
+ goodTpye
|
106
|
}).then(result => {
|
79
|
}).then(result => {
|
107
|
console.log('changeProductNum-DECREASE-result:', result);
|
80
|
console.log('changeProductNum-DECREASE-result:', result);
|
108
|
if (result.code === 200) {
|
81
|
if (result.code === 200) {
|
|
@@ -199,6 +172,7 @@ exports.addToCart = (req, res) => { |
|
@@ -199,6 +172,7 @@ exports.addToCart = (req, res) => { |
199
|
shoppingKey: req.cookies._SPK || null,
|
172
|
shoppingKey: req.cookies._SPK || null,
|
200
|
uid: req.user.uid
|
173
|
uid: req.user.uid
|
201
|
}).then((result) => {
|
174
|
}).then((result) => {
|
|
|
175
|
+ res.cookie('_SPK', result.data.shopping_key);
|
202
|
res.json(result);
|
176
|
res.json(result);
|
203
|
});
|
177
|
});
|
204
|
};
|
178
|
};
|
|
@@ -234,39 +208,5 @@ exports.toggleSelectGoods = (req, res) => { |
|
@@ -234,39 +208,5 @@ exports.toggleSelectGoods = (req, res) => { |
234
|
});
|
208
|
});
|
235
|
};
|
209
|
};
|
236
|
|
210
|
|
237
|
-// 购物车商品选择与取消选择
|
|
|
238
|
-exports.modifyProductNum = (req, res) => {
|
|
|
239
|
- const uid = req.user.uid;
|
|
|
240
|
- const shoppingKey = req.cookies._SPK;
|
|
|
241
|
- const changeType = req.body.changeType;
|
|
|
242
|
- const changeNum = req.body.changeNum;
|
|
|
243
|
- const sku = req.body.sku;
|
|
|
244
|
-
|
|
|
245
|
- let params = {
|
|
|
246
|
- uid,
|
|
|
247
|
- shoppingKey,
|
|
|
248
|
- sku
|
|
|
249
|
- };
|
|
|
250
|
-
|
|
|
251
|
- if (changeType === 'INCREASE') {
|
|
|
252
|
- _.merge(params, {
|
|
|
253
|
- increaseNum: changeNum
|
|
|
254
|
- });
|
|
|
255
|
- } else if (changeType === 'DECREASE') {
|
|
|
256
|
- _.merge(params, {
|
|
|
257
|
- decreaseNum: changeNum
|
|
|
258
|
- });
|
|
|
259
|
- } else {
|
|
|
260
|
-
|
|
|
261
|
- // TODO
|
|
|
262
|
- // CHANGE
|
|
|
263
|
- }
|
|
|
264
|
-
|
|
|
265
|
- cartModel.modifyProductNum(params).then(result => {
|
|
|
266
|
- res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code, message: result.message}));
|
|
|
267
|
- });
|
|
|
268
|
-
|
|
|
269
|
-};
|
|
|
270
|
-
|
|
|
271
|
|
211
|
|
272
|
|
212
|
|