Authored by htoooth

add favorite

/**
* Created by TaoHuang on 2016/6/13.
*/
'use strict';
const helpers = require(`${library}/helpers`);
const mRoot = '../models';
const service = require(`${mRoot}/favorite-service`);
/**
* 收藏品牌ajax请求
*/
module.exports.changeFavoriteBrand = (req, res, next) => {
// TODO: uid get
let uid = '';
let brandId = req.body.brandId;
if (uid && brandId) {
service.changeFavoriteBrandAsync(uid, brandId).then(result => {
res.json(result)
}).catch(next);
} else if (!uid) {
res.json({
code: 403,
message: '用户ID不存在',
data: {
url: helpers.urlFormat('/signin.html')
}
});
} else {
res.json({
code: 400,
message: '操作失败'
});
}
};
... ...
... ... @@ -5,7 +5,7 @@ const sign = require(`${library}/sign`);
const api = new API();
const serviceAPI = new ServiceAPI();
module.exports.getUidProductFavAsync = function(uid, pid, isUrl) {
module.exports.getUidProductFavAsync = function (uid, pid, isUrl) {
isUrl;
return api.get('', sign.apiSign({
method: 'app.favorite.isFavorite',
... ... @@ -15,9 +15,16 @@ module.exports.getUidProductFavAsync = function(uid, pid, isUrl) {
}));
};
module.exports.isFavoriteBrandAsync = function(uid, bid) {
module.exports.isFavoriteBrandAsync = function (uid, bid) {
return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', sign.apiSign({
uid: uid,
brandId: bid
}));
};
module.exports.changeFavoriteBrandAsync = function (uid, brandId) {
return serviceAPI.get('guang/service/v2/favorite/toggleBrand', sign.apiSign({
uid: uid,
brand_id: brandId
})).catch(console.log);
};
... ...
/**
* Created by TaoHuang on 2016/6/13.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const moment = require('moment');
const _ = require('lodash');
const favoriteAPI = require('./favorite-api');
module.exports.changeFavoriteBrandAsync = (uid, brandId) => {
return favoriteAPI.changeFavoriteBrandAsync(uid, brandId);
}
... ...
... ... @@ -12,12 +12,16 @@ const cRoot = './controllers';
// 商品详情controller
const detail = require(`${cRoot}/detail`);
// 收藏品牌
const favorite = require(`${cRoot}/favorite`);
// 商品促销controller
const sale = require(`${cRoot}/sale`);
// 奥特莱斯controller
const outlets = require(`${cRoot}/outlets`);
// 商品促销routers
router.get('/sale', sale.index); // sale 首页
router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页
... ... @@ -42,7 +46,9 @@ router.get('/detail/consult', detail.indexConsult);
router.post('/detail/consult', detail.createConsult);
// 商品热图
router.get('/detail/hotarea',detail.indexHotArea);
router.get('/detail/hotarea', detail.indexHotArea);
// 收藏品牌
router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);
module.exports = router;
... ...