...
|
...
|
@@ -4,8 +4,10 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const co = require('bluebird').coroutine;
|
|
|
const service = require('../models/cart-service');
|
|
|
const helper = require('../models/cart-helper');
|
|
|
const ghelper = require('../../guang/models/guang-helper');
|
|
|
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
|
|
|
|
|
|
const getProductInfo = (req, res, next) => {
|
...
|
...
|
@@ -73,6 +75,35 @@ const cart = (req, res, next) => { |
|
|
*/
|
|
|
const cartAdd = () => {
|
|
|
|
|
|
co(function * (){
|
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let productSku = req.body.productSku;
|
|
|
let buyNumber = req.body.buyNumber || 1;
|
|
|
let goodsType = req.body.goodsType || 0;
|
|
|
let promotionId = req.body.promotionId || 0
|
|
|
let isEdit = req.body.isEdit || 0;
|
|
|
|
|
|
let result = yield service.addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey);
|
|
|
|
|
|
// 设置加入购物车凭证到客户端浏览器
|
|
|
if(!shoppingKey && result && result.data && result.data.shopping_key) {
|
|
|
// req.cookies['_SPK'] = result.data.shopping_key
|
|
|
//$this->setCookie('_SPK', $result['data']['shopping_key'], time() + 86400 * 360);
|
|
|
}
|
|
|
|
|
|
// 老站购物车需要的COOKIE
|
|
|
if (result && result.data && result.data.shopping_key) {
|
|
|
/*$this->setCookie('_g', json_encode(array(
|
|
|
'_k' => $result['data']['shopping_key'],
|
|
|
'_nac' => $result['data']['goods_count'],
|
|
|
'_ac' => 0,
|
|
|
'_r' => 1
|
|
|
)));*/
|
|
|
}
|
|
|
|
|
|
res.send(result);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -80,6 +111,15 @@ const cartAdd = () => { |
|
|
*/
|
|
|
const cartTotal = () => {
|
|
|
|
|
|
co(function * (){
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let callback = req.query.callback;
|
|
|
let ret = yield service.getCartCount(uid, shoppingKey);
|
|
|
|
|
|
return res.send(callback + '(' + JSON.stringify(ret) + ')');
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -120,43 +160,113 @@ const modifyProduct = (req, res) => { |
|
|
return res.send(ret);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 移出购物车
|
|
|
*/
|
|
|
const removeProduct = () => {
|
|
|
const removeProduct = (req, res) => {
|
|
|
|
|
|
co(function * (){
|
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let skuList = req.body.skuList;
|
|
|
let hasPromotion = true;
|
|
|
|
|
|
let ret = yield service.removeFromCart(uid, shoppingKey, skuList, hasPromotion);
|
|
|
|
|
|
if(ret && ret.code === 200) {
|
|
|
yield setShoppingCookie();
|
|
|
}
|
|
|
|
|
|
return res.send(ret);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 移入收藏夹
|
|
|
* 支持批量移入收藏夹
|
|
|
*/
|
|
|
const moveToFav = () => {
|
|
|
const moveToFav = (req, res) => {
|
|
|
|
|
|
co(function * (){
|
|
|
let uid = req.user.uid;
|
|
|
// let shoppingKey = helper.getShoppingKeyByCookie(req);
|
|
|
let skuList = req.body.skuList;
|
|
|
let hasPromotion = req.body.hasPromotion || false;
|
|
|
|
|
|
let ret = yield service.addToFav(uid, skuList, hasPromotion);
|
|
|
|
|
|
if(ret && ret.code === 200) {
|
|
|
yield setShoppingCookie();
|
|
|
}
|
|
|
|
|
|
return res.send(ret);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 检查是否收藏
|
|
|
*/
|
|
|
const checkFav = () => {
|
|
|
const checkFav = (req, res) => {
|
|
|
|
|
|
co(function * (){
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let pids = req.body.pidList;
|
|
|
let ret = {
|
|
|
code: 200,
|
|
|
message: '是否收藏',
|
|
|
data: {}
|
|
|
};
|
|
|
|
|
|
ret.data = yield service.checkUserIsFav(uid, pids);
|
|
|
|
|
|
return res.send(ret);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 凑单商品异步请求
|
|
|
*/
|
|
|
const getTogetherProduct = () => {
|
|
|
const getTogetherProduct = (req, res) => {
|
|
|
|
|
|
co(function * (){
|
|
|
|
|
|
let page = req.query.page;
|
|
|
/*let ret = {
|
|
|
code: 200,
|
|
|
message: '凑单商品'
|
|
|
};*/
|
|
|
|
|
|
ret = yield service.getTogetherProduct(page);
|
|
|
|
|
|
return res.send(ret);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 为你优选商品异步请求
|
|
|
*/
|
|
|
const getRecommendProductAction = () => {
|
|
|
const getRecommendProductAction = (req, res) => {
|
|
|
|
|
|
co(function * (){
|
|
|
|
|
|
let channel = req.yoho.channel;
|
|
|
let uid = req.user.uid;
|
|
|
let udid = ghelper.getUdid(req, res);
|
|
|
let page = req.query.page;
|
|
|
|
|
|
if(page === '6') {
|
|
|
page = 1;
|
|
|
}
|
|
|
|
|
|
let ret = yield service.getRecommendProduct(channel, uid, udid, page);
|
|
|
|
|
|
res.send(ret);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
...
|
...
|
|