Authored by 周少峰

Merge branch 'master' into feature/web-apm

Conflicts:
	package.json
... ... @@ -22,7 +22,7 @@ const stepper = [
const getProductInfo = (req, res, next) => {
let pid = req.query.productId || '';
service.getProductInfoAsync(pid).then((result) => {
req.ctx(service).getProductInfoAsync(pid).then(result => {
return res.render('goods-detail', Object.assign({
layout: false
}, result));
... ... @@ -38,14 +38,14 @@ const getProductInfo = (req, res, next) => {
const getProductData = (req, res, next) => {
let pid = req.query.productId || '';
service.getProductInfoAsync(pid).then((result) => {
req.ctx(service).getProductInfoAsync(pid).then(result => {
return res.send(result);
}).catch(next);
};
// 获取优惠券列表
const getCoupons = (req, res, next) => {
service.getCoupons(req.user.uid).then(data => {
req.ctx(service).getCoupons(req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
... ... @@ -58,7 +58,7 @@ const setShoppingCookie = (req, res) => {
let uid = req.user.uid;
let shoppingKey = helper.getShoppingKeyByCookie(req);
return service.getCartCount(uid, shoppingKey).then(ret => {
return req.ctx(service).getCartCount(uid, shoppingKey).then(ret => {
if (ret && ret.data && ret.data.cart_goods_count) {
res.cookie('_g', JSON.stringify({
... ... @@ -85,7 +85,7 @@ const miniCart = (req, res, next) => {
let uid = req.user.uid;
let shoppingKey = helper.getShoppingKeyByCookie(req);
service.getMiniCartData(uid, shoppingKey).then(ret => {
req.ctx(service).getMiniCartData(uid, shoppingKey).then(ret => {
let dest = {
code: 200,
message: 'shoppingCart',
... ... @@ -114,7 +114,7 @@ const delCartGoods = (req, res, next) => {
skuList[productSku] = parseInt(buyNumber); //eslint-disable-line
service.removeFromCart(uid, shoppingKey, JSON.stringify(skuList))
req.ctx(service).removeFromCart(uid, shoppingKey, JSON.stringify(skuList))
.then(ret => {
if (ret && ret.code === 200 && _.has(ret, 'data.goods_count')) {
ret.data.total_goods_num = ret.data.goods_count;
... ... @@ -148,7 +148,7 @@ const cartAddIndex = (req, res, next) => {
let isEdit = req.body.isEdit || 0;
// 执行加入购物车操作
let result = yield service.addCart(productSku, buyNumber,
let result = yield req.ctx(service).addCart(productSku, buyNumber,
goodsType, isEdit, promotionId,
uid, shoppingKey);
... ... @@ -193,6 +193,7 @@ const cart = (req, res, next) => {
if (isNewCart) {
return res.redirect(yohoHelpers.urlFormat('/shopping/cart'));
}
if (cartDelList) {
res.cookie('cart-del-list', '', {
domain: '.yohobuy.com',
... ... @@ -200,7 +201,7 @@ const cart = (req, res, next) => {
});
}
service.getCartData(uid, shoppingKey)
req.ctx(service).getCartData(uid, shoppingKey)
.then(ret => {
return res.render('cart', {
... ... @@ -232,7 +233,7 @@ const cartAdd = (req, res) => {
let isReAdd = !!req.body.isReAdd || false;
let cartDelList = helper.getCartDelList(req, res, null, isReAdd ? productSku : null);
let result = yield service.addToCart(productSku, buyNumber,
let result = yield req.ctx(service).addToCart(productSku, buyNumber,
goodsType, isEdit, promotionId,
uid, shoppingKey, cartDelList);
... ... @@ -262,7 +263,7 @@ const cartTotal = (req, res) => {
let uid = req.user.uid;
let shoppingKey = helper.getShoppingKeyByCookie(req);
let callback = req.query.callback;
let ret = yield service.getCartCount(uid, shoppingKey);
let ret = yield req.ctx(service).getCartCount(uid, shoppingKey);
return res.send(callback + '(' + JSON.stringify(ret) + ')');
})();
... ... @@ -279,7 +280,7 @@ const selectProduct = (req, res, next) => {
let shoppingKey = helper.getShoppingKeyByCookie(req);
let cartDelList = helper.getCartDelList(req, res);
service.selectGoods(uid, productId, shoppingKey, hasPromotion, cartDelList)
req.ctx(service).selectGoods(uid, productId, shoppingKey, hasPromotion, cartDelList)
.then(ret => {
res.send(ret);
}).catch(next);
... ... @@ -300,7 +301,7 @@ const modifyProductNum = (req, res, next) => {
let activityId = req.body.activity_id || null;
if (activityId) {
return service.bundleNumData({
return req.ctx(service).bundleNumData({
uid: uid,
batch_no: batchNo,
activity_id: activityId,
... ... @@ -322,7 +323,7 @@ const modifyProductNum = (req, res, next) => {
.catch(next);
}
return service.modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey, cartDelList)
return req.ctx(service).modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey, cartDelList)
.then(ret => {
if (ret && ret.code === 200) {
return setShoppingCookie(req, res).then(() => {
... ... @@ -350,7 +351,7 @@ const removeProduct = (req, res) => {
let hasPromotion = true;
let cartDelList = helper.getCartDelList(req, res, req.body.cartDelList);
let ret = yield service.removeFromCart(uid, shoppingKey, skuList, hasPromotion, cartDelList);
let ret = yield req.ctx(service).removeFromCart(uid, shoppingKey, skuList, hasPromotion, cartDelList);
if (ret && ret.code === 200) {
yield setShoppingCookie(req, res);
... ... @@ -388,7 +389,7 @@ const moveToFav = (req, res) => {
}
cartDelList = helper.getCartDelList(req, res, null, productSku);
ret = yield service.addToFav(uid, skuList, hasPromotion, cartDelList);
ret = yield req.ctx(service).addToFav(uid, skuList, hasPromotion, cartDelList);
if (ret && ret.code === 200) {
yield setShoppingCookie(req, res);
... ... @@ -416,7 +417,7 @@ const checkFav = (req, res) => {
let pids = req.body.pidList.split(',');
Object.assign(ret, {code: 200,
data: yield service.checkUserIsFav(uid, pids)});
data: yield req.ctx(service).checkUserIsFav(uid, pids)});
}
return res.send(ret);
... ... @@ -431,7 +432,7 @@ const getTogetherProduct = (req, res) => {
co(function * () {
let page = req.query.page;
let ret = yield service.getTogetherProduct(page);
let ret = yield req.ctx(service).getTogetherProduct(page);
return res.send(ret);
})();
... ... @@ -454,7 +455,7 @@ const getRecommendProductAction = (req, res) => {
page = 1;
}
ret = yield service.getRecommendProduct(channelNum, uid, udid, page);
ret = yield req.ctx(service).getRecommendProduct(channelNum, uid, udid, page);
res.send(ret);
})();
};
... ... @@ -467,7 +468,7 @@ const getIncreasePurchase = (req, res) => {
co(function * () {
let page = req.query.page;
let ret = yield service.getTogetherProduct(page);
let ret = yield req.ctx(service).getTogetherProduct(page);
return res.send(ret);
});
... ... @@ -484,7 +485,7 @@ const modifyProduct = (req, res, next) => {
// swapData => [{"buy_number":"1","selected":"Y","new_product_sku":"735172","old_product_sku":"735171"}]
const swapData = req.body.swapData;
service.modifyProduct({swapData, shoppingKey, uid}, uid, shoppingKey, cartDelList).then((result) => {
req.ctx(service).modifyProduct({swapData, shoppingKey, uid}, uid, shoppingKey, cartDelList).then((result) => {
res.send(result);
}).catch(next);
};
... ... @@ -505,7 +506,7 @@ const swapGift = (req, res, next) => {
let newSku = req.body.newSku;
let cartDelList = helper.getCartDelList(req, res);
service.swapGift(uid, shoppingKey, promotionId, newSkn, newSku, cartDelList)
req.ctx(service).swapGift(uid, shoppingKey, promotionId, newSkn, newSku, cartDelList)
.then(ret => {
res.send(ret);
}).catch(next);
... ... @@ -524,7 +525,7 @@ const queryUserPromotionGift = (req, res, next) => {
let shoppingKey = helper.getShoppingKeyByCookie(req);
let promotionId = req.query.promotionId;
service.queryUserPromotionGift(promotionId, uid, shoppingKey)
req.ctx(service).queryUserPromotionGift(promotionId, uid, shoppingKey)
.then(ret => {
res.send(ret);
}).catch(next);
... ... @@ -554,7 +555,7 @@ const addBundle = (req, res, next) => {
params.uid = uid;
}
service.addBundleData(params).then(result => {
req.ctx(service).addBundleData(params).then(result => {
// 设置加入购物车凭证到客户端浏览器
if (!shoppingKey && _.get(result, 'data.shopping_key')) {
... ...
... ... @@ -5,417 +5,403 @@
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
/**
* [套餐添加购物车]
* @param {[type]} params [description]
* @return {[type]} [description]
*/
const addBundle = (params) => {
return api.get('', Object.assign({
method: 'app.Shopping.addBundle'
}, params), {code: 200});
};
/**
* [套餐增减购物车]
* @param {[type]} params [description | order:1-incr, order:0-decr]
* @return {[type]} [description]
*/
const bundleNum = (params) => {
// 增加
if (params.increaseNum) {
params.method = 'app.Shopping.incrBundle';
params.increase_number = parseInt(params.increaseNum, 10);
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 减少
if (params.decreaseNum) {
params.method = 'app.Shopping.decrBundle';
params.decrease_number = parseInt(params.decreaseNum, 10);
/**
* [套餐添加购物车]
* @param {[type]} params [description]
* @return {[type]} [description]
*/
addBundle(params) {
params = Object.assign({
method: 'app.Shopping.addBundle'
}, params);
return this.get({data: params});
}
delete params.increaseNum;
delete params.decreaseNum;
return api.get('', params, {code: 200});
};
/**
* 获取购物车数据
* @param uid
* @param shoppingKey
* @returns {*}
*/
const cartData = (uid, shoppingKey) => {
let param = {
is_support_mlp: 'Y',
method: 'app.Shopping.queryCart' // old: 'app.Shopping.cart'
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return api.get('', param);
};
/**
* 加入购物车接口
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 未登录用户唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
const addToCart = (productSku, buyNumber,
goodsType, isEdit,
promotionId, uid, shoppingKey) => {
let param = {
method: 'app.Shopping.add',
product_sku: productSku,
buy_number: Number(buyNumber),
goods_type: goodsType,
edit_product_sku: isEdit || 0,
selected: 'Y',
promotion_id: promotionId || null
};
if (uid) {
param.uid = uid;
/**
* [套餐增减购物车]
* @param {[type]} params [description | order:1-incr, order:0-decr]
* @return {[type]} [description]
*/
bundleNum(params) {
// 增加
if (params.increaseNum) {
params.method = 'app.Shopping.incrBundle';
params.increase_number = parseInt(params.increaseNum, 10);
}
// 减少
if (params.decreaseNum) {
params.method = 'app.Shopping.decrBundle';
params.decrease_number = parseInt(params.decreaseNum, 10);
}
delete params.increaseNum;
delete params.decreaseNum;
return this.get({data: params});
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
/**
* 获取购物车数据
* @param uid
* @param shoppingKey
* @returns {*}
*/
cartData(uid, shoppingKey) {
return api.get('', param);
};
let param = {
is_support_mlp: 'Y',
method: 'app.Shopping.queryCart' // old: 'app.Shopping.cart'
};
/**
* 购物车商品选择与取消接口
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 购物车接口返回的数据
*/
const selectGoods = (uid, sku, shoppingKey /* , hasPromotion*/) => {
if (uid) {
param.uid = uid;
}
let param = {
// method: hasPromotion ? 'app.Shopping.selectedAndCart' : 'app.Shopping.selected',
is_support_mlp: 'Y',
method: 'app.Shopping.selectedAndQryCart',
product_sku_list: sku
};
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
if (uid) {
param.uid = uid;
return this.get({data: param});
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
/**
* 加入购物车接口
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 未登录用户唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey) {
let param = {
method: 'app.Shopping.add',
product_sku: productSku,
buy_number: Number(buyNumber),
goods_type: goodsType,
edit_product_sku: isEdit || 0,
selected: 'Y',
promotion_id: promotionId || null
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return this.get({data: param});
}
return api.get('', param);
};
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
const removeFromCart = (uid, shoppingKey, skuList, hasPromotion) =>{
/**
* 购物车商品选择与取消接口
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 购物车接口返回的数据
*/
selectGoods(uid, sku, shoppingKey /* , hasPromotion*/) {
let param = {
// method: hasPromotion ? 'app.Shopping.selectedAndCart' : 'app.Shopping.selected',
is_support_mlp: 'Y',
method: 'app.Shopping.selectedAndQryCart',
product_sku_list: sku
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return this.get({data: param});
}
let param = {
method: 'app.Shopping.remove',
product_sku_list: skuList
};
if (hasPromotion) {
param.method = 'app.Shopping.removeAndQryCart';
param.is_support_mlp = 'Y';
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
removeFromCart(uid, shoppingKey, skuList, hasPromotion) {
let param = {
method: 'app.Shopping.remove',
product_sku_list: skuList
};
if (hasPromotion) {
param.method = 'app.Shopping.removeAndQryCart';
param.is_support_mlp = 'Y';
}
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return this.get({data: param});
}
if (uid) {
param.uid = uid;
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
addToFav(uid, skuList /* , hasPromotion*/) {
let param = {
// method: hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite',
is_support_mlp: 'Y',
method: 'app.Shopping.addfavoriteAndQryCart',
product_sku_list: skuList,
uid: uid
};
return this.get({data: param});
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
/**
* 增减购物车商品数量
*
* @param int $uid 用户ID
* @param string $sku 商品SKU
* @param int $increaseNum 增加的数目
* @param int $decreaseNum 减少的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey) {
let param = {
product_sku: sku
};
// 增加
if (increaseNum) {
param.method = 'app.Shopping.increase';
param.increase_number = Number(increaseNum);
}
// 减少
if (decreaseNum) {
param.method = 'app.Shopping.decrease';
param.decrease_number = Number(decreaseNum);
}
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return this.get({data: param});
}
return api.get('', param);
};
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param bool $hasPromotion 是否有促销ID
* @return array 接口返回的数据
*/
const addToFav = (uid, skuList /* , hasPromotion*/) =>{
let param = {
// method: hasPromotion ? 'app.Shopping.addfavoriteAndCart' : 'app.Shopping.addfavorite',
is_support_mlp: 'Y',
method: 'app.Shopping.addfavoriteAndQryCart',
product_sku_list: skuList,
uid: uid
};
return api.get('', param);
};
/**
* 购物车数量
*
* @param int $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
cartCount(uid, shoppingKey) {
/**
* 增减购物车商品数量
*
* @param int $uid 用户ID
* @param string $sku 商品SKU
* @param int $increaseNum 增加的数目
* @param int $decreaseNum 减少的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
const modifyProductNum = (uid, sku, increaseNum, decreaseNum, shoppingKey) => {
let param = {
method: 'app.Shopping.count'
};
let param = {
product_sku: sku
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
// 增加
if (increaseNum) {
param.method = 'app.Shopping.increase';
param.increase_number = Number(increaseNum);
return this.get({data: param});
}
// 减少
if (decreaseNum) {
param.method = 'app.Shopping.decrease';
param.decrease_number = Number(decreaseNum);
/**
* 凑单商品
*
* @param int $page 分页页码
* @return array
*/
togetherProduct(page) {
let param = {
method: 'web.product.together',
client_type: 'web',
page: page
};
return this.get({data: param});
}
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return api.get('', param);
};
/**
* 购物车数量
*
* @param int $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
const cartCount = (uid, shoppingKey) => {
let param = {
method: 'app.Shopping.count'
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return api.get('', param);
};
/**
* 凑单商品
*
* @param int $page 分页页码
* @return array
*/
const togetherProduct = (page) => {
let param = {
method: 'web.product.together',
client_type: 'web',
// private_key: Yohobuy::$privateKeyList['web'];
page: page
};
return api.get('', param);
};
/**
* 判断商品列表是否收藏情况
* @param uid
* @param pidList
* @returns {Promise.<T>}
*/
const checkUserIsFavProductList = (uid, pidList) => {
pidList = _.isArray(pidList) ? pidList : [];
let promises = _.map(pidList, pid => {
return api.get('', {
method: 'app.favorite.isFavorite',
id: pid,
uid: uid,
type: 'product'
/**
* 判断商品列表是否收藏情况
* @param uid
* @param pidList
* @returns {Promise.<T>}
*/
checkUserIsFavProductList(uid, pidList) {
pidList = _.isArray(pidList) ? pidList : [];
let promises = _.map(pidList, pid => {
return this.get({data: {
method: 'app.favorite.isFavorite',
id: pid,
uid: uid,
type: 'product'
}});
});
});
return Promise.all(promises)
.then(ret => {
return Promise.all(promises)
.then(ret => {
let result = {};
let result = {};
_.forEach(pidList, (pid, index) => {
result[pid] = ret[index];
});
return result;
});
};
_.forEach(pidList, (pid, index) => {
result[pid] = ret[index];
});
/**
* 个人中心页面优选新品数据
*
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
* @param $uid 用户ID
* @param $udid 设备ID
* @param $rec_pos 位置码
* @param $limit 数量限制
* @return array 接口返回的数据
*/
const newPreference = (channel, uid, udid, recPos, limit) => {
let param = {
method: 'app.home.newPreference',
yh_channel: channel,
udid: udid,
rec_pos: recPos,
limit: limit
};
if (uid) {
param.uid = uid;
return result;
});
}
return api.get('', param);
};
/**
* 修改商品颜色和尺寸
* @function modifyProduct
* @param { Number } uid 用户ID
* @param { String } swapData 商品修改信息
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Object } 接口返回单个商品修改结果
*/
const modifyProduct = (options) => {
let params = {
method: 'app.Shopping.swap'
};
_.merge(params, {
swap_data: options.swapData
});
if (options.uid) {
_.merge(params, {
uid: options.uid
});
/**
* 个人中心页面优选新品数据
*
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
* @param $uid 用户ID
* @param $udid 设备ID
* @param $rec_pos 位置码
* @param $limit 数量限制
* @return array 接口返回的数据
*/
newPreference(channel, uid, udid, recPos, limit) {
let param = {
method: 'app.home.newPreference',
yh_channel: channel,
udid: udid,
rec_pos: recPos,
limit: limit
};
if (uid) {
param.uid = uid;
}
return this.get({data: param});
}
if (options.shoppingKey) {
/**
* 修改商品颜色和尺寸
* @function modifyProduct
* @param { Number } uid 用户ID
* @param { String } swapData 商品修改信息
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Object } 接口返回单个商品修改结果
*/
modifyProduct(options) {
let params = {
method: 'app.Shopping.swap'
};
_.merge(params, {
shopping_key: options.shoppingKey
swap_data: options.swapData
});
}
return api.get('', params);
};
/**
* 更换加价购,赠品商品
* @function modifyProduct
* @param { Number } uid 用户ID
* @param { String } swapData 商品修改信息
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Object } 接口返回单个商品修改结果
*/
const swapGift = (uid, shoppingKey, promotionId, newSkn, newSku) => {
if (options.uid) {
_.merge(params, {
uid: options.uid
});
}
let param = {
method: 'app.Shopping.swapGift',
promotion_id: promotionId,
new_product_skn: newSkn,
new_product_sku: newSku
};
if (options.shoppingKey) {
_.merge(params, {
shopping_key: options.shoppingKey
});
}
if (uid) {
param.uid = uid;
return this.get({data: params});
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
/**
* 更换加价购,赠品商品
* @function modifyProduct
* @param { Number } uid 用户ID
* @param { String } swapData 商品修改信息
* @param { String } shoppingKey 未登录用户唯一识别码
* @return { Object } 接口返回单个商品修改结果
*/
swapGift(uid, shoppingKey, promotionId, newSkn, newSku) {
let param = {
method: 'app.Shopping.swapGift',
promotion_id: promotionId,
new_product_skn: newSkn,
new_product_sku: newSku
};
if (uid) {
param.uid = uid;
}
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return this.get({data: param});
}
return api.get('', param);
};
/**
* 查询所有可选的赠品或者加价购活动下的商品
* @param promotionId array
* @returns {*}
*/
const queryPromotionGift = (promotionIds) => {
let param = {
method: 'app.Shopping.queryPromotionGifts',
promotion_ids: promotionIds
};
return api.get('', param);
};
module.exports = {
addBundle,
bundleNum,
cartData,
addToCart,
selectGoods,
removeFromCart,
addToFav,
modifyProductNum,
cartCount,
togetherProduct,
checkUserIsFavProductList,
newPreference,
modifyProduct,
swapGift,
queryPromotionGift
/**
* 查询所有可选的赠品或者加价购活动下的商品
* @param promotionId array
* @returns {*}
*/
queryPromotionGift(promotionIds) {
let param = {
method: 'app.Shopping.queryPromotionGifts',
promotion_ids: promotionIds
};
return this.get({data: param});
}
};
... ...
... ... @@ -9,1099 +9,1072 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
// const md5 = require('md5');
const ERROR_400_MESSAGE = '系统繁忙,请稍候再试!';
const productAPI = require('./product-api');
const cartApi = require('./cart-api');
const ProductAPI = require('./product-api');
const CartApi = require('./cart-api');
const chelper = require('./cart-helper');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 转换价格
*
* @param float|string $price 价格
* @return float|string 转换之后的价格
*/
const transPrice = (price) => {
return price ? (price * 1).toFixed(2) : '0.00';
};
const _getProductIntroAsync = (productSkn) => {
return co(function * () {
let result = yield Promise.props({
sizeInfo: productAPI.sizeInfoAsync(productSkn)
});
return result;
})();
};
_getProductIntroAsync(productSkn) {
let that = this;
/**
* 获得sku商品数据
*/
const _getSkuDataByProductBaseInfo = (data) => {
let totalStorageNum = 0;
let skuGoods = null;// sku商品
let defaultImage = '';// 默认图
let chooseSkuFlag = false; // 选中状态
return co(function * () {
let result = yield Promise.props({
sizeInfo: new ProductAPI(that.ctx).sizeInfoAsync(productSkn)
});
if (_.isEmpty(_.get(data, 'goods_list', []))) {
return {
totalStorageNum,
skuGoods,
defaultImage
};
return result;
})();
}
skuGoods = _.get(data, 'goods_list', []).reduce((acc, cur, pos)=> {
// 如果status为0,即skc下架时就跳过该商品$value['status'] === 0
let goodsGroup = {};
/**
* 获得sku商品数据
*/
_getSkuDataByProductBaseInfo(data) {
let totalStorageNum = 0;
let skuGoods = null;// sku商品
let defaultImage = '';// 默认图
let chooseSkuFlag = false; // 选中状态
if (_.isEmpty(cur.color_image)) {
return acc;
}
if (cur.images_list) {
// 商品列表
goodsGroup.productSkc = cur.product_skc;
goodsGroup.src = helpers.image(cur.color_image, 25, 35);
goodsGroup.title = `${_.trim(data.product_name)} ${cur.color_name}`;
goodsGroup.name = cur.factory_goods_name;
goodsGroup.focus = false;
goodsGroup.total = 0;
goodsGroup.thumbs = [];
goodsGroup.size = [];
if (_.isEmpty(_.get(data, 'goods_list', []))) {
return {
totalStorageNum,
skuGoods,
defaultImage
};
}
_.get(cur, 'images_list', []).forEach((good) => {
if (good.image_url) {
goodsGroup.thumbs.push({
url: '',
shower: helpers.image(good.image_url, 420, 560),
img: helpers.image(good.image_url, 75, 100)
});
}
});
skuGoods = _.get(data, 'goods_list', []).reduce((acc, cur, pos)=> {
// 缩略图空,不显示
if (_.isEmpty(goodsGroup.thumbs)) {
return acc;
}
// 如果status为0,即skc下架时就跳过该商品$value['status'] === 0
let goodsGroup = {};
// 默认第一张图片
if (pos === 0) {
defaultImage = helpers.image(cur.color_image, 420, 560);
}
// 商品的尺码列表
_.get(cur, 'size_list', []).forEach((size) => {
if (data.attribute === 3) {
// 虚拟商品,门票默认最大为4,
size.storage_number = size.storage_number > 4 ? 4 : size.storage_number;
if (_.isEmpty(cur.color_image)) {
return acc;
}
// 如果status为0,即skc下架时就跳过该商品
if (cur.status === 0) {
size.storage_number = 0;
if (cur.images_list) {
// 商品列表
goodsGroup.productSkc = cur.product_skc;
goodsGroup.src = helpers.image(cur.color_image, 25, 35);
goodsGroup.title = `${_.trim(data.product_name)} ${cur.color_name}`;
goodsGroup.name = cur.factory_goods_name;
goodsGroup.focus = false;
goodsGroup.total = 0;
goodsGroup.thumbs = [];
goodsGroup.size = [];
}
goodsGroup.size.push({
name: size.size_name,
sku: size.product_sku,
num: _.parseInt(size.storage_number),
goodsId: size.size_id
_.get(cur, 'images_list', []).forEach((good) => {
if (good.image_url) {
goodsGroup.thumbs.push({
url: '',
shower: helpers.image(good.image_url, 420, 560),
img: helpers.image(good.image_url, 75, 100)
});
}
});
// 单个sku商品的总数
goodsGroup.total += _.parseInt(size.storage_number);
// 缩略图空,不显示
if (_.isEmpty(goodsGroup.thumbs)) {
return acc;
}
if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品
goodsGroup.focus = true;
chooseSkuFlag = true;// 选中sku商品
// 默认第一张图片
if (pos === 0) {
defaultImage = helpers.image(cur.color_image, 420, 560);
}
totalStorageNum += _.parseInt(size.storage_number);
// 商品的尺码列表
_.get(cur, 'size_list', []).forEach((size) => {
if (data.attribute === 3) {
// 虚拟商品,门票默认最大为4,
size.storage_number = size.storage_number > 4 ? 4 : size.storage_number;
}
});
// 如果status为0,即skc下架时就跳过该商品
if (cur.status === 0) {
size.storage_number = 0;
}
acc.push(goodsGroup);
return acc;
}, []);
goodsGroup.size.push({
name: size.size_name,
sku: size.product_sku,
num: _.parseInt(size.storage_number),
goodsId: size.size_id
});
if (!_.isEmpty(skuGoods) && !chooseSkuFlag) { // 没有选中一个sku商品,默认选中第一个sku商品
_.head(skuGoods).focus = true;
}
// 单个sku商品的总数
goodsGroup.total += _.parseInt(size.storage_number);
return {
defaultImage: defaultImage,
skuGoods: skuGoods,
totalStorageNum: totalStorageNum
};
};
if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品
goodsGroup.focus = true;
chooseSkuFlag = true;// 选中sku商品
}
/**
* 使sizeBoList id以 sizeAttributeBos id顺序一样
* @param sizeInfoBo
*/
const _sizeInfoBoSort = (sizeInfoBo) => {
if (!sizeInfoBo.sizeBoList || !sizeInfoBo.sizeAttributeBos) {
return {};
}
totalStorageNum += _.parseInt(size.storage_number);
_.get(sizeInfoBo, 'sizeBoList', []).forEach((sizeBoList, sizek)=> {
let sortAttr = {};
});
sizeBoList.sortAttributes.forEach(sortAttributes => {
sortAttr[sortAttributes.id] = sortAttributes;
});
acc.push(goodsGroup);
return acc;
}, []);
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
});
if (!_.isEmpty(skuGoods) && !chooseSkuFlag) { // 没有选中一个sku商品,默认选中第一个sku商品
_.head(skuGoods).focus = true;
}
_.get(sizeInfoBo, 'sizeBoList', []).forEach((sizeBoList, sizek)=> {
let sortAttr = [];
return {
defaultImage: defaultImage,
skuGoods: skuGoods,
totalStorageNum: totalStorageNum
};
}
sizeInfoBo.sizeAttributeBos.forEach(val => {
if (sizeBoList.sortAttributes[val.id]) {
sortAttr.push(sizeBoList.sortAttributes[val.id]);
}
});
/**
* 使sizeBoList id以 sizeAttributeBos id顺序一样
* @param sizeInfoBo
*/
_sizeInfoBoSort(sizeInfoBo) {
if (!sizeInfoBo.sizeBoList || !sizeInfoBo.sizeAttributeBos) {
return {};
}
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
_.get(sizeInfoBo, 'sizeBoList', []).forEach((sizeBoList, sizek)=> {
let sortAttr = {};
});
sizeBoList.sortAttributes.forEach(sortAttributes => {
sortAttr[sortAttributes.id] = sortAttributes;
});
return sizeInfoBo;
};
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
});
/**
* 获取尺寸信息
* @param sizeInfo
* @returns {{}}
*/
const _getSizeData = (sizeInfo) => {
_.get(sizeInfoBo, 'sizeBoList', []).forEach((sizeBoList, sizek)=> {
let sortAttr = [];
// 尺码信息
if (!_.has(sizeInfo, 'sizeInfoBo')) {
return {};
}
sizeInfoBo.sizeAttributeBos.forEach(val => {
if (sizeBoList.sortAttributes[val.id]) {
sortAttr.push(sizeBoList.sortAttributes[val.id]);
}
});
sizeInfo.sizeInfoBo = _sizeInfoBoSort(sizeInfo.sizeInfoBo);
let boyReference = _.get(sizeInfo, 'productExtra.boyReference', false);
let girlReference = _.get(sizeInfo, 'productExtra.girlReference', false);
let gender = _.get(sizeInfo, 'productDescBo.gender', 3);
let referenceName = (function() {
if (gender === 3 && boyReference) {
return '参考尺码(男)';
} else if (gender === 3 && girlReference) {
return '参考尺码(女)';
} else {
return '参考尺码';
}
}());
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
// 判断是否显示参考尺码
let showReference = (boyReference && _.get(sizeInfo, 'sizeInfoBo.sizeBoList[0].boyReferSize', false)) ||
(girlReference && _.get(sizeInfo, 'sizeInfoBo.sizeBoList[0].girlReferSize', false));
});
if (!_.has(sizeInfo, 'sizeInfoBo.sizeAttributeBos')) {
return {};
return sizeInfoBo;
}
// 尺码信息头部
let size = {
thead: [{name: '吊牌尺码', id: ''}],
tbody: []
};
/**
* 获取尺寸信息
* @param sizeInfo
* @returns {{}}
*/
_getSizeData(sizeInfo) {
// 显示参考尺码
if (showReference) {
size.thead[1] = {name: referenceName, id: ''};
}
// 尺码信息
if (!_.has(sizeInfo, 'sizeInfoBo')) {
return {};
}
_.get(sizeInfo, 'sizeInfoBo.sizeAttributeBos', []).forEach((value) => {
size.thead.push({
name: value.attributeName || ' ',
id: value.id
});
});
sizeInfo.sizeInfoBo = this._sizeInfoBoSort(sizeInfo.sizeInfoBo);
let boyReference = _.get(sizeInfo, 'productExtra.boyReference', false);
let girlReference = _.get(sizeInfo, 'productExtra.girlReference', false);
let gender = _.get(sizeInfo, 'productDescBo.gender', 3);
let referenceName = (function() {
if (gender === 3 && boyReference) {
return '参考尺码(男)';
} else if (gender === 3 && girlReference) {
return '参考尺码(女)';
} else {
return '参考尺码';
}
}());
_.get(sizeInfo, 'sizeInfoBo.sizeBoList', []).forEach((value) => {
let sizes = [];
// 判断是否显示参考尺码
let showReference = (boyReference && _.get(sizeInfo, 'sizeInfoBo.sizeBoList[0].boyReferSize', false)) ||
(girlReference && _.get(sizeInfo, 'sizeInfoBo.sizeBoList[0].girlReferSize', false));
// 吊牌尺码
sizes.push(value.sizeName);
if (!_.has(sizeInfo, 'sizeInfoBo.sizeAttributeBos')) {
return {};
}
// 判断是否显示参考尺码
if (boyReference && (gender === 1 || gender === 3) && showReference) {
sizes.push(_.get(value, 'boyReferSize.referenceName', ' '));
} else if (girlReference && (gender === 2 || gender === 3) && showReference) {
sizes.push(_.get(value, 'girlReferSize.referenceName', ' '));
} else {
if (size.thead[1] && showReference) {
size.thead[1] = {};
}
// 尺码信息头部
let size = {
thead: [{name: '吊牌尺码', id: ''}],
tbody: []
};
// 显示参考尺码
if (showReference) {
size.thead[1] = {name: referenceName, id: ''};
}
// 其他尺码信息
_.get(value, 'sortAttributes', []).forEach(attr => {
sizes.push(_.get(attr, 'sizeValue', ' '));
_.get(sizeInfo, 'sizeInfoBo.sizeAttributeBos', []).forEach((value) => {
size.thead.push({
name: value.attributeName || ' ',
id: value.id
});
});
// 尺码信息
size.tbody.push(sizes);
});
_.get(sizeInfo, 'sizeInfoBo.sizeBoList', []).forEach((value) => {
let sizes = [];
// 参考尺码为空
if (_.isEmpty(size.thead[1]) && showReference) {
// 移除这个值
size.thead.splice(1, 1);
}
// 吊牌尺码
sizes.push(value.sizeName);
// 测量方式
if (sizeInfo.sizeImage) {
size.sizeImg = sizeInfo.sizeImage;
}
// 判断是否显示参考尺码
if (boyReference && (gender === 1 || gender === 3) && showReference) {
sizes.push(_.get(value, 'boyReferSize.referenceName', ' '));
} else if (girlReference && (gender === 2 || gender === 3) && showReference) {
sizes.push(_.get(value, 'girlReferSize.referenceName', ' '));
} else {
if (size.thead[1] && showReference) {
size.thead[1] = {};
}
}
return size;
};
// 其他尺码信息
_.get(value, 'sortAttributes', []).forEach(attr => {
sizes.push(_.get(attr, 'sizeValue', ' '));
});
/**
* 商品尺码信息
*
* @param productSkn
* @param maxSortId
* @return object
*/
const _getIntroInfo = (productSkn, additionalData)=> {
if (!productSkn) {
return {};
}
// 尺码信息
size.tbody.push(sizes);
});
// 参考尺码为空
if (_.isEmpty(size.thead[1]) && showReference) {
// 移除这个值
size.thead.splice(1, 1);
}
let sizeInfo = additionalData.sizeInfo;
// 测量方式
if (sizeInfo.sizeImage) {
size.sizeImg = sizeInfo.sizeImage;
}
if (_.isEmpty(sizeInfo)) {
return {};
return size;
}
let result = {};
/**
* 商品尺码信息
*
* @param productSkn
* @param maxSortId
* @return object
*/
_getIntroInfo(productSkn, additionalData) {
if (!productSkn) {
return {};
}
// 尺寸数据
result.size = _getSizeData(sizeInfo);
let sizeInfo = additionalData.sizeInfo;
return result;
};
if (_.isEmpty(sizeInfo)) {
return {};
}
/**
* 详情页数据格式化
* @param origin Object 原始数据
* @return result Object 格式化数据
*/
const _detailDataPkg = (origin) => {
if (_.isEmpty(origin) || _.isEmpty(origin)) {
return {};
}
let result = {};
let result = {};
let propOrigin = _.partial(_.get, origin);
// 尺寸数据
result.size = this._getSizeData(sizeInfo);
// 商品名称
if (!propOrigin('product_name')) {
return result;
}
result.name = propOrigin('product_name');
result.skn = propOrigin('product_skn');
result.productId = propOrigin('product_id');
/**
* 详情页数据格式化
* @param origin Object 原始数据
* @return result Object 格式化数据
*/
_detailDataPkg(origin) {
if (_.isEmpty(origin) || _.isEmpty(origin)) {
return {};
}
// 商品价格
result.marketPrice = propOrigin('format_market_price');
result.salePrice = propOrigin('format_sales_price');
result.hasOtherPrice = true;
let result = {};
let propOrigin = _.partial(_.get, origin);
if (result.salePrice === '0') {
delete result.salePrice;
result.hasOtherPrice = false;
}
// 商品名称
if (!propOrigin('product_name')) {
return result;
}
// 上市期
if (propOrigin('expect_arrival_time')) {
result.arrivalDate = `${propOrigin('expect_arrival_time')}月`;
result.presalePrice = propOrigin('format_sales_price');
delete result.salePrice;
result.hasOtherPrice = false;
}
result.name = propOrigin('product_name');
result.skn = propOrigin('product_skn');
result.productId = propOrigin('product_id');
// sku商品信息
let skuData = _getSkuDataByProductBaseInfo(origin);
// 商品价格
result.marketPrice = propOrigin('format_market_price');
result.salePrice = propOrigin('format_sales_price');
result.hasOtherPrice = true;
// 商品购买状态
let soldOut = !!(propOrigin('status') === 0 || skuData.totalStorageNum === 0);
let virtualGoods = propOrigin('attribute') === 3; // 虚拟商品
if (result.salePrice === '0') {
delete result.salePrice;
result.hasOtherPrice = false;
}
if (!soldOut && !virtualGoods) {
result.addToCart = 1;
}
// 上市期
if (propOrigin('expect_arrival_time')) {
result.arrivalDate = `${propOrigin('expect_arrival_time')}月`;
result.presalePrice = propOrigin('format_sales_price');
delete result.salePrice;
result.hasOtherPrice = false;
}
result.isCollect = propOrigin('is_collect');
result.colors = skuData.skuGoods;
// sku商品信息
let skuData = this._getSkuDataByProductBaseInfo(origin);
return result;
};
// 商品购买状态
let soldOut = !!(propOrigin('status') === 0 || skuData.totalStorageNum === 0);
let virtualGoods = propOrigin('attribute') === 3; // 虚拟商品
/**
* 获取某一个商品详情主页面
*/
const getProductInfoAsync = (pid) => {
return co(function * () {
if (!pid) {
return {};
if (!soldOut && !virtualGoods) {
result.addToCart = 1;
}
// 获取商品基本信息
let productData = yield productAPI.getProductAsync(pid);
result.isCollect = propOrigin('is_collect');
result.colors = skuData.skuGoods;
if (_.isEmpty(productData.data)) {
return Promise.reject({
code: 404,
message: 'app.product.data api wrong'
});
}
return result;
}
let productSkn = _.get(productData, 'data.product_skn');
/**
* 获取某一个商品详情主页面
*/
getProductInfoAsync(pid) {
let that = this;
let productDescription = yield _getProductIntroAsync(productSkn);
let productInfo = _detailDataPkg(productData.data);
let intro = _getIntroInfo(productSkn, productDescription);
return co(function * () {
if (!pid) {
return {};
}
return Object.assign(productInfo, intro);
})();
};
// 获取商品基本信息
let productData = yield new ProductAPI(that.ctx).getProductAsync(pid);
// 获取优惠券列表
const getCoupons = (uid) => api.get('', {
method: 'app.Shopping.listCoupon',
uid: uid
}).then(result => {
if (result.code === 200) {
let unuse = [];
let use = [];
_.get(result, 'data.unusable_coupons', []).forEach(i => {
unuse.push({
code: i.coupon_code,
name: i.coupon_name,
value: i.coupon_value,
canuse: false
});
});
if (_.isEmpty(productData.data)) {
return Promise.reject({
code: 404,
message: 'app.product.data api wrong'
});
}
_.get(result, 'data.usable_coupons', []).forEach(i => {
use.push({
code: i.coupon_code,
name: i.coupon_name,
value: i.coupon_value
});
});
let productSkn = _.get(productData, 'data.product_skn');
result.data = _.concat(use, unuse);
let productDescription = yield that._getProductIntroAsync(productSkn);
let productInfo = that._detailDataPkg(productData.data);
let intro = that._getIntroInfo(productSkn, productDescription);
return Object.assign(productInfo, intro);
})();
}
return result;
});
// 获取优惠券列表
getCoupons(uid) {
let params = {
method: 'app.Shopping.listCoupon',
uid: uid
};
/**
* 购物车数据
* @param uid
* @param shoppingKey
* @param cartDelList
* @returns {*}
*/
const getCartData = (uid, shoppingKey, cartDelList) => {
return cartApi.cartData(uid, shoppingKey).then(cartDataRet => {
return chelper.formatCart(cartDataRet, uid, shoppingKey, cartDelList);
});
};
return this.get({data: params}).then(result => {
/**
* 获取购物车总数
*
* @param int $uid 用户ID
* @param string $shoppingKey 客户端购物标识
* @return array
*/
const getCartCount = (uid, shoppingKey) => {
return cartApi.cartCount(uid, shoppingKey);
};
if (result.code === 200) {
let unuse = [];
let use = [];
/**
* 加入购物车 获取数量
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 购物车在浏览器的唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
const addCart = (productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey) => {
_.get(result, 'data.unusable_coupons', []).forEach(i => {
unuse.push({
code: i.coupon_code,
name: i.coupon_name,
value: i.coupon_value,
canuse: false
});
});
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
_.get(result, 'data.usable_coupons', []).forEach(i => {
use.push({
code: i.coupon_code,
name: i.coupon_name,
value: i.coupon_value
});
});
result.data = _.concat(use, unuse);
}
if (!productSku) {
return result;
}
});
}
let ret = yield cartApi.addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey);
/**
* 购物车数据
* @param uid
* @param shoppingKey
* @param cartDelList
* @returns {*}
*/
getCartData(uid, shoppingKey, cartDelList) {
return new CartApi(this.ctx).cartData(uid, shoppingKey).then(cartDataRet => {
return chelper.formatCart(cartDataRet, uid, shoppingKey, cartDelList);
});
}
if (ret && ret.code) {
result = ret;
}
/**
* 获取购物车总数
*
* @param int $uid 用户ID
* @param string $shoppingKey 客户端购物标识
* @return array
*/
getCartCount(uid, shoppingKey) {
return new CartApi(this.ctx).cartCount(uid, shoppingKey);
}
return result;
})();
};
/**
* 加入购物车 获取数量
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 购物车在浏览器的唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
addCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
/**
* 加入购物车
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 购物车在浏览器的唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
const addToCart = (productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey, cartDelList) => {
if (!productSku) {
return result;
}
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
let ret = yield new CartApi(that.ctx).addToCart(
productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey
);
if (!productSku) {
return result;
}
if (ret && ret.code) {
result = ret;
}
let ret = yield cartApi.addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey);
return result;
})();
}
if (ret && ret.code) {
result = {
code: ret.code,
data: yield getCartData(uid, shoppingKey || _.get(ret, 'data.shopping_key'), cartDelList)
/**
* 加入购物车
*
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @param string $shoppingKey 购物车在浏览器的唯一识别码,可以不传
* @return array 加入购物车接口返回的数据
*/
addToCart(productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
}
if (!shoppingKey && result.data) {
result.data.shopping_key = _.get(ret, 'data.shopping_key');
}
/* if (empty($addCart) || (isset($addCart['code']) && $addCart['code'] !== 200) ) {
UdpLog::info('【购物车】校验参数传递auth','productSku:'.$productSku.'buyNumber:'.$buyNumber.
'goodsType:'.$goodsType,'isEdit:'.$isEdit.'promotionId:'.$promotionId.'uid:'.$uid.'shoppingKey:'.$shoppingKey);
}*/
if (!productSku) {
return result;
}
return result;
})();
};
let ret = yield new CartApi(that.ctx).addToCart(
productSku, buyNumber, goodsType, isEdit, promotionId, uid, shoppingKey
);
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表json格式, 如{"744403":1}
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 处理之后的数据的数据
*/
const selectGoods = (uid, skuList, shoppingKey, hasPromotion, cartDelList) => {
if (ret && ret.code) {
result = {
code: ret.code,
data: yield that.getCartData(uid, shoppingKey || _.get(ret, 'data.shopping_key'), cartDelList)
};
}
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (!shoppingKey && result.data) {
result.data.shopping_key = _.get(ret, 'data.shopping_key');
}
if (!skuList) {
// UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
return result;
}
let select = yield cartApi.selectGoods(uid, skuList, shoppingKey, hasPromotion);
})();
}
if (select && select.code) {
result = {
code: select.code,
data: chelper.formatCart(select, uid, shoppingKey, cartDelList)
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表json格式, 如{"744403":1}
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 处理之后的数据的数据
*/
selectGoods(uid, skuList, shoppingKey, hasPromotion, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
// result = select;
}/* else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:'
. $skuList . 'shoppingKey:' . $shoppingKey . 'hasPromotion:' . $hasPromotion);
}*/
return result;
})();
};
if (!skuList) {
return result;
}
/**
* 修改购物车商品数量
*
* @param int $uid 用户ID
* @param string $sku 商品SKU
* @param int $increaseNum 增加的数目
* @param int $decreaseNum 减少的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
const modifyProductNum = (uid, sku, increaseNum, decreaseNum, shoppingKey, cartDelList) => {
let select = yield new CartApi(that.ctx).selectGoods(uid, skuList, shoppingKey, hasPromotion);
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (select && select.code) {
result = {
code: select.code,
data: chelper.formatCart(select, uid, shoppingKey, cartDelList)
};
}
if (!sku) {
// UdpLog::info('【购物车】校验参数传递auth', 'sku:' . $sku);
return result;
}
let ret = yield cartApi.modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey);
})();
}
if (ret && ret.code) {
result = {
code: ret.code,
data: yield getCartData(uid, shoppingKey, cartDelList)
/**
* 修改购物车商品数量
*
* @param int $uid 用户ID
* @param string $sku 商品SKU
* @param int $increaseNum 增加的数目
* @param int $decreaseNum 减少的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
}/* else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'sku:' . $sku, 'increaseNum:'
. $increaseNum . 'decreaseNum:' . $decreaseNum . 'shoppingKey:' . $shoppingKey);
}*/
return result;
})();
};
if (!sku) {
return result;
}
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表json格式, 如{"744403":1}
* @param string $count 要删除的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 接口返回的数据
*/
const removeFromCart = (uid, shoppingKey, skuList, hasPromotion, cartDelList) => {
let ret = yield new CartApi(that.ctx).modifyProductNum(uid, sku, increaseNum, decreaseNum, shoppingKey);
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (ret && ret.code) {
result = {
code: ret.code,
data: yield that.getCartData(uid, shoppingKey, cartDelList)
};
}
if (!skuList) {
// UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
return result;
}
let ret = yield cartApi.removeFromCart(uid, shoppingKey, skuList, hasPromotion);
})();
if (!hasPromotion) {
return ret;
}
}
if (ret && ret.code) {
result = {
code: ret.code,
data: chelper.formatCart(ret, uid, shoppingKey, cartDelList)
/**
* 移出购物车
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表json格式, 如{"744403":1}
* @param string $count 要删除的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 接口返回的数据
*/
removeFromCart(uid, shoppingKey, skuList, hasPromotion, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
}/* else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:' .
$skuList . 'shoppingKey:' . $shoppingKey . 'hasPromotion:' . $hasPromotion);
}*/
return result;
})();
};
if (!skuList) {
return result;
}
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 接口返回的数据
*/
const addToFav = (uid, skuList, hasPromotion, cartDelList) => {
let ret = yield new CartApi(that.ctx).removeFromCart(uid, shoppingKey, skuList, hasPromotion);
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (!hasPromotion) {
return ret;
}
if (!uid) {
return {
code: 403,
message: '请先登录!',
data: {
url: helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/cart/cart')
})
}
};
}
if (ret && ret.code) {
result = {
code: ret.code,
data: chelper.formatCart(ret, uid, shoppingKey, cartDelList)
};
}
if (!skuList) {
// UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
return result;
}
let ret = yield cartApi.addToFav(uid, skuList, hasPromotion);
})();
}
if (ret && ret.code) {
result = {
code: ret.code,
data: chelper.formatCart(ret, uid, null, cartDelList)
/**
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $skuList 商品sku列表
* @param bool hasPromotion 标识是不是有promotion_id参数, 后端会去调用不同的接口
* @return array 接口返回的数据
*/
addToFav(uid, skuList, hasPromotion, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
}/* else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:' . $skuList . 'hasPromotion:' . $hasPromotion);
}*/
return result;
})();
};
/**
* 检查用户是否收藏这一批商品
*
* @param int $uid 用户ID
* @param array $skuList 商品SKU列表
* @return array
*/
const checkUserIsFav = (uid, skuList) => {
return co(function * () {
let result = {};
if (!uid) {
return {
code: 403,
message: '请先登录!',
data: {
url: helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/cart/cart')
})
}
};
}
if (!skuList) {
return result;
}
if (!skuList) {
return result;
}
if (!uid || !_.isNumber(uid)) {
let ret = yield new CartApi(that.ctx).addToFav(uid, skuList, hasPromotion);
_.forEach(skuList, it => {
result[it] = false;
});
if (ret && ret.code) {
result = {
code: ret.code,
data: chelper.formatCart(ret, uid, null, cartDelList)
};
}
return result;
}
})();
return yield cartApi.checkUserIsFavProductList(uid, skuList);
})();
};
}
/**
* 获取为你优选商品 待处理
*
* @param $channel 频道
* @param $uid 用户id
* @param $udid 设备id
* @param int $page 分页页码
* @return array
* @internal param $rec_pos
* @internal param $limit
*/
const getRecommendProduct = (channelNum, uid, udid, page) => {
return co(function * () {
let result = {
code: 200,
message: '',
data: {
header: '为您优选',
hasPrev: false,
hasNext: false,
item: null
/**
* 检查用户是否收藏这一批商品
*
* @param int $uid 用户ID
* @param array $skuList 商品SKU列表
* @return array
*/
checkUserIsFav(uid, skuList) {
let that = this;
return co(function * () {
let result = {};
if (!skuList) {
return result;
}
};
if (!_.isNumber(page)) {
return result;
}
if (!uid || !_.isNumber(uid)) {
let together = yield cartApi.newPreference(channelNum, uid, udid, '100003', 30);
let plist = _.get(together, 'data.product_list');
_.forEach(skuList, it => {
result[it] = false;
});
if (!plist || !plist.length) {
return result;
}
return result;
}
if (page > 5) {
page = 1;
}
return yield new CartApi(that.ctx).checkUserIsFavProductList(uid, skuList);
})();
}
let begin = (page - 1) * 6;
let end = begin + 7;
let items = _.map(_.slice(plist, begin, end), it => {
let item = {
id: it.product_id,
skn: it.product_skn,
title: it.product_name,
img: it.default_images ? helpers.image(it.default_images, 190, 250) : '',
alt: it.product_name,
price: '¥' + chelper.transPrice(it.sales_price),
marketPrice: (it.market_price && +it.market_price > +it.sales_price) ?
'¥' + chelper.transPrice(it.market_price) : ''
/**
* 获取为你优选商品 待处理
*
* @param $channel 频道
* @param $uid 用户id
* @param $udid 设备id
* @param int $page 分页页码
* @return array
* @internal param $rec_pos
* @internal param $limit
*/
getRecommendProduct(channelNum, uid, udid, page) {
let that = this;
return co(function * () {
let result = {
code: 200,
message: '',
data: {
header: '为您优选',
hasPrev: false,
hasNext: false,
item: null
}
};
item.href = helpers.getUrlBySkc(it.product_skn);
if (+it.sales_price !== +it.market_price) {
it.marketPrice = chelper.transPrice(it.market_price);
if (!_.isNumber(page)) {
return result;
}
return item;
});
Object.assign(result.data, {
item: items
});
let together = yield new CartApi(that.ctx).newPreference(channelNum, uid, udid, '100003', 30);
let plist = _.get(together, 'data.product_list');
return result;
})();
};
if (!plist || !plist.length) {
return result;
}
/**
* 获取凑单商品
*
* @param int $page 分页页码
* @return array
*/
const getTogetherProduct = (page) => {
return co(function * () {
let result = {
code: 200,
message: '',
data: {
header: '凑单商品',
hasPrev: false,
hasNext: false,
item: null
if (page > 5) {
page = 1;
}
};
if (!_.isNumber(page)) {
return result;
}
let begin = (page - 1) * 6;
let end = begin + 7;
let items = _.map(_.slice(plist, begin, end), it => {
let item = {
id: it.product_id,
skn: it.product_skn,
title: it.product_name,
img: it.default_images ? helpers.image(it.default_images, 190, 250) : '',
alt: it.product_name,
price: '¥' + chelper.transPrice(it.sales_price),
marketPrice: (it.market_price && +it.market_price > +it.sales_price) ?
'¥' + chelper.transPrice(it.market_price) : ''
};
item.href = helpers.getUrlBySkc(it.product_skn);
if (+it.sales_price !== +it.market_price) {
it.marketPrice = chelper.transPrice(it.market_price);
}
return item;
});
let together = yield cartApi.togetherProduct(page);
Object.assign(result.data, {
item: items
});
if (!_.get(together, 'data.goods')) {
return result;
}
result.data.hasPrev = true;
result.data.hasNext = true;
result.data.item = _.map(together.data.goods, it => {
let item = {
id: it.id,
skn: it.product_skn,
})();
}
// it.url,
href: it.url,
title: it.product_name,
img: it.default_pic ? helpers.image(it.default_pic, 100, 100) : '',
alt: it.product_name,
price: Number(it.price.sales_price)
/**
* 获取凑单商品
*
* @param int $page 分页页码
* @return array
*/
getTogetherProduct(page) {
let that = this;
return co(function * () {
let result = {
code: 200,
message: '',
data: {
header: '凑单商品',
hasPrev: false,
hasNext: false,
item: null
}
};
if (item.price !== Number(it.price.market_price)) {
it.marketPrice = Number(it.price.market_price);
if (!_.isNumber(page)) {
return result;
}
return item;
});
// 当数据量不足6个时,判定为没有下一页
if (page === 1) {
result.data.hasPrev = false;
}
let together = yield new CartApi(that.ctx).togetherProduct(page);
if (!result.data.item || result.data.item.length < 6) {
result.data.hasNext = false;
}
return result;
})();
};
if (!_.get(together, 'data.goods')) {
return result;
}
/**
* 修改购物车商品
* @param param
* @param uid
* @param shoppingKey
* @param cartDelList
*/
const modifyProduct = (param, uid, shoppingKey, cartDelList) => {
result.data.hasPrev = true;
result.data.hasNext = true;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
result.data.item = _.map(together.data.goods, it => {
let ret = yield cartApi.modifyProduct(param);
let item = {
id: it.id,
skn: it.product_skn,
href: it.url,
title: it.product_name,
img: it.default_pic ? helpers.image(it.default_pic, 100, 100) : '',
alt: it.product_name,
price: Number(it.price.sales_price)
};
if (ret && ret.code) {
result = {
code: ret.code,
data: yield getCartData(uid, shoppingKey, cartDelList)
};
}
if (item.price !== Number(it.price.market_price)) {
it.marketPrice = Number(it.price.market_price);
}
return result;
})();
};
return item;
});
/**
* 重选赠品或加价购商品
* @param uid
* @param shoppingKey
* @param promotionId
* @param newSkn
* @param newSku
* @param cartDelList
*/
const swapGift = (uid, shoppingKey, promotionId, newSkn, newSku, cartDelList) => {
return co(function * () {
// 当数据量不足6个时,判定为没有下一页
if (page === 1) {
result.data.hasPrev = false;
}
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (!result.data.item || result.data.item.length < 6) {
result.data.hasNext = false;
}
let ret = yield cartApi.swapGift(uid, shoppingKey, promotionId, newSkn, newSku);
return result;
})();
}
if (ret && ret.code) {
result = {
code: ret.code,
data: yield getCartData(uid, shoppingKey, cartDelList)
/**
* 修改购物车商品
* @param param
* @param uid
* @param shoppingKey
* @param cartDelList
*/
modifyProduct(param, uid, shoppingKey, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
}
return result;
})();
let ret = yield new CartApi(that.ctx).modifyProduct(param);
};
if (ret && ret.code) {
result = {
code: ret.code,
data: yield that.getCartData(uid, shoppingKey, cartDelList)
};
}
/**
* 查询指定优惠下的可选赠品或加价购
* @param promotionId 优惠ID
* @param uid
* @param shoppingKey
*/
const queryUserPromotionGift = (promotionId, uid, shoppingKey) => {
return result;
})();
}
return co(function * () {
let promotionGifts = yield cartApi.queryPromotionGift(promotionId);
let cartDataRet = yield cartApi.cartData(uid, shoppingKey);
let selectedGift = chelper.formatCartGoods(_.get(cartDataRet, 'data.ordinary_cart_data.goods_list'));
let currentProduct = null; // 默认展示第一个商品
/**
* 重选赠品或加价购商品
* @param uid
* @param shoppingKey
* @param promotionId
* @param newSkn
* @param newSku
* @param cartDelList
*/
swapGift(uid, shoppingKey, promotionId, newSkn, newSku, cartDelList) {
let that = this;
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
if (promotionGifts && promotionGifts.code === 200) {
let promotionList = chelper.formatPriceGifts(_.get(promotionGifts, 'data.arrays', []));
let ret = yield new CartApi(that.ctx).swapGift(uid, shoppingKey, promotionId, newSkn, newSku);
promotionGifts.data = _.get(promotionList, '[0]', {});
if (ret && ret.code) {
result = {
code: ret.code,
data: yield that.getCartData(uid, shoppingKey, cartDelList)
};
}
let goodsList = [];
let checked;
return result;
})();
_.forEach(promotionList, value => {
if (!value.goodsList || !value.goodsList.length) {
return;
}
}
_.forEach(value.goodsList, it => {
if (!checked) {
checked = true;
it.active = true;
currentProduct = it;
promotionGifts.data.promotionDesc = value.promotionTitle;
/**
* 查询指定优惠下的可选赠品或加价购
* @param promotionId 优惠ID
* @param uid
* @param shoppingKey
*/
queryUserPromotionGift(promotionId, uid, shoppingKey) {
let that = this;
let cartApiModel = new CartApi(that.ctx);
return co(function * () {
let promotionGifts = yield cartApiModel.queryPromotionGift(promotionId);
let cartDataRet = yield cartApiModel.cartData(uid, shoppingKey);
let selectedGift = chelper.formatCartGoods(_.get(cartDataRet, 'data.ordinary_cart_data.goods_list'));
let currentProduct = null; // 默认展示第一个商品
if (promotionGifts && promotionGifts.code === 200) {
let promotionList = chelper.formatPriceGifts(_.get(promotionGifts, 'data.arrays', []));
promotionGifts.data = _.get(promotionList, '[0]', {});
let goodsList = [];
let checked;
_.forEach(promotionList, value => {
if (!value.goodsList || !value.goodsList.length) {
return;
}
Object.assign(it, {
isSelected: !!_.find(selectedGift, ['skn', it.skn]),
promotionId: value.promotionId,
promotionTitle: value.promotionTitle,
maxSelectNumber: value.maxSelectNumber
_.forEach(value.goodsList, it => {
if (!checked) {
checked = true;
it.active = true;
currentProduct = it;
promotionGifts.data.promotionDesc = value.promotionTitle;
}
Object.assign(it, {
isSelected: !!_.find(selectedGift, ['skn', it.skn]),
promotionId: value.promotionId,
promotionTitle: value.promotionTitle,
maxSelectNumber: value.maxSelectNumber
});
goodsList.push(it);
});
goodsList.push(it);
});
});
promotionGifts.data.goodsList = goodsList;
promotionGifts.data.goodsList = goodsList;
// 获取选中商品的数据详情
if (currentProduct && currentProduct.id) {
let prodInfo = yield getProductInfoAsync(currentProduct.id);
// 获取选中商品的数据详情
if (currentProduct && currentProduct.id) {
let prodInfo = yield that.getProductInfoAsync(currentProduct.id);
// 价格为活动价
if (prodInfo) {
prodInfo.salePrice = '¥' + currentProduct.subjoinPrice;
}
// 价格为活动价
if (prodInfo) {
prodInfo.salePrice = '¥' + currentProduct.subjoinPrice;
}
promotionGifts.data.productInfo = prodInfo;
promotionGifts.data.productInfo = prodInfo;
}
}
}
return promotionGifts;
})();
};
return promotionGifts;
})();
/**
* 首页mini购物车数据
* @param uid
* @param shoppingKey
*/
const getMiniCartData = (uid, shoppingKey) => {
}
return co(function * () {
let cartDataRet = yield cartApi.cartData(uid, shoppingKey);
/**
* 首页mini购物车数据
* @param uid
* @param shoppingKey
*/
getMiniCartData(uid, shoppingKey) {
let that = this;
if (!cartDataRet || cartDataRet.code !== 200) {
return null;
}
return co(function * () {
let cartDataRet = yield new CartApi(that.ctx).cartData(uid, shoppingKey);
let ret = cartDataRet && cartDataRet.data;
let advCart = _.get(ret, 'advance_cart_data');
let comCart = _.get(ret, 'ordinary_cart_data');
let advGoodsList = _.flatten(_.map(_.get(advCart, 'goods_pool_list'), 'goods_list'));
let comGoodsList = _.flatten(_.map(_.get(comCart, 'goods_pool_list'), 'goods_list'));
let comSubs = _.flatten(_.map(_.get(comCart, 'goods_pool_list'), 'sub_pool'));
let subsGoodsList = _.flatten(_.map(comSubs, 'goods_list'));
let advOffShe = _.get(advCart, 'off_shelves_goods_list');
let comOffShe = _.get(comCart, 'off_shelves_goods_list');
let advSoldOuts = _.get(advCart, 'sold_out_goods_list');
let comSoldOuts = _.get(comCart, 'sold_out_goods_list');
let goodsList = _(advGoodsList).concat(comGoodsList, subsGoodsList,
advOffShe, comOffShe,
advSoldOuts, comSoldOuts);
goodsList = _.filter(goodsList.value(), it => !!it);
let glist = _.map(goodsList, g => {
let goods = {
is_advance: g.is_advance,
default_img: g.goods_images ? helpers.image(g.goods_images, 46, 62) : '',
product_name: g.product_name,
factory_goods_name: g.factory_goods_name,
size_name: g.size_name,
show_price: transPrice(g.real_price),
buy_number: g.buy_number,
goods_incart_id: g.shopping_cart_id,
product_sku: g.product_sku,
promotion_id: g.promotion_id
};
goods.product_url = helpers.getUrlBySkc(g.product_skn);
return goods;
});
if (!cartDataRet || cartDataRet.code !== 200) {
return null;
}
let advCount = _.get(ret, 'advance_cart_data.shopping_cart_data.goods_count') || 0;
let comCount = _.get(ret, 'ordinary_cart_data.shopping_cart_data.goods_count') || 0;
let ret = cartDataRet && cartDataRet.data;
let advCart = _.get(ret, 'advance_cart_data');
let comCart = _.get(ret, 'ordinary_cart_data');
let advGoodsList = _.flatten(_.map(_.get(advCart, 'goods_pool_list'), 'goods_list'));
let comGoodsList = _.flatten(_.map(_.get(comCart, 'goods_pool_list'), 'goods_list'));
let comSubs = _.flatten(_.map(_.get(comCart, 'goods_pool_list'), 'sub_pool'));
let subsGoodsList = _.flatten(_.map(comSubs, 'goods_list'));
let advOffShe = _.get(advCart, 'off_shelves_goods_list');
let comOffShe = _.get(comCart, 'off_shelves_goods_list');
let advSoldOuts = _.get(advCart, 'sold_out_goods_list');
let comSoldOuts = _.get(comCart, 'sold_out_goods_list');
let goodsList = _(advGoodsList).concat(comGoodsList, subsGoodsList,
advOffShe, comOffShe,
advSoldOuts, comSoldOuts);
goodsList = _.filter(goodsList.value(), it => !!it);
let glist = _.map(goodsList, g => {
let goods = {
is_advance: g.is_advance,
default_img: g.goods_images ? helpers.image(g.goods_images, 46, 62) : '',
product_name: g.product_name,
factory_goods_name: g.factory_goods_name,
size_name: g.size_name,
show_price: chelper.transPrice(g.real_price),
buy_number: g.buy_number,
goods_incart_id: g.shopping_cart_id,
product_sku: g.product_sku,
promotion_id: g.promotion_id
};
goods.product_url = helpers.getUrlBySkc(g.product_skn);
return goods;
});
return {
main_goods: glist,
total: Number(advCount) + Number(comCount)
};
})();
};
let advCount = _.get(ret, 'advance_cart_data.shopping_cart_data.goods_count') || 0;
let comCount = _.get(ret, 'ordinary_cart_data.shopping_cart_data.goods_count') || 0;
// 套餐添加购物车
const addBundleData = (params) => {
return cartApi.addBundle(params).then(d => { // eslint-disable-line
return d;
});
};
return {
main_goods: glist,
total: Number(advCount) + Number(comCount)
};
})();
}
// 套餐增减购物车
const bundleNumData = (params, cartDelList) => {
// 套餐添加购物车
addBundleData(params) {
return new CartApi(this.ctx).addBundle(params);
}
return co(function * () {
let result = {
code: 400,
message: ERROR_400_MESSAGE
};
// 套餐增减购物车
bundleNumData(params, cartDelList) {
let that = this;
if (!params.activity_id) {
return {
return co(function * () {
let result = {
code: 400,
message: '无效的活动'
message: ERROR_400_MESSAGE
};
}
let ret = yield cartApi.bundleNum(params);
if (!params.activity_id) {
return {
code: 400,
message: '无效的活动'
};
}
if (ret && ret.code) {
result = {
code: ret.code,
data: yield getCartData(params.uid, params.shopping_key, cartDelList)
};
}
let ret = yield new CartApi(that.ctx).bundleNum(params);
return result;
})();
};
if (ret && ret.code) {
result = {
code: ret.code,
data: yield that.getCartData(params.uid, params.shopping_key, cartDelList)
};
}
module.exports = {
getProductInfoAsync, /** 获取商品信息 **/
getCartData, /** 购物车数据 **/
getCartCount, /** 得到购物车数量 **/
addCart, /** 加入到购物车 获取数量 **/
addToCart, /** 加入到购物车 **/
selectGoods, /** 选中/取消选中商品 **/
modifyProductNum, /** 修改商品数量 **/
removeFromCart, /** 从购物车中删除 **/
addToFav, /** 移入收藏 **/
checkUserIsFav, /** 判断商品是否已收藏 **/
getRecommendProduct, /** 为您优选商品 **/
getTogetherProduct, /** 凑单商品 **/
modifyProduct, /** 修改购物车商品 **/
swapGift, /** 重选赠品或加价购商品 **/
queryUserPromotionGift, /** 查询指定优惠下的可选赠品或加价购 **/
getCoupons, /** 获取优惠券列表 **/
getMiniCartData, /** 首页mini购物车数据 **/
addBundleData, /** 套餐添加购物车 **/
bundleNumData /** 套餐增减购物车 **/
return result;
})();
}
};
... ...
... ... @@ -2,30 +2,31 @@
* Created by TaoHuang on 2016/10/19.
*/
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const sizeInfoAsync = skn => {
return api.get('', {
method: 'h5.product.intro',
productskn: skn
});
sizeInfoAsync(skn) {
let params = {
method: 'h5.product.intro',
productskn: skn
};
};
return this.get({data: params});
}
/**
* 获得产品信息
* @param pid
* @returns {Promise.<type>}
*/
const getProductAsync = (pid) => {
return api.get('', {
method: 'app.product.data',
product_id: pid
});
};
/**
* 获得产品信息
* @param pid
* @returns {Promise.<type>}
*/
getProductAsync(pid) {
let params = {
method: 'app.product.data',
product_id: pid
};
module.exports = {
sizeInfoAsync,
getProductAsync
return this.get({data: params});
}
};
... ...
... ... @@ -17,7 +17,7 @@ module.exports = class extends global.yoho.BaseModel {
let data = {};
let scale = 1 / 3; // 分三等份
if (vipInfo.code !== 200) {
if (_.get(vipInfo, 'code', 400) !== 200) {
return vip;
}
... ... @@ -38,7 +38,7 @@ module.exports = class extends global.yoho.BaseModel {
}
// 进度条百分比
vip.current_total_percent = 100;
vip.current_total_percent = 1;
if (vip.current_total_growth <= vip.grades[1].val) {
vip.current_total_percent = (vip.current_total_growth * scale / vip.grades[1].val);
} else if (vip.current_total_growth <= vip.grades[2].val) {
... ...
... ... @@ -167,6 +167,8 @@ module.exports = {
}
},
REQUEST_LIMIT: {
// 10s 最多访问5次
10: 5,
// 30s 最多访问15次
30: 15,
... ...
{
"name": "yohobuy-node",
"version": "5.9.88",
"version": "6.1.1",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -256,7 +256,7 @@ Cart = {
if (!$this.data('gift') && !$item.hasClass('tr-disabled')) {
countJSON.push({
productPrice: $item.find('.product-price p.p-product-price').text(),
productTitle: $item.find('.pay-pro-info a').text(),
productTitle: $.trim($item.find('.pay-pro-info a').text()),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
... ... @@ -310,8 +310,8 @@ Cart = {
});
PromotionArray.push({
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
productPrice: $item.find('.product-price p.p-product-price').text(),
productTitle: $.trim($item.find('.pay-pro-info a').text()),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
... ... @@ -369,8 +369,8 @@ Cart = {
});
PromotionArray.push({
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
productPrice: $item.find('.product-price p.p-product-price').text(),
productTitle: $.trim($item.find('.pay-pro-info a').text()),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
... ...