Authored by htoooth

add fav

... ... @@ -142,7 +142,20 @@ const isFavShop = (req, res, next) => {
};
const num = (req, res, next) => {
let bid = req.query.bid;
let sid = req.query.sid;
if (sid) {
return brandService.getShopFavNumAsync(sid).then((result) => {
res.json(result);
}).catch(next);
}
if (bid) {
return brandService.getBrandFavNumAsync(bid).then((result) => {
res.json(result);
}).catch(next);
}
};
module.exports = {
... ...
... ... @@ -1115,6 +1115,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
result.name = propOrigin('product_name');
result.skn = propOrigin('product_skn');
result.productId = propOrigin('product_id');
result.shopId = propOrigin('shop_id', 0);
result.maxSortId = propOrigin('maxSortId', '');
result.smallSortId = propOrigin('smallSortId', '');
... ...
... ... @@ -5,6 +5,8 @@
'use strict';
const api = require('./favorite-api');
const serviceApi = global.yoho.ServiceAPI;
const _ = require('lodash');
const isFavoriteAsync = _.partial(api.isFavAsync, _, _, 'brand');
... ... @@ -13,8 +15,24 @@ const addFavAsync = _.partial(api.addFavAsync, _, _, 'brand');
const cancelFavAsync = _.partial(api.cancelFavAsync, _, _, 'brand');
const getShopFavNumAsync = (sid) => {
return serviceApi.get('brower/favorite/queryBrandFavoriteCount', {
favIds: [sid],
type: 'shop'
});
};
const getBrandIdNumAsync = (bid) => {
return serviceApi.get('brower/favorite/queryBrandFavoriteCount', {
brandId: bid,
type: 'brand'
});
};
module.exports = {
isFavoriteAsync,
addFavAsync,
cancelFavAsync
cancelFavAsync,
getShopFavNumAsync,
getBrandIdNumAsync
};
... ...
... ... @@ -5,6 +5,7 @@
'use strict';
const api = require('./favorite-brand-api');
const _ = require('lodash');
const changeAsync = (type, uid, brandId) => {
switch (type) {
... ... @@ -17,10 +18,48 @@ const changeAsync = (type, uid, brandId) => {
}
};
const getShopFavNumAsync = (sid) => {
return api.getShopFavNumAsync(sid).then((result) => {
if (result.code === 200) {
return {
code: 200,
data: {
count: _.get(result, 'data.count')
}
};
} else {
return {
code: 500,
message: '服务器错误'
};
}
});
};
const getBrandFavNumAsync = (bid) => {
return api.getBrandIdNumAsync(bid).then((result) => {
if (result.code === 200) {
return {
code: 200,
data: {
count: _.get(result, 'data.count')
}
};
} else {
return {
code: 500,
message: '服务器错误'
};
}
});
};
const isFavoriteAsync = api.isFavoriteAsync;
module.exports = {
changeAsync,
isFavoriteAsync
isFavoriteAsync,
getShopFavNumAsync,
getBrandFavNumAsync
};
... ...
... ... @@ -71,7 +71,7 @@ router.get('/detail/header', detail.productHeader); // 价
router.get('/detail/return', detail.detailReturn); // 特殊商品退换货
router.get('/detail/recommend', detail.recommend); // 推荐商品
router.get('/index/isfav', favorite.isFavoriteBrand); // 品牌收藏状态
router.get('/index/favnum', favorite.num); // 收藏数量
router.get('/index/favnum', favorite.num); // 收藏数量(先店铺,后品牌)
router.get('/detail/coupon', auth, coupon.acquire); // 获得优惠券
router.get('/detail/getPacakge', detail.getPackage); // 获取套餐
router.get('/detail/notify/status', auth, notify.show); // 到货通知状态
... ... @@ -102,8 +102,8 @@ router.get('/shop/couponsync', list.shopCouponSync);
router.get('/brand/couponsync', list.brandCouponSync);
router.get('/shoplist', list.shopList); // 店铺列表页
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
router.post('/shop/togglecollect', auth, favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏店铺
// 品牌页水牌
router.post('/index/getNodeContent', list.getNodeContent);
... ...
... ... @@ -29,7 +29,8 @@
data-md5="{{goodsInfo.md5}}"
data-limitcode="{{goodsInfo.limitProductCode}}"
data-count="{{goodsInfo.bundle.count}}"
data-type="{{goodsInfo.bundle.type}}">
data-type="{{goodsInfo.bundle.type}}"
data-shop="{{goodsInfo.shopId}}">
{{> product/detail-header}}
</div>
{{/if}}
... ...
... ... @@ -24,6 +24,7 @@ var Dialog = require('../common/dialog').Dialog;
var $main = $('.main'),
id = $main.data('id'),
shopId = $main.data('shop'),
md5 = $main.data('md5'),
skn = $main.data('skn'),
deposit = $main.data('deposit') === 'Y',
... ... @@ -1571,17 +1572,19 @@ bindEvent.fire();
});
// 品牌收藏
$.ajax({
type: 'GET',
url: '/product/index/isfav',
data: {
brandId: $('#brand-favour').data('id')
}
}).then(function(result) {
if (result.code === 200 && result.data) {
$('#brand-favour').addClass('coled');
}
});
if (getUid()) {
$.ajax({
type: 'GET',
url: '/product/index/isfav',
data: {
brandId: $('#brand-favour').data('id')
}
}).then(function(result) {
if (result.code === 200 && result.data) {
$('#brand-favour').addClass('coled');
}
});
}
}());
... ...
var $ = require('yoho-jquery');
module.exports.getFavNum = function(sid, bid) {
return $.getJSON('/product/index/favnum', {sid: sid, bid: bid});
};
module.exports.addFav = function(sid, bid) {
if (!getUid()) {
return window.jumpUrl(window.signinUrl());
}
if (sid) {
return $.post('/product/shop/togglecollect', {
isFavorite: 0,
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise(); //eslint-disable-line
} if (result.code === 401) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.post('/product/index/favoriteBrand', {
type: 'add',
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else if (result.code === 403) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
module.exports.cancelFav = function(sid, bid) {
if (!getUid()) {
return window.jumpUrl(window.signinUrl());
}
if (sid) {
return $.post('/product/shop/togglecollect', {
isFavorite: 1,
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
}
if (result.code === 401) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.post('/product/index/favoriteBrand', {
type: 'cancel',
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else if (result.code === 403) {
return window.jumpUrl(window.signinUrl());
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
module.exports.statusFav = function(sid, bid) {
if (sid) {
return $.post('/product/index/isFavoriteShop', {
shopId: sid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
if (bid) {
return $.getJSON('/product/index/isfav', {
brandId: bid
}).then(function(result) {
if (result.code === 200) {
return $.Deferred().resolve().promise();//eslint-disable-line
} else {
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
};
... ...
... ... @@ -49,6 +49,6 @@ function addAsync(skn, sku) {
}
module.exports = {
statusAsync,
addAsync
statusAsync: statusAsync,
addAsync: addAsync
};
... ...