...
|
...
|
@@ -18,6 +18,27 @@ const getProductInfo = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 设置购物车COOKIE信息
|
|
|
*/
|
|
|
const setShoppingCookie = (req) => {
|
|
|
|
|
|
let uid = req.user.uid || true;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
|
|
|
return service.getCartCount(uid, shoppingKey).then(ret => {
|
|
|
if (ret && ret.data && ret.data.cart_goods_count) {
|
|
|
req.cookies('_g', {
|
|
|
_k: shoppingKey,
|
|
|
_nac: ret.data.cart_goods_count,
|
|
|
_ac: 0,
|
|
|
_r: 1
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 我的购物车
|
|
|
*/
|
...
|
...
|
@@ -27,6 +48,10 @@ const cart = (req, res, next) => { |
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
|
|
|
if (cartDelList) {
|
|
|
req.cookies['cart-del-list'] = '';
|
|
|
}
|
|
|
|
|
|
service.getCartData(uid, shoppingKey, cartDelList)
|
|
|
.then(ret => {
|
|
|
console.log(JSON.stringify(ret));
|
...
|
...
|
@@ -58,24 +83,44 @@ const cartTotal = () => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置购物车COOKIE信息
|
|
|
*/
|
|
|
const setShoppingCookie = () => {
|
|
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车商品选择与取消
|
|
|
*/
|
|
|
const selectProduct = () => {
|
|
|
const selectProduct = (req, res) => {
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let productId = req.body.skuList;
|
|
|
let hasPromotion = req.body.hasPromotion || false;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
|
|
|
service.selectGoods(uid, productId, shoppingKey, hasPromotion)
|
|
|
.then(ret => {
|
|
|
res.send(ret);
|
|
|
}).catch(() => {
|
|
|
res.send({
|
|
|
code: 400
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 修改购物车商品数量
|
|
|
*/
|
|
|
const modifyProduct = () => {
|
|
|
const modifyProduct = (req, res) => {
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let sku = req.body.sku;
|
|
|
let increaseNum = req.body.increaseNum || null;
|
|
|
let decreaseNum = req.body.decreaseNum || null;
|
|
|
|
|
|
return service.modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey)
|
|
|
.then(ret => {
|
|
|
if (ret && ret.code === 200) {
|
|
|
return setShoppingCookie().then(() => {
|
|
|
return res.send(ret);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
|