...
|
...
|
@@ -9,7 +9,7 @@ const helpers = global.yoho.helpers; |
|
|
const _ = require('lodash');
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
|
|
|
const indexModel = require('../models/index');
|
|
|
const cartModel = require('../models/index');
|
|
|
|
|
|
/**
|
|
|
* [购物车首页]
|
...
|
...
|
@@ -60,7 +60,7 @@ const indexData = (req, res, next) => { |
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
|
|
|
return indexModel.indexData(uid, shoppingKey, channel, cartType).then(data => {
|
|
|
return req.ctx(cartModel).indexData(uid, shoppingKey, channel, cartType).then(data => {
|
|
|
data ? res.json({
|
|
|
code: 200,
|
|
|
data
|
...
|
...
|
@@ -92,7 +92,7 @@ const select = (req, res, next) => { |
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
|
|
|
return indexModel.selectGood(uid, skuList, shoppingKey, cartType).then(data => {
|
|
|
return req.ctx(cartModel).selectGood(uid, skuList, shoppingKey, cartType).then(data => {
|
|
|
data ? res.json({
|
|
|
code: 200,
|
|
|
data
|
...
|
...
|
@@ -124,7 +124,7 @@ const del = (req, res, next) => { |
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
|
|
|
return indexModel.removeFromCart(uid, skuList, shoppingKey, cartType).then(data => {
|
|
|
return req.ctx(cartModel).removeFromCart(uid, skuList, shoppingKey, cartType).then(data => {
|
|
|
data ? res.json({
|
|
|
code: 200,
|
|
|
data
|
...
|
...
|
@@ -166,7 +166,8 @@ const add = (req, res, next) => { |
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
|
|
|
return indexModel.addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey).then(data => {
|
|
|
return req.ctx(cartModel).addToCart(
|
|
|
productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey).then(data => {
|
|
|
if (!shoppingKey && _.has(data, 'data.shopping_key')) {
|
|
|
res.cookie('_SPK', data.data.shopping_key, {
|
|
|
expires: new Date(Date.now() + 86400 * 360),
|
...
|
...
|
@@ -200,10 +201,10 @@ const goodinfo = (req, res, next) => { |
|
|
});
|
|
|
}
|
|
|
|
|
|
return indexModel.cartProductData(uid, skn, buyNum).then(data => {
|
|
|
return req.ctx(cartModel).cartProductData(uid, skn, buyNum).then(data => {
|
|
|
return new Promise((resolve) => {
|
|
|
if (mnum && data) {
|
|
|
return indexModel.handleBundleInfo(skn).then(disRes => {
|
|
|
return req.ctx(cartModel).handleBundleInfo(skn).then(disRes => {
|
|
|
result.discountBuy = disRes;
|
|
|
resolve(data);
|
|
|
});
|
...
|
...
|
@@ -249,7 +250,7 @@ const col = (req, res, next) => { |
|
|
data: helpers.urlFormat('/signin.html')
|
|
|
});
|
|
|
}
|
|
|
return indexModel.addToFav(uid, skuList, cartType).then(data => {
|
|
|
return req.ctx(cartModel).addToFav(uid, skuList, cartType).then(data => {
|
|
|
data ? res.json({
|
|
|
code: 200,
|
|
|
data
|
...
|
...
|
@@ -286,9 +287,9 @@ const modifyNum = (req, res, next) => { |
|
|
let promise;
|
|
|
|
|
|
if (increaseNum > 0) {
|
|
|
promise = indexModel.increaseProductNum(uid, sku, increaseNum, shoppingKey);
|
|
|
promise = req.ctx(cartModel).increaseProductNum(uid, sku, increaseNum, shoppingKey);
|
|
|
} else if (decreaseNum > 0) {
|
|
|
promise = indexModel.decreaseProductNum(uid, sku, decreaseNum, shoppingKey);
|
|
|
promise = req.ctx(cartModel).decreaseProductNum(uid, sku, decreaseNum, shoppingKey);
|
|
|
}
|
|
|
|
|
|
return promise.then(data => {
|
...
|
...
|
@@ -333,7 +334,7 @@ const modify = (req, res, next) => { |
|
|
|
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
return indexModel.modifyCartProduct(uid, [{
|
|
|
return req.ctx(cartModel).modifyCartProduct(uid, [{
|
|
|
old_product_sku: oldProductSku,
|
|
|
new_product_sku: newProductSku,
|
|
|
buy_number: buyNumber,
|
...
|
...
|
@@ -370,7 +371,7 @@ const modifyPriceGift = (req, res, next) => { |
|
|
|
|
|
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
|
|
|
// uid = 20422448;
|
|
|
return indexModel.modifyCartPriceGiftProduct(uid, newProductSku,
|
|
|
return req.ctx(cartModel).modifyCartPriceGiftProduct(uid, newProductSku,
|
|
|
newProductSkn, promotionId, shoppingKey)
|
|
|
.then(data => {
|
|
|
data ? res.json(data) : res.status(400).json({
|
...
|
...
|
@@ -389,7 +390,7 @@ const gift = (req, res, next) => { |
|
|
if (!promotionIds) {
|
|
|
return next();
|
|
|
}
|
|
|
return indexModel.getPriceGiftList(promotionIds, 'Gift').then(data => {
|
|
|
return req.ctx(cartModel).getPriceGiftList(promotionIds, 'Gift').then(data => {
|
|
|
res.render('gift', Object.assign(data, {
|
|
|
title: '赠品',
|
|
|
module: 'cart',
|
...
|
...
|
@@ -420,7 +421,7 @@ const advanceBuy = (req, res, next) => { |
|
|
if (!promotionIds) {
|
|
|
return next();
|
|
|
}
|
|
|
return indexModel.getPriceGiftList(promotionIds, 'Needpaygift').then(data => {
|
|
|
return req.ctx(cartModel).getPriceGiftList(promotionIds, 'Needpaygift').then(data => {
|
|
|
res.render('gift', Object.assign(data, {
|
|
|
title: '加价购',
|
|
|
module: 'cart',
|
...
|
...
|
@@ -457,7 +458,7 @@ const giftinfo = (req, res, next) => { |
|
|
message: '参数错误'
|
|
|
});
|
|
|
}
|
|
|
return indexModel.giftProductData(skn, promotionId).then(data => {
|
|
|
return req.ctx(cartModel).giftProductData(skn, promotionId).then(data => {
|
|
|
data ? res.json({
|
|
|
promotionId: promotionId,
|
|
|
cartInfo: data
|
...
|
...
|
@@ -478,7 +479,7 @@ const incrBundle = (req, res, next) => { |
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = req.cookies._SPK || '';
|
|
|
|
|
|
return indexModel.incrBundle({
|
|
|
return req.ctx(cartModel).incrBundle({
|
|
|
uid: uid,
|
|
|
shopping_key: shoppingKey,
|
|
|
activity_id: req.body.activity_id,
|
...
|
...
|
@@ -499,7 +500,7 @@ const decrBundle = (req, res, next) => { |
|
|
let uid = req.user.uid;
|
|
|
let shoppingKey = req.cookies._SPK || '';
|
|
|
|
|
|
return indexModel.decrBundle({
|
|
|
return req.ctx(cartModel).decrBundle({
|
|
|
uid: uid,
|
|
|
shopping_key: shoppingKey,
|
|
|
activity_id: req.body.activity_id,
|
...
|
...
|
|