Authored by yyq

店铺收藏

... ... @@ -6,6 +6,7 @@
const helpers = global.yoho.helpers;
const brandService = require('../models/favorite-brand-service');
const productService = require('../models/favorite-product-service');
const fav = require('../models/favorite');
/**
* 收藏品牌ajax请求
... ... @@ -85,7 +86,36 @@ const collectProduct = (req, res, next) => {
}
};
const collectShop = (req, res, next) => {
let uid = req.user.uid || '';
let shopId = req.body.shopId;
let isadd = req.body.isFavorite;
// needColloect 说明刚登录状态 是cookie传的值
if (req.body.needColloect * 1 === 1) {
isadd = true;
}
if (!uid) {
res.json({
code: 401,
message: '用户没有登录',
data: {url: helpers.urlFormat('/signin')}
});
} else if (!shopId) {
res.json({
code: 400,
message: '收藏失败'
});
} else {
fav.toggleFavShop(shopId, uid, isadd).then(result => {
res.json(result);
}).catch(next);
}
};
module.exports = {
changeFavoriteBrand,
collectProduct
collectProduct,
collectShop
};
... ...
... ... @@ -24,6 +24,9 @@ const shop = (shopId, req, res, next) => {
// 经典模板
list.getShopData(shopId, req.user.id, req.query, shopInfo).then(result => {
Object.assign(result, {
page: 'shop'
});
res.render('list/shop-index', result);
}).catch(next);
... ... @@ -126,6 +129,9 @@ exports.shopList = (req, res, next) => {
}
list.getShopListData(req.query).then(result => {
Object.assign(result, {
page: 'shop'
});
res.render('list/shop-list', result);
}).catch(next);
};
... ...
/**
* 收藏相关接口
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/17
*/
'use strict';
const api = global.yoho.API;
/**
* 收藏API
* @function addFavAsync
* @param { number } uid 用户uid
* @param { number } id 收藏id
* @param { string } type 收藏类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 收藏结果
*/
const addFavAsync = (uid, id, type) => {
return api.get('', {
method: 'app.favorite.add',
id: id,
uid: uid,
type: type
});
};
/**
* 取消收藏API
* @function cancelFavAsync
* @param { number } uid 用户uid
* @param { number } id 收藏id
* @param { string } type 收藏类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 取消收藏结果
*/
const cancelFavAsync = (uid, id, type) => {
return api.get('', {
method: 'app.favorite.cancel',
fav_id: id,
uid: uid,
type: type
});
};
module.exports = {
addFavAsync, // 收藏
cancelFavAsync // 取消收藏
};
... ...
... ... @@ -4,6 +4,6 @@
'use strict';
const favoriteProductAPI = require('./favorite-product-api');
const favoriteProductAPI = require('./favorite-api');
module.exports = favoriteProductAPI;
... ...
/**
* 收藏相关接口
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/17
*/
'use strict';
const favAPI = require('./favorite-api');
/**
* 收藏商品
* @function toggleFavProduct
* @param { number } productId 商品id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavProduct = (productId, uid, isadd) => {
if (isadd) {
return favAPI.addFavAsync(uid, productId, 'product');
} else {
return favAPI.cancelFavAsync(uid, productId, 'product');
}
};
/**
* 收藏品牌
* @function toggleFavBrand
* @param { number } brandId 品牌id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavBrand = (brandId, uid, isadd) => {
if (isadd) {
return favAPI.addFavAsync(uid, brandId, 'brand');
} else {
return favAPI.cancelFavAsync(uid, brandId, 'brand');
}
};
/**
* 收藏店铺
* @function toggleFavShop
* @param { number } shopId 店铺id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavShop = (shopId, uid, isadd) => {
if (isadd) {
return favAPI.addFavAsync(uid, shopId, 'shop');
} else {
return favAPI.cancelFavAsync(uid, shopId, 'shop');
}
};
module.exports = {
toggleFavProduct, // 收藏商品
toggleFavBrand, // 收藏品牌
toggleFavShop // 收藏店铺
};
... ...
... ... @@ -13,6 +13,8 @@ const shopHandler = require('./shop-handler');
const helpers = global.yoho.helpers;
const _ = require('lodash');
const limitNum = 60; // 商品每页显示数目
// 品牌页folder名称
const brandFolderSeries = '经典系列';
... ... @@ -419,12 +421,10 @@ exports.getShopListData = (params) => {
return Promise.all(apiMethod).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {header: true})
// pathNav: searchHandler.handlePathNavData(shopInfo, params, 'shop')
};
// 面包屑导航
// Object.assign(finalResult, searchHandler.handlePathNavData(shopInfo, params, 'shop'));
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop'));
// 店铺介绍
... ... @@ -439,17 +439,24 @@ exports.getShopListData = (params) => {
}
// // 获取商品数据和顶部筛选条件
// if (result[2].code === 200) {
// let allGoods = {
// name: '全部商品 ALL',
// sort: searchHandler.handleOptsData(params, _.get(result[2], 'data.total', 0)),
// list: productProcess.processProductList(_.get(result[2], 'data.product_list', []))
// };
if (result[2].code === 200) {
let tip = {
start: (_.get(result[2], 'data.page', 1) - 1) * limitNum + 1,
total: _.get(result[2], 'data.total', 0)
};
// _.set(allGoods, 'sort.newPage', true); // 启用新的分页导航
tip.end = tip.start + limitNum - 1;
if (tip.end > tip.total) {
tip.end = tip.total;
}
// finalResult.allGoods = allGoods;
// }
Object.assign(finalResult, {
filters: searchHandler.handleFilterData(_.get(result[2], 'data.filter', {}), params),
opts: searchHandler.handleOptsData(params, tip.total),
goods: productProcess.processProductList(_.get(result[2], 'data.product_list', [])),
footPager: {tip: tip}
});
}
if (result[3].code === 200) {
finalResult.leftContent = searchHandler.handleSortData(_.get(result[3],
... ...
... ... @@ -30,9 +30,9 @@ const relateArticleUrl = 'guang/service/v2/article/getArticleByBrand';
*/
const getProductList = (params) => {
let finalParams = {
limit: 60,
method: 'app.search.li',
order: 's_n_desc',
method: 'app.search.li'
limit: 60
};
Object.assign(finalParams, params);
... ...
... ... @@ -13,7 +13,7 @@ const helpers = global.yoho.helpers;
const newProductsName = '新品上架 NEW';
const hotProductsName = '人气单品 HOT';
const shopRecommentName = '经典推荐';
const shopListUrl = '/shoplist';
const shopListUrl = '/product/shoplist';
/**
* 新品上架
... ... @@ -134,22 +134,21 @@ const navigationBar = (data, shopId) => {
},
{
name: '全部商品',
url: `{shopListUrl}/?navBar=1&shopId=${shopId}`
url: `${shopListUrl}/?navBar=1&shopId=${shopId}`
},
{
name: '人气单品',
url: `{shopListUrl}/?navBar=2&shopId=${shopId}`
url: `${shopListUrl}/?navBar=2&shopId=${shopId}`
},
{
name: '新品上架',
url: `{shopListUrl}/?navBar=3&shopId=${shopId}`
url: `${shopListUrl}/?navBar=3&shopId=${shopId}`
}
];
return {navigationBar: _.union(shopNav, _.filter(data, (value) => {
return value.url;
}))
};
}))};
};
/**
... ...
... ... @@ -71,8 +71,8 @@ router.get('/list/new', list.new);
// 品牌页
router.get('/list/brand', list.brand);
// 品牌页
router.get('/shoplist', list.shopList);
router.get('/shoplist', list.shopList); // 店铺列表页
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
// 品牌页水牌
router.post('/index/getNodeContent', list.getNodeContent);
... ...
/**
* 首页
* @author: bikai<kai.bi@yoho.cn>
* @date: 2016/4/26
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var product = require('./index/product');
var $shopIntro = $('.shop-intro'),
$shopCollect = $('.shop-collect'),
// $sliderLeft = $('.slider-left'),
$allGoods = $('.all-goods'),
$fixedArea = $allGoods.find('.fixed-area'),
fixedAreaTop = $fixedArea.offset() ? $fixedArea.offset().top : 0;
// Pjax
// require('yoho-pjax');
require('../common');
require('../plugins/filter');
require('../plugins/sort-pager');
// require('../common/slider');
// require('../product/list');
product.init(4);
lazyLoad($('img.lazy'));
// if ($sliderLeft.length) {
// $sliderLeft.slider();
// }
$shopIntro.on('click', function() {
$('.pop-shop-intro').show();
$('.mask').show();
});
$('.close-btn, .mask').on('click', function() {
$('.pop-shop-intro').hide();
$('.mask').hide();
});
// 收藏店铺
function colloectAction() {
var $colloectIcon = $shopCollect.find('.shop-collect-ico'),
$colloectText = $shopCollect.find('.shop-collect-text'),
isFavorite = $colloectIcon.hasClass('on'),
needColloect = window.cookie('needColloect');
$.ajax({
type: 'post',
url: '/product/shop/togglecollect',
data: {
isFavorite: isFavorite ? 0 : 1,
needColloect: needColloect,
shopId: $shopCollect.data('id')
},
success: function(res) {
if (res.code === 200) {
if (isFavorite) {
$colloectIcon.removeClass('on');
$colloectText.html('收藏');
} else {
$colloectIcon.addClass('on');
$colloectText.html('已收藏');
}
if (needColloect) {
$colloectIcon.addClass('on');
$colloectText.html('已收藏');
}
} else if (res.code === 401) {
window.setCookie('needColloect', '1', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
location.href = res.data.url;
}
}
});
}
$shopCollect.on('click', function() {
colloectAction();
});
if (window.cookie('needColloect') * 1 === 1 && window.getUid()) {
colloectAction();
window.setCookie('needColloect', '', {
path: '/',
domain: '.yohobuy.com',
expires: 1
});
}
// 全部商品使用 pjax 翻页
// $allGoods.pjax('a.pjax', '.goods-wrap', {
// timeout: 5000,
// scrollTo: false // 默认滚动没有动画,禁止掉
// }).on('pjax:end', function() {
// product.init(4);
// lazyLoad($('img.lazy'));
// $fixedArea = $allGoods.find('.fixed-area'); // 翻页后 fixed-area 区域有变化,需要更新选择器
// // 分页后移动到全部商品
// $('html, body').animate({
// scrollTop: $allGoods.offset().top - 30
// });
// }).on('click', '.menu-list li', function() {
// var $this = $(this);
// $this.siblings().removeClass('on');
// $this.addClass('on');
// });
$(window).on('scroll', function() {
var scrollTop = $(this).scrollTop();
if (scrollTop > fixedAreaTop) {
$fixedArea.css({
position: 'fixed',
top: 0
});
} else {
$fixedArea.css({
position: 'static',
top: 0
});
}
});
... ...