...
|
...
|
@@ -5,267 +5,10 @@ |
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
var Promise = require('bluebird');
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
|
|
|
// const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
|
|
|
// const sign = require(`${global.library}/sign`);
|
|
|
// const logger = require(`${global.library}/logger`);
|
|
|
// const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
// var api = new ServiceAPI();
|
|
|
|
|
|
// 获取预售商品
|
|
|
const getPreSaleProducts = () => {
|
|
|
return Promise.resolve({
|
|
|
preSalePros: [{
|
|
|
gender: '1',
|
|
|
tags: '[Object]',
|
|
|
status: 1,
|
|
|
smallSortId: 115,
|
|
|
vip1Price: 379.04999999999995,
|
|
|
isGlobal: 'N',
|
|
|
vip3Price: 351.12,
|
|
|
isOutlets: 2,
|
|
|
isDiscount: 'Y',
|
|
|
brandDomain: 'allenove',
|
|
|
isSpecial: 'N',
|
|
|
goodsList: '[Object]',
|
|
|
isAdvance: 'N',
|
|
|
productId: 286135,
|
|
|
vipDiscountType: 1,
|
|
|
salesNum: 0,
|
|
|
cnAlphabet: 'ALLENOVE95S11GeBenHaGen',
|
|
|
productSkn: 51160998,
|
|
|
shelveTime: 1455616165,
|
|
|
vip2Price: 359.1,
|
|
|
editTime: 1455616165,
|
|
|
isNew: 'N',
|
|
|
isLimited: 'N',
|
|
|
brandName: 'Alle nove',
|
|
|
maxSortId: 1,
|
|
|
productName: 'Alle nove 小方领长袖衬衫【哥本哈根】',
|
|
|
brandId: 1007,
|
|
|
defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
stockNumber: 29,
|
|
|
storageNum: 29,
|
|
|
isSoonSoldOut: false,
|
|
|
middleSortId: 12,
|
|
|
salesPrice: 399,
|
|
|
isPromotion: 101,
|
|
|
marketPrice: 1299,
|
|
|
vipPrice: 0,
|
|
|
id: 51160998,
|
|
|
thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/0279bf8ab67a6c962b08e37b3a13ce3401.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
url: 'http://www.yohobuy.com/product/pro_286135_367985/ALLENOVE95S11GeBenHaGen.html',
|
|
|
brandUrl: '//allenove.yohobuy.com',
|
|
|
orderNum: 1, // 购买数量
|
|
|
numIsValid: true, // 库存是否正常
|
|
|
isValid: true // 是否没有实效
|
|
|
}]
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 获取普通商品
|
|
|
const getNormalProducts = () => {
|
|
|
return Promise.resolve({
|
|
|
commonPros: [{ gender: '1',
|
|
|
tags: '[Object]',
|
|
|
status: 1,
|
|
|
smallSortId: 115,
|
|
|
vip1Price: 284.05,
|
|
|
isGlobal: 'N',
|
|
|
vip3Price: 263.12,
|
|
|
isOutlets: 2,
|
|
|
isDiscount: 'Y',
|
|
|
brandDomain: 'allenove',
|
|
|
isSpecial: 'N',
|
|
|
goodsList: [Object],
|
|
|
isAdvance: 'N',
|
|
|
productId: 286141,
|
|
|
vipDiscountType: 1,
|
|
|
salesNum: 0,
|
|
|
cnAlphabet: 'ALLENOVE95S14WeiYeNa',
|
|
|
productSkn: 51161001,
|
|
|
shelveTime: 1455616165,
|
|
|
vip2Price: 269.1,
|
|
|
editTime: 1455616165,
|
|
|
isNew: 'N',
|
|
|
isLimited: 'N',
|
|
|
brandName: 'Alle nove',
|
|
|
maxSortId: 1,
|
|
|
productName: 'Alle nove 翼型领长袖衬衫【维也纳】',
|
|
|
brandId: 1007,
|
|
|
defaultImages: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
stockNumber: 21,
|
|
|
storageNum: 21,
|
|
|
isSoonSoldOut: false,
|
|
|
middleSortId: 12,
|
|
|
salesPrice: 299,
|
|
|
isPromotion: 101,
|
|
|
marketPrice: 1299,
|
|
|
vipPrice: 0,
|
|
|
id: 51161001,
|
|
|
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/02/0128dc014524ccf208b4f6f7760c9b9cf2.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
url: 'http://www.yohobuy.com/product/pro_286141_367991/ALLENOVE95S14WeiYeNa.html',
|
|
|
brandUrl: '//allenove.yohobuy.com',
|
|
|
orderNum: 2, // 购买数量
|
|
|
numIsValid: true, // 库存是否正常
|
|
|
isValid: true, // 是否没有实效
|
|
|
selectColor: '蓝',
|
|
|
selectSize: 'M'
|
|
|
}, { gender: '1',
|
|
|
tags: '[Object]',
|
|
|
status: 1,
|
|
|
smallSortId: 115,
|
|
|
vip1Price: 379.04999999999995,
|
|
|
isGlobal: 'N',
|
|
|
vip3Price: 351.12,
|
|
|
isOutlets: 2,
|
|
|
isDiscount: 'Y',
|
|
|
brandDomain: 'allenove',
|
|
|
isSpecial: 'N',
|
|
|
goodsList: '[Object]',
|
|
|
isAdvance: 'N',
|
|
|
productId: 286143,
|
|
|
vipDiscountType: 1,
|
|
|
salesNum: 0,
|
|
|
cnAlphabet: 'ALLENOVE95S20BaSaiLuoNa',
|
|
|
productSkn: 51161002,
|
|
|
shelveTime: 1455616165,
|
|
|
vip2Price: 359.1,
|
|
|
editTime: 1455616165,
|
|
|
isNew: 'N',
|
|
|
isLimited: 'N',
|
|
|
brandName: 'Foobar',
|
|
|
maxSortId: 1,
|
|
|
productName: 'Foobar 纽扣领绅士长袖衬衫【巴塞罗那】',
|
|
|
brandId: 1007,
|
|
|
defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
stockNumber: 25,
|
|
|
storageNum: 25,
|
|
|
isSoonSoldOut: false,
|
|
|
middleSortId: 12,
|
|
|
salesPrice: 399,
|
|
|
isPromotion: 101,
|
|
|
marketPrice: 1299,
|
|
|
vipPrice: 0,
|
|
|
id: 51161002,
|
|
|
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/05/024f60a070ab61981c139684f147d41f17.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
url: 'http://www.yohobuy.com/product/pro_286143_367993/ALLENOVE95S20BaSaiLuoNa.html',
|
|
|
brandUrl: '//allenove.yohobuy.com',
|
|
|
orderNum: 1, // 购买数量
|
|
|
numIsValid: false, // 库存是否正常
|
|
|
isValid: true // 是否没有实效
|
|
|
},
|
|
|
{ gender: '1',
|
|
|
tags: [Object],
|
|
|
status: 1,
|
|
|
smallSortId: 115,
|
|
|
vip1Price: 379.04999999999995,
|
|
|
isGlobal: 'N',
|
|
|
vip3Price: 351.12,
|
|
|
isOutlets: 2,
|
|
|
isDiscount: 'Y',
|
|
|
brandDomain: 'allenove',
|
|
|
isSpecial: 'N',
|
|
|
goodsList: [Object],
|
|
|
isAdvance: 'N',
|
|
|
productId: 286169,
|
|
|
vipDiscountType: 1,
|
|
|
salesNum: 0,
|
|
|
cnAlphabet: 'ALLENOVE95S09BiSa',
|
|
|
productSkn: 51161015,
|
|
|
shelveTime: 1455616145,
|
|
|
vip2Price: 359.1,
|
|
|
editTime: 1455616145,
|
|
|
isNew: 'N',
|
|
|
isLimited: 'N',
|
|
|
brandName: 'Alle nove',
|
|
|
maxSortId: 1,
|
|
|
productName: 'Alle nove 高支牛津休闲长袖衬衫【比萨】',
|
|
|
brandId: 1007,
|
|
|
defaultImages: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
stockNumber: 27,
|
|
|
storageNum: 27,
|
|
|
isSoonSoldOut: false,
|
|
|
middleSortId: 12,
|
|
|
salesPrice: 399,
|
|
|
isPromotion: 101,
|
|
|
marketPrice: 1299,
|
|
|
vipPrice: 0,
|
|
|
id: 51161015,
|
|
|
thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/10/21/05/027f47db67ca5cdb9fa996c8300947b975.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
url: 'http://www.yohobuy.com/product/pro_286169_368019/ALLENOVE95S09BiSa.html',
|
|
|
brandUrl: '//allenove.yohobuy.com',
|
|
|
orderNum: 2, // 购买数量
|
|
|
numIsValid: true, // 库存是否正常
|
|
|
isValid: true // 是否没有实效
|
|
|
}]
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 获取失效商品
|
|
|
const getInvalidProducts = () => {
|
|
|
return Promise.resolve({
|
|
|
invalidPros: [{ gender: '1',
|
|
|
tags: ['Object'],
|
|
|
status: 1,
|
|
|
smallSortId: 115,
|
|
|
vip1Price: 379.04999999999995,
|
|
|
isGlobal: 'N',
|
|
|
vip3Price: 351.12,
|
|
|
isOutlets: 2,
|
|
|
isDiscount: 'Y',
|
|
|
brandDomain: 'allenove',
|
|
|
isSpecial: 'N',
|
|
|
goodsList: ['Object'],
|
|
|
isAdvance: 'N',
|
|
|
productId: 286139,
|
|
|
vipDiscountType: 1,
|
|
|
salesNum: 0,
|
|
|
cnAlphabet: 'ALLENOVE95S13PuLuoWangSi',
|
|
|
productSkn: 51161000,
|
|
|
shelveTime: 1455616165,
|
|
|
vip2Price: 359.1,
|
|
|
editTime: 1455616165,
|
|
|
isNew: 'N',
|
|
|
isLimited: 'N',
|
|
|
brandName: 'Alle nove',
|
|
|
maxSortId: 1,
|
|
|
productName: 'Alle nove 复古圆领长袖衬衫【普罗旺斯】',
|
|
|
brandId: 1007,
|
|
|
defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
stockNumber: 12,
|
|
|
storageNum: 12,
|
|
|
isSoonSoldOut: false,
|
|
|
middleSortId: 12,
|
|
|
salesPrice: 399,
|
|
|
isPromotion: 101,
|
|
|
marketPrice: 1299,
|
|
|
vipPrice: 0,
|
|
|
id: 51161000,
|
|
|
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
|
|
|
url: 'http://www.yohobuy.com/product/pro_286139_367989/ALLENOVE95S13PuLuoWangSi.html',
|
|
|
brandUrl: '//allenove.yohobuy.com',
|
|
|
orderNum: 1, // 购买数量
|
|
|
numIsValid: true, // 库存是否正常
|
|
|
isValid: false // 是否没有实效
|
|
|
}]
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 获取购物车信息
|
|
|
const getCartInfo = () => {
|
|
|
return Promise.all([
|
|
|
getPreSaleProducts(),
|
|
|
getNormalProducts(),
|
|
|
getInvalidProducts()
|
|
|
]);
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* 加入购物车
|
|
|
* @function addToCart
|
...
|
...
|
@@ -382,9 +125,143 @@ const transferToFavorite = (uid, sku, hasPromotion) => { |
|
|
return api.get('', params);
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* 商品选择与取消选择
|
|
|
* @function toggleSelectGoods
|
|
|
* @param { Number } uid 用户UID
|
|
|
* @param { String } sku 商品sku列表
|
|
|
* @param { String } shoppingKey 未登录用户唯一识别码,可以不传
|
|
|
* @return { Array }
|
|
|
*/
|
|
|
const toggleSelectGoods = (params) => {
|
|
|
// BLK 没有促销, 新接口
|
|
|
let method = 'app.Shopping.selectedAndCart';
|
|
|
|
|
|
_.merge(params, {method});
|
|
|
return api.get('', params);
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* 商品选择与取消选择
|
|
|
* @function toggleSelectGoods
|
|
|
* @param { Number } uid 用户UID
|
|
|
* @param { String } sku 商品sku列表
|
|
|
* @param { String } shoppingKey 未登录用户唯一识别码,可以不传
|
|
|
* @return { Array }
|
|
|
*/
|
|
|
const removeGoods = (params) => {
|
|
|
// BLK 没有促销, 新接口
|
|
|
let method = 'app.Shopping.removeAndCart';
|
|
|
|
|
|
_.merge(params, {method});
|
|
|
return api.get('', params);
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
* 每次操作处理购物车数据
|
|
|
* @function toggleSelectGoods
|
|
|
* @param { Object } result 购物车数据
|
|
|
* {
|
|
|
* advance_cart_data: { // 预售商品
|
|
|
* gift_list: [], // 赠品
|
|
|
* goods_list: [] // 商品列表
|
|
|
* off_shelves_goods_list: [], // 下架商品, 失效商品
|
|
|
* price_gift: [], // 加价购商品
|
|
|
* promotion_info: [], // 促销信息
|
|
|
* shopping_cart_data: [], // 商品价格计算相关信息
|
|
|
* sold_out_goods_list: [] // 售罄商品
|
|
|
* },
|
|
|
* ordinary_cart_data: { // 普通商品
|
|
|
* gift_list: [],
|
|
|
* goods_list: [],
|
|
|
* off_shelves_goods_list: [],
|
|
|
* price_gift: [],
|
|
|
* promotion_info: [],
|
|
|
* shopping_cart_data: [],
|
|
|
* sold_out_goods_list: []
|
|
|
* },
|
|
|
* md5: '...',
|
|
|
* message: '...'
|
|
|
* }
|
|
|
*/
|
|
|
const filterCartData = (result, uid) => {
|
|
|
// 预售商品
|
|
|
let advancedGoods = [],
|
|
|
selectedAdvanceNum = 0,
|
|
|
advancedCartData;
|
|
|
|
|
|
// 普通商品
|
|
|
let ordinaryGoods = [],
|
|
|
selectedOrdinaryNum = 0,
|
|
|
ordinaryCartData;
|
|
|
|
|
|
// skn=0或者已下架的商品,定义为失效商品
|
|
|
let invalidGoods = [];
|
|
|
|
|
|
// 库存不足商品
|
|
|
let soldOutGoods = [];
|
|
|
|
|
|
// 商品总数量
|
|
|
let buyNumber;
|
|
|
let totalNum = 0;
|
|
|
|
|
|
// 返回值
|
|
|
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);
|
|
|
advancedGoods = _.concat(advancedGoods, advancedCartData.goods_list);
|
|
|
invalidGoods = _.concat(invalidGoods, advancedCartData.off_shelves_goods_list);
|
|
|
soldOutGoods = _.concat(soldOutGoods, advancedCartData.sold_out_goods_list);
|
|
|
|
|
|
_.forEach(advancedGoods, function(good){
|
|
|
buyNumber = parseInt(good.buy_number, 10);
|
|
|
totalNum += buyNumber;
|
|
|
if (good.selected === 'Y') {
|
|
|
selectedAdvanceNum += buyNumber;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (result.data && result.data.ordinary_cart_data) {
|
|
|
// 普通商品
|
|
|
ordinaryCartData = result.data.ordinary_cart_data;
|
|
|
console.log('---------------ordinary------:', ordinaryCartData.goods_list.length);
|
|
|
ordinaryGoods = _.concat(ordinaryGoods, ordinaryCartData.goods_list);
|
|
|
invalidGoods = _.concat(invalidGoods, ordinaryCartData.off_shelves_goods_list);
|
|
|
soldOutGoods = _.concat(soldOutGoods, ordinaryCartData.sold_out_goods_list);
|
|
|
|
|
|
_.forEach(ordinaryGoods, function(good){
|
|
|
buyNumber = parseInt(good.buy_number, 10);
|
|
|
totalNum += buyNumber;
|
|
|
if (good.selected === 'Y') {
|
|
|
selectedOrdinaryNum += buyNumber;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// console.log('ordinaryGoods:', ordinaryGoods);
|
|
|
|
|
|
|
|
|
return _.merge(resData, {
|
|
|
hasGoods: advancedGoods.length || ordinaryGoods.length || invalidGoods.length,
|
|
|
preSalePros: advancedGoods.length ? _.groupBy(advancedGoods, 'brand_id') : [],
|
|
|
commonPros: ordinaryGoods.length ? _.groupBy(ordinaryGoods, 'brand_id') : [],
|
|
|
invalidPros: invalidGoods,
|
|
|
selectedNum: selectedAdvanceNum + selectedOrdinaryNum,
|
|
|
checkAll: totalNum === (selectedAdvanceNum + selectedOrdinaryNum)
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
addToCart,
|
|
|
getCartData,
|
|
|
getCartInfo,
|
|
|
transferToFavorite
|
|
|
transferToFavorite,
|
|
|
toggleSelectGoods,
|
|
|
removeGoods,
|
|
|
filterCartData
|
|
|
}; |
...
|
...
|
|