Showing
4 changed files
with
69 additions
and
3 deletions
apps/product/controllers/favorite.js
0 → 100644
1 | +/** | ||
2 | + * Created by TaoHuang on 2016/6/13. | ||
3 | + */ | ||
4 | +'use strict'; | ||
5 | + | ||
6 | +const helpers = require(`${library}/helpers`); | ||
7 | + | ||
8 | +const mRoot = '../models'; | ||
9 | +const service = require(`${mRoot}/favorite-service`); | ||
10 | + | ||
11 | +/** | ||
12 | + * 收藏品牌ajax请求 | ||
13 | + */ | ||
14 | +module.exports.changeFavoriteBrand = (req, res, next) => { | ||
15 | + // TODO: uid get | ||
16 | + let uid = ''; | ||
17 | + let brandId = req.body.brandId; | ||
18 | + | ||
19 | + if (uid && brandId) { | ||
20 | + service.changeFavoriteBrandAsync(uid, brandId).then(result => { | ||
21 | + res.json(result) | ||
22 | + }).catch(next); | ||
23 | + } else if (!uid) { | ||
24 | + res.json({ | ||
25 | + code: 403, | ||
26 | + message: '用户ID不存在', | ||
27 | + data: { | ||
28 | + url: helpers.urlFormat('/signin.html') | ||
29 | + } | ||
30 | + }); | ||
31 | + } else { | ||
32 | + res.json({ | ||
33 | + code: 400, | ||
34 | + message: '操作失败' | ||
35 | + }); | ||
36 | + } | ||
37 | +}; |
@@ -5,7 +5,7 @@ const sign = require(`${library}/sign`); | @@ -5,7 +5,7 @@ const sign = require(`${library}/sign`); | ||
5 | const api = new API(); | 5 | const api = new API(); |
6 | const serviceAPI = new ServiceAPI(); | 6 | const serviceAPI = new ServiceAPI(); |
7 | 7 | ||
8 | -module.exports.getUidProductFavAsync = function(uid, pid, isUrl) { | 8 | +module.exports.getUidProductFavAsync = function (uid, pid, isUrl) { |
9 | isUrl; | 9 | isUrl; |
10 | return api.get('', sign.apiSign({ | 10 | return api.get('', sign.apiSign({ |
11 | method: 'app.favorite.isFavorite', | 11 | method: 'app.favorite.isFavorite', |
@@ -15,9 +15,16 @@ module.exports.getUidProductFavAsync = function(uid, pid, isUrl) { | @@ -15,9 +15,16 @@ module.exports.getUidProductFavAsync = function(uid, pid, isUrl) { | ||
15 | })); | 15 | })); |
16 | }; | 16 | }; |
17 | 17 | ||
18 | -module.exports.isFavoriteBrandAsync = function(uid, bid) { | 18 | +module.exports.isFavoriteBrandAsync = function (uid, bid) { |
19 | return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', sign.apiSign({ | 19 | return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', sign.apiSign({ |
20 | uid: uid, | 20 | uid: uid, |
21 | brandId: bid | 21 | brandId: bid |
22 | })); | 22 | })); |
23 | }; | 23 | }; |
24 | + | ||
25 | +module.exports.changeFavoriteBrandAsync = function (uid, brandId) { | ||
26 | + return serviceAPI.get('guang/service/v2/favorite/toggleBrand', sign.apiSign({ | ||
27 | + uid: uid, | ||
28 | + brand_id: brandId | ||
29 | + })).catch(console.log); | ||
30 | +}; |
apps/product/models/favorite-service.js
0 → 100644
1 | +/** | ||
2 | + * Created by TaoHuang on 2016/6/13. | ||
3 | + */ | ||
4 | + | ||
5 | +'use strict'; | ||
6 | + | ||
7 | +const Promise = require('bluebird'); | ||
8 | +const co = Promise.coroutine; | ||
9 | +const moment = require('moment'); | ||
10 | +const _ = require('lodash'); | ||
11 | + | ||
12 | +const favoriteAPI = require('./favorite-api'); | ||
13 | + | ||
14 | +module.exports.changeFavoriteBrandAsync = (uid, brandId) => { | ||
15 | + return favoriteAPI.changeFavoriteBrandAsync(uid, brandId); | ||
16 | +} |
@@ -12,12 +12,16 @@ const cRoot = './controllers'; | @@ -12,12 +12,16 @@ const cRoot = './controllers'; | ||
12 | // 商品详情controller | 12 | // 商品详情controller |
13 | const detail = require(`${cRoot}/detail`); | 13 | const detail = require(`${cRoot}/detail`); |
14 | 14 | ||
15 | +// 收藏品牌 | ||
16 | +const favorite = require(`${cRoot}/favorite`); | ||
17 | + | ||
15 | // 商品促销controller | 18 | // 商品促销controller |
16 | const sale = require(`${cRoot}/sale`); | 19 | const sale = require(`${cRoot}/sale`); |
17 | 20 | ||
18 | // 奥特莱斯controller | 21 | // 奥特莱斯controller |
19 | const outlets = require(`${cRoot}/outlets`); | 22 | const outlets = require(`${cRoot}/outlets`); |
20 | 23 | ||
24 | + | ||
21 | // 商品促销routers | 25 | // 商品促销routers |
22 | router.get('/sale', sale.index); // sale 首页 | 26 | router.get('/sale', sale.index); // sale 首页 |
23 | router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页 | 27 | router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页 |
@@ -42,7 +46,9 @@ router.get('/detail/consult', detail.indexConsult); | @@ -42,7 +46,9 @@ router.get('/detail/consult', detail.indexConsult); | ||
42 | router.post('/detail/consult', detail.createConsult); | 46 | router.post('/detail/consult', detail.createConsult); |
43 | 47 | ||
44 | // 商品热图 | 48 | // 商品热图 |
45 | -router.get('/detail/hotarea',detail.indexHotArea); | 49 | +router.get('/detail/hotarea', detail.indexHotArea); |
46 | 50 | ||
51 | +// 收藏品牌 | ||
52 | +router.post('/index/favoriteBrand', favorite.changeFavoriteBrand); | ||
47 | 53 | ||
48 | module.exports = router; | 54 | module.exports = router; |
-
Please register or login to post a comment