...
|
...
|
@@ -4,7 +4,9 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const co = require('bluebird').coroutine;
|
|
|
const logger = global.yoho.logger;
|
|
|
const service = require('../models/cart-service');
|
|
|
const helper = require('../models/cart-helper');
|
|
|
const ghelper = require('../../guang/models/guang-helper');
|
...
|
...
|
@@ -134,7 +136,8 @@ const cartAdd = (req, res) => { |
|
|
let goodsType = req.body.goodsType || 0;
|
|
|
let promotionId = req.body.promotionId || 0;
|
|
|
let isEdit = req.body.isEdit || 0;
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let isReAdd = !!req.body.isReAdd || false;
|
|
|
let cartDelList = helper.getCartDelList(req, res, null, isReAdd ? productSku : null);
|
|
|
|
|
|
let result = yield service.addToCart(productSku, buyNumber,
|
|
|
goodsType, isEdit, promotionId,
|
...
|
...
|
@@ -182,7 +185,7 @@ const selectProduct = (req, res) => { |
|
|
let productId = req.body.skuList;
|
|
|
let hasPromotion = req.body.hasPromotion || false;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let cartDelList = helper.getCartDelList(req, res);
|
|
|
|
|
|
service.selectGoods(uid, productId, shoppingKey, hasPromotion, cartDelList)
|
|
|
.then(ret => {
|
...
|
...
|
@@ -204,7 +207,7 @@ const modifyProductNum = (req, res, next) => { |
|
|
let sku = req.body.sku;
|
|
|
let increaseNum = req.body.increaseNum || null;
|
|
|
let decreaseNum = req.body.decreaseNum || null;
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let cartDelList = helper.getCartDelList(req, res);
|
|
|
|
|
|
return service.modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey, cartDelList)
|
|
|
.then(ret => {
|
...
|
...
|
@@ -232,20 +235,17 @@ const removeProduct = (req, res) => { |
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let skuList = req.body.skuList;
|
|
|
let hasPromotion = true;
|
|
|
let cartDelList = req.body.cartDelList;
|
|
|
|
|
|
// let cartDelList = req.cookies['cart-del-list'];
|
|
|
|
|
|
let cartDelList = helper.getCartDelList(req, res, req.body.cartDelList);
|
|
|
|
|
|
let ret = yield service.removeFromCart(uid, shoppingKey, skuList, hasPromotion, cartDelList);
|
|
|
|
|
|
if (ret && ret.code === 200) {
|
|
|
yield setShoppingCookie(req, res);
|
|
|
|
|
|
res.cookie('cart-del-list', cartDelList, {
|
|
|
/* res.cookie('cart-del-list', cartDelList, {
|
|
|
domain: '.yohobuy.com',
|
|
|
path: '/'
|
|
|
});
|
|
|
});*/
|
|
|
}
|
|
|
|
|
|
return res.send(ret);
|
...
|
...
|
@@ -264,9 +264,25 @@ const moveToFav = (req, res) => { |
|
|
// let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let skuList = req.body.skuList;
|
|
|
let hasPromotion = req.body.hasPromotion || false;
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let isReFav = !!req.body.isReFav || false;
|
|
|
let productSku = null;
|
|
|
let cartDelList;
|
|
|
let ret;
|
|
|
|
|
|
let ret = yield service.addToFav(uid, skuList, hasPromotion, cartDelList);
|
|
|
if (isReFav) {
|
|
|
try {
|
|
|
let sl = JSON.parse(skuList);
|
|
|
|
|
|
if (sl && sl.length) {
|
|
|
productSku = _.get(sl[0], 'product_sku');
|
|
|
}
|
|
|
} catch (err) {
|
|
|
logger.error(err);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cartDelList = helper.getCartDelList(req, res, null, productSku);
|
|
|
ret = yield service.addToFav(uid, skuList, hasPromotion, cartDelList);
|
|
|
|
|
|
if (ret && ret.code === 200) {
|
|
|
yield setShoppingCookie(req, res);
|
...
|
...
|
@@ -363,7 +379,7 @@ const getIncreasePurchase = (req, res) => { |
|
|
const modifyProduct = (req, res, next) => {
|
|
|
const uid = req.user && req.user.uid;
|
|
|
const shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let cartDelList = helper.getCartDelList(req, res);
|
|
|
|
|
|
// swapData => [{"buy_number":"1","selected":"Y","new_product_sku":"735172","old_product_sku":"735171"}]
|
|
|
const swapData = req.body.swapData;
|
...
|
...
|
@@ -386,7 +402,7 @@ const swapGift = (req, res, next) => { |
|
|
let promotionId = req.body.promotionId;
|
|
|
let newSkn = req.body.newSkn;
|
|
|
let newSku = req.body.newSku;
|
|
|
let cartDelList = req.cookies['cart-del-list'];
|
|
|
let cartDelList = helper.getCartDelList(req, res);
|
|
|
|
|
|
service.swapGift(uid, shoppingKey, promotionId, newSkn, newSku, cartDelList)
|
|
|
.then(ret => {
|
...
|
...
|
|