...
|
...
|
@@ -2,11 +2,11 @@ |
|
|
|
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const path = require('path');
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
const pager = require(pagerPath).handlePagerData;
|
|
|
const pager = require('./pager').handlePagerData;
|
|
|
|
|
|
const favoriteApi = require('./favorite-api');
|
|
|
|
...
|
...
|
@@ -26,10 +26,104 @@ const getFavoriteTabs = (type) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const favoriteProductList = (uid, page, limit, type, sort, subscribe, reduction, promotion) => {
|
|
|
const _getSortInfo = (categoryList, sort)=> {
|
|
|
if (_.isEmpty(categoryList)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
let result = {};
|
|
|
|
|
|
result.all = categoryList.map((category) => {
|
|
|
return {
|
|
|
name: category.category_name,
|
|
|
url: helpers.urlFormat('/home/favorite', {sort_id: category.category_id}),
|
|
|
count: category.num,
|
|
|
focus: category.category_id === sort
|
|
|
};
|
|
|
});
|
|
|
|
|
|
let defaultCategory = {
|
|
|
name: '全部',
|
|
|
url: helpers.urlFormat('/home/favorite'),
|
|
|
count: _.sumBy(categoryList, category => category.num),
|
|
|
focus: sort === 0
|
|
|
};
|
|
|
|
|
|
result.all.unshift(defaultCategory);
|
|
|
result.default = result.all.slice(0, 7);
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const _getPager = (page, total, totalPage, size, type)=> {
|
|
|
let result = {};
|
|
|
|
|
|
if (page && total && totalPage) {
|
|
|
result = {
|
|
|
count: total,
|
|
|
curPage: page,
|
|
|
totalPages: totalPage,
|
|
|
hasCheckAll: true
|
|
|
};
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const getGoodsInfo = (data, page, limit)=> {
|
|
|
let result = data.slice((page - 1) * limit, page * limit).map((item) => {
|
|
|
return {
|
|
|
skn: item.product_id,
|
|
|
img: helpers.image(item.image, 100, 100),
|
|
|
name: item.product_name,
|
|
|
url: helpers.getUrlBySkc(item.product_id, item.goodsId, item.cnAlphabet),
|
|
|
price: item.sales_price,
|
|
|
priceDown: item.price_down,
|
|
|
buyNow: helpers.getUrlBySkc(item.product_id, item.goodsId, item.cnAlphabet),
|
|
|
soldOut: item.storage === 0 ? true : '',
|
|
|
hadNoticed: item.is_subscribe_reduction === 'Y' ? true : '',
|
|
|
activites: {
|
|
|
count: item.promotion_list ? item.promotion_list.length : 0,
|
|
|
list: _.get(item, 'promotion_list', []).map((val) => {
|
|
|
return {
|
|
|
type: val.promotion_type,
|
|
|
name: val.promotion_title
|
|
|
};
|
|
|
})
|
|
|
}
|
|
|
};
|
|
|
});
|
|
|
|
|
|
if (_.isEmpty(result)) {
|
|
|
return {
|
|
|
empty: '您没有收藏商品'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 降价提醒
|
|
|
*/
|
|
|
const _redutionCount = (uid)=> {
|
|
|
return co(function*() {
|
|
|
let data = yield favoriteApi.redutionCount(uid);
|
|
|
let result = {
|
|
|
count: 0,
|
|
|
phone: '',
|
|
|
url: '/home/favorite/reduction'
|
|
|
};
|
|
|
|
|
|
if (data.data.num) {
|
|
|
result.count = +data.data.num;
|
|
|
result.phone = data.data.mobile;
|
|
|
}
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
|
|
|
const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => {
|
|
|
return co(function*() {
|
|
|
let data = {};
|
|
|
let product = {};
|
|
|
let result = {
|
|
|
sort: {},
|
|
|
reduction: {},
|
...
|
...
|
@@ -38,68 +132,80 @@ const favoriteProductList = (uid, page, limit, type, sort, subscribe, reduction, |
|
|
pager: {}
|
|
|
};
|
|
|
|
|
|
product = yield favoriteApi.getFavoriteProductList(uid);
|
|
|
if (product.data.category_list) {
|
|
|
result.sort = getSortInfo(product.data.category_list, sort);
|
|
|
}
|
|
|
|
|
|
result.reduction = yield redutionCount(uid);
|
|
|
let productList = [];
|
|
|
|
|
|
if (product.data.product_list) {
|
|
|
product.data.product_list.forEach(function(product) {
|
|
|
if (
|
|
|
(reduction === 'Y' && promotion === 'Y' && product.is_price_down === 'Y' && promotion === 'Y') ||
|
|
|
(sort && product.category_id === sort) ||
|
|
|
(subscribe && product.is_subscribe_reduction === 'Y') ||
|
|
|
(reduction === 'Y' && product.is_price_down === 'Y') ||
|
|
|
(promotion === 'Y' && product.is_join_promotion === 'Y')
|
|
|
) {
|
|
|
productList.push(product);
|
|
|
}
|
|
|
});
|
|
|
productList = product.data.product_list;
|
|
|
}
|
|
|
if (reduction === 'N' && promotion === 'N') {
|
|
|
result.filter = {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else if (reduction === 'N' && promotion === 'Y') {
|
|
|
result.filter = {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else if (reduction === 'Y' && promotion === 'N') {
|
|
|
result.filter = {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y', is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else {
|
|
|
result.filter = {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y', is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
}
|
|
|
let product = yield favoriteApi.getFavoriteProductList(uid, 1, 500);
|
|
|
|
|
|
result.sort = _getSortInfo(_.get(product, 'data.category_list'), selectedSort);
|
|
|
result.reduction = yield _redutionCount(uid);
|
|
|
|
|
|
let productList = (function() {
|
|
|
let products = _.get(product, 'data.product_list', []);
|
|
|
|
|
|
if (reduction === 'Y' && promotion === 'Y') {
|
|
|
//参加活动的降价商品
|
|
|
return products.filter(pro => pro.is_price_down === 'Y' && pro.is_join_promotion === 'Y');
|
|
|
} else if (selectedSort) {
|
|
|
//商品分类过滤
|
|
|
return products.filter(pro => pro.category_id === selectedSort);
|
|
|
} else if (subscribe === 'Y') {
|
|
|
//订阅降价通知过滤
|
|
|
return products.filter(pro => pro.is_subscribe_reduction === 'Y');
|
|
|
} else if (reduction === 'Y') {
|
|
|
//降价商品过滤
|
|
|
return products.filter(pro => pro.is_price_down === 'Y');
|
|
|
} else if (promotion === 'Y') {
|
|
|
//参加活动商品过滤
|
|
|
return products.filter(pro => pro.is_join_promotion === 'Y');
|
|
|
} else {
|
|
|
return products;
|
|
|
}
|
|
|
}());
|
|
|
|
|
|
result.filter = (function() {
|
|
|
if (reduction === 'N' && promotion === 'N') {
|
|
|
return {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else if (reduction === 'N' && promotion === 'Y') {
|
|
|
return {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite'),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else if (reduction === 'Y' && promotion === 'N') {
|
|
|
return {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite'),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y', is_promotion: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
} else {
|
|
|
return {
|
|
|
reductionUrl: helpers.urlFormat('/home/favorite', {is_promotion: 'Y'}),
|
|
|
reductionChecked: '',
|
|
|
activityUrl: helpers.urlFormat('/home/favorite', {is_reduction: 'Y'}),
|
|
|
activityChecked: ''
|
|
|
};
|
|
|
}
|
|
|
}());
|
|
|
|
|
|
let total = productList;
|
|
|
let total = productList.length;
|
|
|
let pageTotal = Math.ceil(total / limit);
|
|
|
|
|
|
result.pager = getPager(page, total, pageTotal);
|
|
|
page = page > pageTotal ? pageTotal : page;
|
|
|
|
|
|
result.goods = getGoodsInfo(productList, page, limit);
|
|
|
result.pager = pager(total, query);
|
|
|
result.pager.hasCheckAll = true;
|
|
|
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const favoriteBrandList = (uid, page, limit, type)=> {
|
|
|
const favoriteBrandList = (uid, page, limit)=> {
|
|
|
return co(function*() {
|
|
|
let result = {
|
|
|
brands: {
|
...
|
...
|
@@ -113,19 +219,12 @@ const favoriteBrandList = (uid, page, limit, type)=> { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if (brand.data.page_total < page) {
|
|
|
page = brand.data.page_total;
|
|
|
brand = yield favoriteApi.favoriteBrandData(uid, page, limit);
|
|
|
}
|
|
|
|
|
|
if (!brand.data.brand_list) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
let brands = [];
|
|
|
|
|
|
brand.data.brand_list.forEach((item, i)=> {
|
|
|
brands.push({
|
|
|
result.brands = _.get(brand, 'data.brand_list', []).map((item) => {
|
|
|
return {
|
|
|
id: item.brand_id,
|
|
|
brandOrShopType: item.brandOrShopType || '',
|
|
|
shop_id: item.shop_id || '',
|
...
|
...
|
@@ -134,127 +233,54 @@ const favoriteBrandList = (uid, page, limit, type)=> { |
|
|
name: item.brand_name,
|
|
|
naCount: item.new_product_num,
|
|
|
colCount: item.brand_favorite_num
|
|
|
});
|
|
|
};
|
|
|
});
|
|
|
result.brands = brands;
|
|
|
|
|
|
let total = brand.data.total || 0;
|
|
|
let pageTotal = brand.data.page_total || 0;
|
|
|
|
|
|
page = brand.data.page || 0;
|
|
|
result.pager = getPager(page, total, pageTotal);
|
|
|
result.pager = _getPager(page, total, pageTotal);
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const favoriteArticleListAsync = (uid, udid, page, limit)=> {
|
|
|
return co(function*() {
|
|
|
let result = {articles: [], pager: {}};
|
|
|
let result = {};
|
|
|
|
|
|
let articles = yield favoriteApi.favoriteArticleData(uid, udid, page, limit);
|
|
|
|
|
|
if (!articles.data && !articles.data.data) {
|
|
|
articles.data.data.forEach((item)=> {
|
|
|
result.articles.push({
|
|
|
id: item.id,
|
|
|
name: item.title,
|
|
|
img: helpers.image(item.src, 146, 96),
|
|
|
desc: item.intro,
|
|
|
url: helpers.urlFormat('/' + item.id + '.html', '', 'guang')
|
|
|
});
|
|
|
});
|
|
|
|
|
|
let total = articles.data.total || 0;
|
|
|
let pageTotal = articles.data.totalPage || 0;
|
|
|
let pageNum = articles.data.page || 0;
|
|
|
|
|
|
result.pager = getPager(pageNum, total, pageTotal);
|
|
|
} else {
|
|
|
result.articles = {empty: '你尚未收藏任何文章!'};
|
|
|
}
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
result.articles = _.get(articles, 'data.data', []).map((item) => {
|
|
|
return {
|
|
|
id: item.id,
|
|
|
name: item.title,
|
|
|
img: helpers.image(item.src, 146, 96),
|
|
|
desc: item.intro,
|
|
|
url: helpers.urlFormat('/' + item.id + '.html', '', 'guang')
|
|
|
};
|
|
|
});
|
|
|
|
|
|
const getPager = (page, total, totalPage, size, type)=> {
|
|
|
let result = {};
|
|
|
let total = articles.data.total || 0;
|
|
|
let pageTotal = articles.data.totalPage || 0;
|
|
|
let pageNum = articles.data.page || 0;
|
|
|
|
|
|
if (page && total && totalPage) {
|
|
|
result = {
|
|
|
count: total,
|
|
|
curPage: page,
|
|
|
totalPages: totalPage,
|
|
|
hasCheckAll: true
|
|
|
};
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
result.pager = _getPager(pageNum, total, pageTotal);
|
|
|
|
|
|
const getGoodsInfo = (data, page, limit)=> {
|
|
|
let result = [];
|
|
|
let begin = (page - 1) * limit;
|
|
|
|
|
|
if (!data) {
|
|
|
data = data.slice(begin, limit);
|
|
|
data.forEach((item, i)=> {
|
|
|
let obj = {
|
|
|
skn: item.product_id,
|
|
|
img: helpers.img(item.image, 100, 100),
|
|
|
name: item.product_name,
|
|
|
url: helpers.getUrlBySkc(item.product_id, item.goodsId, item.cnAlphabet),
|
|
|
price: item.sales_price,
|
|
|
priceDown: item.price_down,
|
|
|
buyNow: helpers.getUrlBySkc(item.product_id, item.goodsId, item.cnAlphabet),
|
|
|
soldOut: item.storage === 0 ? true : '',
|
|
|
hadNoticed: item.is_subscribe_reduction === 'Y' ? true : '',
|
|
|
count: item.promotion_list ? item.promotion_list.length : 0
|
|
|
if (_.isEmpty(result.articles)) {
|
|
|
result.articles = {
|
|
|
empty: '你尚未收藏任何文章!'
|
|
|
};
|
|
|
|
|
|
if (item.promotion_list) {
|
|
|
item.promotion_list.forEach(function(item1) {
|
|
|
obj.activites.list.push({
|
|
|
type: item1.promotion_type,
|
|
|
name: item1.promotion_title
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
result.push(obj);
|
|
|
});
|
|
|
} else {
|
|
|
result = {empty: '您没有收藏商品'};
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const redutionCount = (uid)=> {
|
|
|
return co(function*() {
|
|
|
let result = {count: 0, url: '/home/favorite/reduction', phone: ''};
|
|
|
let data = yield favoriteApi.redutionCount(uid);
|
|
|
if (data.data.num) {
|
|
|
result.count = +data.data.num;
|
|
|
result.phone = data.data.mobile;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const getSortInfo = (categoryList, sort)=> {
|
|
|
let result = {default: {}, all: []};
|
|
|
let defaultCategory = {name: '全部', url: helpers.urlFormat('/home/favorite'), count: 0, focus: ''};
|
|
|
|
|
|
categoryList.forEach(function(category) {
|
|
|
result.all.push({
|
|
|
name: category.category_name,
|
|
|
url: helpers.urlFormat('/home/favorite', {sort_id: category.category_id}),
|
|
|
count: category.num,
|
|
|
focus: category.category_id === sort ? true : ''
|
|
|
});
|
|
|
defaultCategory.count += category.num;
|
|
|
defaultCategory.focus = sort === 0 ? true : '';
|
|
|
});
|
|
|
result.all.unshift(defaultCategory);
|
|
|
result.default = result.all.slice(result.all, 0, 7);
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
getFavoriteTabs,
|
...
|
...
|
|