...
|
...
|
@@ -5,9 +5,7 @@ const co = Promise.coroutine; |
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const path = require('path');
|
|
|
const pager = require('./pager').handlePagerData;
|
|
|
|
|
|
const favoriteApi = require('./favorite-api');
|
|
|
|
|
|
const TABS = [
|
...
|
...
|
@@ -54,7 +52,7 @@ const _getSortInfo = (categoryList, sort)=> { |
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const _getPager = (page, total, totalPage, size, type)=> {
|
|
|
const _getPager = (page, total, totalPage)=> {
|
|
|
let result = {};
|
|
|
|
|
|
if (page && total && totalPage) {
|
...
|
...
|
@@ -205,7 +203,7 @@ const favoriteProductListAsync = (uid, page, limit, selectedSort, subscribe, red |
|
|
})();
|
|
|
};
|
|
|
|
|
|
const favoriteBrandListAsync = (uid, page, limit)=> {
|
|
|
const favoriteBrandListAsync = (uid, page, limit, type)=> {
|
|
|
return co(function*() {
|
|
|
let result = {
|
|
|
brands: {
|
...
|
...
|
@@ -237,15 +235,14 @@ const favoriteBrandListAsync = (uid, page, limit)=> { |
|
|
});
|
|
|
|
|
|
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 = pager(total, {page, limit, type});
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const favoriteArticleListAsync = (uid, udid, page, limit)=> {
|
|
|
const favoriteArticleListAsync = (uid, udid, page, limit, type)=> {
|
|
|
return co(function*() {
|
|
|
let result = {};
|
|
|
|
...
|
...
|
@@ -262,10 +259,8 @@ const favoriteArticleListAsync = (uid, udid, page, limit)=> { |
|
|
});
|
|
|
|
|
|
let total = articles.data.total || 0;
|
|
|
let pageTotal = articles.data.totalPage || 0;
|
|
|
let pageNum = articles.data.page || 0;
|
|
|
|
|
|
result.pager = _getPager(pageNum, total, pageTotal);
|
|
|
result.pager = pager(total, {page, limit, type});
|
|
|
|
|
|
if (_.isEmpty(result.articles)) {
|
|
|
result.articles = {
|
...
|
...
|
@@ -305,14 +300,83 @@ const newProductAsync = (uid, page, limit, id) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
const reduction = (uid, page, limit, type) =>{
|
|
|
const reductionAsync = (uid, page, limit) =>{
|
|
|
let result = {};
|
|
|
|
|
|
result.tabs = getFavoriteTabs('product');
|
|
|
return favoriteProductListAsync(uid, page, limit, 0, 'Y').then((products) => {
|
|
|
result.goods = products.goods;
|
|
|
result.reductionUrl = helpers.urlFormat('/home/fovorite');
|
|
|
return {
|
|
|
meFavoritePage: true,
|
|
|
meFavorite: result
|
|
|
};
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
const enableNoticeAsync = (uid, mobile, id) => {
|
|
|
return co(function *() {
|
|
|
let result = {
|
|
|
code: 400,
|
|
|
message: '订阅失败'
|
|
|
};
|
|
|
|
|
|
if (!uid || !mobile || !id) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
let data = yield favoriteApi.redutionAdd(uid, mobile, id);
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
result.code = 200;
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (data.code === 500) {
|
|
|
result.code = 500;
|
|
|
switch (data.message) {
|
|
|
case 'count must be lt 5':
|
|
|
result.message = '您的订阅数已经到达上限';
|
|
|
break;
|
|
|
case 'mobile must bu not null':
|
|
|
result.message = '请填写手机号';
|
|
|
break;
|
|
|
default:
|
|
|
result.message = '订阅失败';
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const disableNoticeAsync = (uid, id) => {
|
|
|
return co(function * () {
|
|
|
if (!uid || !id) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '取消失败'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return yield favoriteApi.redutionCancel(uid, id);
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const cancelAsync = (uid, id, type) => {
|
|
|
return favoriteApi.cancel[type](uid, id);
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getFavoriteTabs,
|
|
|
favoriteBrandListAsync,
|
|
|
favoriteProductListAsync,
|
|
|
favoriteArticleListAsync,
|
|
|
newProductAsync
|
|
|
newProductAsync,
|
|
|
reductionAsync,
|
|
|
enableNoticeAsync,
|
|
|
disableNoticeAsync,
|
|
|
cancelAsync
|
|
|
}; |
...
|
...
|
|