Authored by jinhu.tung

modify cart number

@@ -190,5 +190,38 @@ exports.toggleSelectGoods = (req, res) => { @@ -190,5 +190,38 @@ exports.toggleSelectGoods = (req, res) => {
190 }); 190 });
191 }; 191 };
192 192
  193 +// 购物车商品选择与取消选择
  194 +exports.modifyProductNum = (req, res) => {
  195 + const uid = req.cookies.uid;
  196 + const shoppingKey = req.cookies._SPK;
  197 + const changeType = req.body.changeType;
  198 + const changeNum = req.body.changeNum;
  199 + const sku = req.body.sku;
  200 +
  201 + let params = {
  202 + uid,
  203 + shoppingKey,
  204 + sku
  205 + };
  206 +
  207 + if(changeType === 'INCREASE') {
  208 + _.merge(params, {
  209 + increaseNum: changeNum
  210 + });
  211 + } else if(changeType === 'DECREASE') {
  212 + _.merge(params, {
  213 + decreaseNum: changeNum
  214 + });
  215 + } else {
  216 + // TODO
  217 + // CHANGE
  218 + }
  219 +
  220 + cartModel.modifyProductNum(params).then(result => {
  221 + res.json(_.merge(cartModel.filterCartData(result, uid), {code: result.code}));
  222 + });
  223 +
  224 +}
  225 +
193 226
194 227
@@ -259,15 +259,72 @@ const filterCartData = (result, uid) => { @@ -259,15 +259,72 @@ const filterCartData = (result, uid) => {
259 selectedNum: selectedAdvanceNum + selectedOrdinaryNum, 259 selectedNum: selectedAdvanceNum + selectedOrdinaryNum,
260 checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum), 260 checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum),
261 totalMoney: totalAdvanceMoney + totalOrdinaryMoney 261 totalMoney: totalAdvanceMoney + totalOrdinaryMoney
262 - 262 +
263 }); 263 });
264 }; 264 };
265 265
  266 +/**
  267 + * 增减购物车商品数量
  268 + * @function modifyProductNum
  269 + * @param { Number } uid 用户ID
  270 + * @param { String } sku 商品SKU
  271 + * @param { Number } increaseNum 增加的数目
  272 + * @param { Number } decreaseNum 减少的数目
  273 + * @param { String } shoppingKey 未登录用户唯一识别码
  274 + * @return { Array } 接口返回的数据
  275 + */
  276 +const modifyProductNum = (options) => {
  277 + const increaseNum = options.increaseNum;
  278 + const decreaseNum = options.decreaseNum;
  279 + const uid = options.uid;
  280 + const shoppingKey = options.shoppingKey;
  281 + const sku = options.sku;
  282 +
  283 + let params = {
  284 + product_sku: options.sku
  285 + }
  286 +
  287 + // 增加
  288 + if(increaseNum) {
  289 + _.merge(params, {
  290 + method: 'app.Shopping.increase',
  291 + increase_number: parseInt(increaseNum, 10)
  292 + });
  293 + }
  294 +
  295 + // 减少
  296 + if(decreaseNum) {
  297 + _.merge(params, {
  298 + method: 'app.Shopping.decrease',
  299 + decrease_number: parseInt(decreaseNum, 10)
  300 + });
  301 + }
  302 +
  303 + if(uid) {
  304 + _.merge(params, {uid});
  305 + }
  306 +
  307 + if(shoppingKey) {
  308 + _.merge(params, {
  309 + shopping_key: shoppingKey
  310 + });
  311 + }
  312 +
  313 + if(sku) {
  314 + _.merge(params, {
  315 + product_sku: sku
  316 + });
  317 + }
  318 +
  319 + return api.get('', params);
  320 +}
  321 +
266 module.exports = { 322 module.exports = {
267 addToCart, 323 addToCart,
268 getCartData, 324 getCartData,
269 transferToFavorite, 325 transferToFavorite,
270 toggleSelectGoods, 326 toggleSelectGoods,
271 removeGoods, 327 removeGoods,
272 - filterCartData 328 + filterCartData,
  329 + modifyProductNum
273 }; 330 };
@@ -12,11 +12,7 @@ @@ -12,11 +12,7 @@
12 12
13 API使用: 13 API使用:
14 14
15 - var address = cascadingAddress({  
16 - el: '#address',  
17 - url: 'http://localhost:3000/areas/0',  
18 - resource: 'areas'  
19 - }); 15 + var address = cascadingAddress({el: '#address'});
20 16
21 获取选择地址文本: 17 获取选择地址文本:
22 18