...
|
...
|
@@ -83,8 +83,8 @@ const addToCart = (options) => { |
|
|
* }
|
|
|
*/
|
|
|
const getCartData = (shoppingKey, uid) => {
|
|
|
console.log('SPK:', shoppingKey);
|
|
|
console.log('uid:', uid);
|
|
|
// console.log('SPK:', shoppingKey);
|
|
|
// console.log('uid:', uid);
|
|
|
let params = {
|
|
|
method: 'app.Shopping.cart'
|
|
|
};
|
...
|
...
|
@@ -132,12 +132,49 @@ const toggleSelectGoods = (params) => { |
|
|
let method = 'app.Shopping.selectedAndCart';
|
|
|
|
|
|
_.merge(params, {method});
|
|
|
|
|
|
/*
|
|
|
let resultData;
|
|
|
let skus = JSON.parse(params.product_sku_list).map(sku => return sku.product_sku);
|
|
|
const skusLen = skus.length;
|
|
|
|
|
|
_.merge(params, {method});
|
|
|
|
|
|
return getCartData(params.shopping_key, params.uid).then(function(result) {
|
|
|
// 检查库存量
|
|
|
resultData = result.data;
|
|
|
|
|
|
_.find(
|
|
|
_.concat(resultData.ordinary_cart_data.goods_list, resultData.advance_cart_data.goods_list),
|
|
|
(goodItem) => {
|
|
|
if (skusLen == 1 && goodItem.product_sku === skus[0] &&
|
|
|
(parseInt(goodItem.buy_number, 10) > parseInt(goodItem.storage_number, 10))) {
|
|
|
// 单个商品
|
|
|
return {
|
|
|
code: '1000',
|
|
|
message: '您勾选的商品库存不足'
|
|
|
};
|
|
|
} else {
|
|
|
if((parseInt(goodItem.buy_number, 10) > parseInt(goodItem.storage_number, 10))) {
|
|
|
// 全选
|
|
|
return api.get('', params).then(result => {
|
|
|
return _.merge(result, {
|
|
|
code: '1001',
|
|
|
message: '您全选的商品中存在库存不足商品,已帮您自动取消勾选'
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
*/
|
|
|
|
|
|
return api.get('', params);
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* 商品选择与取消选择
|
|
|
* @function toggleSelectGoods
|
|
|
* 删除商品
|
|
|
* @function removeGoods
|
|
|
* @param { Number } uid 用户UID
|
|
|
* @param { String } sku 商品sku列表
|
|
|
* @param { String } shoppingKey 未登录用户唯一识别码,可以不传
|
...
|
...
|
@@ -153,7 +190,7 @@ const removeGoods = (params) => { |
|
|
|
|
|
/*
|
|
|
* 每次操作处理购物车数据
|
|
|
* @function toggleSelectGoods
|
|
|
* @function filterCartData
|
|
|
* @param { Object } result 购物车数据
|
|
|
* {
|
|
|
* advance_cart_data: { // 预售商品
|
...
|
...
|
@@ -199,17 +236,20 @@ const filterCartData = (result, uid) => { |
|
|
|
|
|
// 商品总数量
|
|
|
let buyNumber;
|
|
|
let storageNumber;
|
|
|
let totalNum = 0;
|
|
|
let noStorage = [];
|
|
|
|
|
|
// 返回值
|
|
|
let resData = {
|
|
|
loggedIn: uid
|
|
|
};
|
|
|
|
|
|
// 预售商品
|
|
|
if (result.data && result.data.advance_cart_data) {
|
|
|
// 预售商品
|
|
|
advancedCartData = result.data.advance_cart_data;
|
|
|
console.log('---------------advance------:', advancedCartData.goods_list.length);
|
|
|
|
|
|
// console.log('---------------advance------:', advancedCartData.goods_list.length);
|
|
|
totalAdvanceMoney = advancedCartData.shopping_cart_data.last_order_amount;
|
|
|
advancedGoods = _.concat(advancedGoods, advancedCartData.goods_list);
|
|
|
invalidGoods = _.concat(invalidGoods, advancedCartData.off_shelves_goods_list);
|
...
|
...
|
@@ -217,17 +257,25 @@ const filterCartData = (result, uid) => { |
|
|
|
|
|
_.forEach(advancedGoods, function(good) {
|
|
|
buyNumber = parseInt(good.buy_number, 10);
|
|
|
storageNumber = parseInt(good.storage_number, 10);
|
|
|
totalNum += buyNumber;
|
|
|
_.merge(good, {
|
|
|
left_number: storageNumber - buyNumber
|
|
|
});
|
|
|
if (good.selected === 'Y') {
|
|
|
selectedAdvanceNum += buyNumber;
|
|
|
if (storageNumber < buyNumber) {
|
|
|
noStorage.push(good.product_name);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 普通商品
|
|
|
if (result.data && result.data.ordinary_cart_data) {
|
|
|
// 普通商品
|
|
|
ordinaryCartData = result.data.ordinary_cart_data;
|
|
|
console.log('---------------ordinary------:', ordinaryCartData.goods_list.length);
|
|
|
|
|
|
// console.log('---------------ordinary------:', ordinaryCartData.goods_list.length);
|
|
|
totalOrdinaryMoney = ordinaryCartData.shopping_cart_data.last_order_amount;
|
|
|
ordinaryGoods = _.concat(ordinaryGoods, ordinaryCartData.goods_list);
|
|
|
invalidGoods = _.concat(invalidGoods, ordinaryCartData.off_shelves_goods_list);
|
...
|
...
|
@@ -235,9 +283,17 @@ const filterCartData = (result, uid) => { |
|
|
|
|
|
_.forEach(ordinaryGoods, function(good) {
|
|
|
buyNumber = parseInt(good.buy_number, 10);
|
|
|
storageNumber = parseInt(good.storage_number, 10);
|
|
|
totalNum += buyNumber;
|
|
|
_.merge(good, {
|
|
|
left_number: storageNumber - buyNumber
|
|
|
});
|
|
|
|
|
|
if (good.selected === 'Y') {
|
|
|
selectedOrdinaryNum += buyNumber;
|
|
|
if (storageNumber < buyNumber) {
|
|
|
noStorage.push(good.product_name);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -252,8 +308,8 @@ const filterCartData = (result, uid) => { |
|
|
invalidPros: invalidGoods,
|
|
|
selectedNum: selectedAdvanceNum + selectedOrdinaryNum,
|
|
|
checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum),
|
|
|
totalMoney: totalAdvanceMoney + totalOrdinaryMoney
|
|
|
|
|
|
totalMoney: totalAdvanceMoney + totalOrdinaryMoney,
|
|
|
noStorage
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -273,12 +329,18 @@ const modifyProductNum = (options) => { |
|
|
const uid = options.uid;
|
|
|
const shoppingKey = options.shoppingKey;
|
|
|
const sku = options.sku;
|
|
|
const goodType = options.goodType;
|
|
|
const goodType = options.goodTpye;
|
|
|
|
|
|
let buyNumber,
|
|
|
storageNumber;
|
|
|
|
|
|
let params = {
|
|
|
product_sku: options.sku
|
|
|
};
|
|
|
|
|
|
// 减少到库存范围内,自动勾选
|
|
|
// let selectedParams;
|
|
|
|
|
|
// 增加
|
|
|
if (increaseNum) {
|
|
|
_.merge(params, {
|
...
|
...
|
@@ -310,17 +372,88 @@ const modifyProductNum = (options) => { |
|
|
});
|
|
|
|
|
|
return getCartData(shoppingKey, uid).then(function(result) {
|
|
|
console.log('getCartData--pre-callback-result:', result);
|
|
|
console.log('modifyProductNum---params:', params);
|
|
|
// console.log('getCartData--pre-callback-result:', JSON.stringify(result, '', 4));
|
|
|
// console.log('modifyProductNum---params:', params);
|
|
|
|
|
|
if (goodType === 'advance') {
|
|
|
// 检查库存量
|
|
|
// 同步
|
|
|
_.find(result.data.advance_cart_data.goods_list, (goodItem) => {
|
|
|
if (goodItem.product_sku === sku) {
|
|
|
buyNumber = parseInt(goodItem.buy_number, 10);
|
|
|
storageNumber = parseInt(goodItem.storage_number, 10);
|
|
|
|
|
|
// 计算剩余多少
|
|
|
_.merge(goodItem, {
|
|
|
left_number: storageNumber - buyNumber
|
|
|
});
|
|
|
|
|
|
// 减少到库存范围内,自动勾选
|
|
|
// if(decreaseNum && buyNumber <= storageNumber) {
|
|
|
// selectedParams = {
|
|
|
// product_sku_list: JSON.stringify([{
|
|
|
// "goods_type": "ordinary",
|
|
|
// "buy_number": buyNumber,
|
|
|
// "selected": "Y",
|
|
|
// "product_sku": sku,
|
|
|
// "promotion_id": 0
|
|
|
// }]),
|
|
|
// uid: uid,
|
|
|
// shopping_key: shoppingKey
|
|
|
// };
|
|
|
// }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 增加
|
|
|
if (increaseNum && (buyNumber + increaseNum) > storageNumber) {
|
|
|
return {
|
|
|
code: '1000',
|
|
|
message: '商品库存不足'
|
|
|
};
|
|
|
}
|
|
|
} else if (goodType === 'ordinary') {
|
|
|
// 检查库存量
|
|
|
// 同步
|
|
|
_.find(result.data.ordinary_cart_data.goods_list, (goodItem) => {
|
|
|
if (goodItem.product_sku === sku) {
|
|
|
buyNumber = parseInt(goodItem.buy_number, 10);
|
|
|
storageNumber = parseInt(goodItem.storage_number, 10);
|
|
|
|
|
|
// 计算剩余多少
|
|
|
_.merge(goodItem, {
|
|
|
left_number: storageNumber - buyNumber
|
|
|
});
|
|
|
|
|
|
// 减少到库存范围内,自动勾选
|
|
|
// if(decreaseNum && buyNumber <= storageNumber) {
|
|
|
// selectedParams = {
|
|
|
// product_sku_list: JSON.stringify([{
|
|
|
// "goods_type": "ordinary",
|
|
|
// "buy_number": buyNumber,
|
|
|
// "selected": "Y",
|
|
|
// "product_sku": sku,
|
|
|
// "promotion_id": 0
|
|
|
// }]),
|
|
|
// uid: uid,
|
|
|
// shopping_key: shoppingKey
|
|
|
// };
|
|
|
// }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 增加
|
|
|
if (increaseNum && (buyNumber + increaseNum) > storageNumber) {
|
|
|
return {
|
|
|
code: '1000',
|
|
|
message: '商品库存不足'
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 异步
|
|
|
return api.get('', params);
|
|
|
});
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|