Authored by jinhu.tung

modify cart number

... ... @@ -190,5 +190,38 @@ exports.toggleSelectGoods = (req, res) => {
});
};
// 购物车商品选择与取消选择
exports.modifyProductNum = (req, res) => {
const uid = req.cookies.uid;
const shoppingKey = req.cookies._SPK;
const changeType = req.body.changeType;
const changeNum = req.body.changeNum;
const sku = req.body.sku;
let params = {
uid,
shoppingKey,
sku
};
if(changeType === 'INCREASE') {
_.merge(params, {
increaseNum: changeNum
});
} else if(changeType === 'DECREASE') {
_.merge(params, {
decreaseNum: changeNum
});
} else {
// TODO
// CHANGE
}
cartModel.modifyProductNum(params).then(result => {
res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code}));
});
}
... ...
... ... @@ -259,15 +259,72 @@ const filterCartData = (result, uid) => {
selectedNum: selectedAdvanceNum + selectedOrdinaryNum,
checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum),
totalMoney: totalAdvanceMoney + totalOrdinaryMoney
});
};
/**
* 增减购物车商品数量
* @function modifyProductNum
* @param { Number } uid 用户ID
* @param { String } sku 商品SKU
* @param { Number } increaseNum 增加的数目
* @param { Number } decreaseNum 减少的数目
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Array } 接口返回的数据
*/
const modifyProductNum = (options) => {
const increaseNum = options.increaseNum;
const decreaseNum = options.decreaseNum;
const uid = options.uid;
const shoppingKey = options.shoppingKey;
const sku = options.sku;
let params = {
product_sku: options.sku
}
// 增加
if(increaseNum) {
_.merge(params, {
method: 'app.Shopping.increase',
increase_number: parseInt(increaseNum, 10)
});
}
// 减少
if(decreaseNum) {
_.merge(params, {
method: 'app.Shopping.decrease',
decrease_number: parseInt(decreaseNum, 10)
});
}
if(uid) {
_.merge(params, {uid});
}
if(shoppingKey) {
_.merge(params, {
shopping_key: shoppingKey
});
}
if(sku) {
_.merge(params, {
product_sku: sku
});
}
return api.get('', params);
}
module.exports = {
addToCart,
getCartData,
transferToFavorite,
toggleSelectGoods,
removeGoods,
filterCartData
filterCartData,
modifyProductNum
};
... ...
... ... @@ -12,11 +12,7 @@
API使用:
var address = cascadingAddress({
el: '#address',
url: 'http://localhost:3000/areas/0',
resource: 'areas'
});
var address = cascadingAddress({el: '#address'});
获取选择地址文本:
... ...