Merge branch 'release/1019'
Showing
4 changed files
with
38 additions
and
21 deletions
@@ -17,10 +17,10 @@ const changeFavoriteBrand = (req, res, next) => { | @@ -17,10 +17,10 @@ const changeFavoriteBrand = (req, res, next) => { | ||
17 | 17 | ||
18 | if (uid && brandId) { | 18 | if (uid && brandId) { |
19 | brandService.changeAsync(uid, brandId).then(result => { | 19 | brandService.changeAsync(uid, brandId).then(result => { |
20 | - res.json(result); | 20 | + return res.json(result); |
21 | }).catch(next); | 21 | }).catch(next); |
22 | } else if (!uid) { | 22 | } else if (!uid) { |
23 | - res.json({ | 23 | + return res.json({ |
24 | code: 403, | 24 | code: 403, |
25 | message: '用户ID不存在', | 25 | message: '用户ID不存在', |
26 | data: { | 26 | data: { |
@@ -28,13 +28,29 @@ const changeFavoriteBrand = (req, res, next) => { | @@ -28,13 +28,29 @@ const changeFavoriteBrand = (req, res, next) => { | ||
28 | } | 28 | } |
29 | }); | 29 | }); |
30 | } else { | 30 | } else { |
31 | - res.json({ | 31 | + return res.json({ |
32 | code: 400, | 32 | code: 400, |
33 | message: '操作失败' | 33 | message: '操作失败' |
34 | }); | 34 | }); |
35 | } | 35 | } |
36 | }; | 36 | }; |
37 | 37 | ||
38 | +const isFavoriteBrand = (req, res, next) => { | ||
39 | + let uid = req.user.uid || ''; | ||
40 | + let brandId = req.query.brandId; | ||
41 | + | ||
42 | + if (uid && brandId) { | ||
43 | + brandService.isFavoriteAsync(uid, brandId).then(result => { | ||
44 | + return res.json(result); | ||
45 | + }).catch(next); | ||
46 | + } else { | ||
47 | + return res.json({ | ||
48 | + code: 400, | ||
49 | + message: '状态失败' | ||
50 | + }); | ||
51 | + } | ||
52 | +}; | ||
53 | + | ||
38 | const collectProduct = (req, res, next) => { | 54 | const collectProduct = (req, res, next) => { |
39 | let uid = req.user.uid || ''; | 55 | let uid = req.user.uid || ''; |
40 | let pid = req.body.productId; | 56 | let pid = req.body.productId; |
@@ -43,7 +59,6 @@ const collectProduct = (req, res, next) => { | @@ -43,7 +59,6 @@ const collectProduct = (req, res, next) => { | ||
43 | if (uid && pid) { | 59 | if (uid && pid) { |
44 | switch (type) { | 60 | switch (type) { |
45 | case 'add': | 61 | case 'add': |
46 | - { | ||
47 | productService.createAsync(uid, pid) | 62 | productService.createAsync(uid, pid) |
48 | .then(result => { | 63 | .then(result => { |
49 | if (result.code === 413) { | 64 | if (result.code === 413) { |
@@ -54,22 +69,17 @@ const collectProduct = (req, res, next) => { | @@ -54,22 +69,17 @@ const collectProduct = (req, res, next) => { | ||
54 | }) | 69 | }) |
55 | .catch(next); | 70 | .catch(next); |
56 | break; | 71 | break; |
57 | - } | ||
58 | case 'cancel': | 72 | case 'cancel': |
59 | - { | ||
60 | productService.deleteAsync(uid, pid) | 73 | productService.deleteAsync(uid, pid) |
61 | .then(result => res.json(result)) | 74 | .then(result => res.json(result)) |
62 | .catch(next); | 75 | .catch(next); |
63 | break; | 76 | break; |
64 | - } | ||
65 | default: | 77 | default: |
66 | - { | ||
67 | res.json({ | 78 | res.json({ |
68 | code: 400, | 79 | code: 400, |
69 | message: '错误类型' | 80 | message: '错误类型' |
70 | }); | 81 | }); |
71 | } | 82 | } |
72 | - } | ||
73 | } else if (!uid) { | 83 | } else if (!uid) { |
74 | res.json({ | 84 | res.json({ |
75 | code: 403, | 85 | code: 403, |
@@ -117,5 +127,6 @@ const collectShop = (req, res, next) => { | @@ -117,5 +127,6 @@ const collectShop = (req, res, next) => { | ||
117 | module.exports = { | 127 | module.exports = { |
118 | changeFavoriteBrand, | 128 | changeFavoriteBrand, |
119 | collectProduct, | 129 | collectProduct, |
120 | - collectShop | 130 | + collectShop, |
131 | + isFavoriteBrand | ||
121 | }; | 132 | }; |
@@ -67,7 +67,7 @@ const _getProductIntroAsync = (productId, productSkn) => { | @@ -67,7 +67,7 @@ const _getProductIntroAsync = (productId, productSkn) => { | ||
67 | * pid : product id | 67 | * pid : product id |
68 | * bid : brand id | 68 | * bid : brand id |
69 | */ | 69 | */ |
70 | -const _getProductFavoriteDataAsync = (uid, pid, bid) => { | 70 | +const _getProductFavoriteDataAsync = (uid, pid) => { |
71 | return co(function*() { | 71 | return co(function*() { |
72 | let result = { | 72 | let result = { |
73 | product: false, | 73 | product: false, |
@@ -84,23 +84,14 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => { | @@ -84,23 +84,14 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => { | ||
84 | requestApi.product = favoriteProductService.isFavoriteAsync(uid, pid); | 84 | requestApi.product = favoriteProductService.isFavoriteAsync(uid, pid); |
85 | } | 85 | } |
86 | 86 | ||
87 | - if (bid) { | ||
88 | - requestApi.brand = favoriteBrandService.isFavoriteAsync(uid, bid); | ||
89 | - } | ||
90 | - | ||
91 | let requestData = yield Promise.props(requestApi); | 87 | let requestData = yield Promise.props(requestApi); |
92 | 88 | ||
93 | let productData = requestData.product; | 89 | let productData = requestData.product; |
94 | - let brandData = requestData.brand; | ||
95 | 90 | ||
96 | if (productData) { | 91 | if (productData) { |
97 | result.product = productData.code === 200 && productData.data ? true : false; | 92 | result.product = productData.code === 200 && productData.data ? true : false; |
98 | } | 93 | } |
99 | 94 | ||
100 | - if (brandData) { | ||
101 | - result.brand = brandData.code && brandData.code === 200 ? true : false; | ||
102 | - } | ||
103 | - | ||
104 | return result; | 95 | return result; |
105 | })(); | 96 | })(); |
106 | }; | 97 | }; |
@@ -1076,7 +1067,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => { | @@ -1076,7 +1067,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => { | ||
1076 | 1067 | ||
1077 | let requestApi = { | 1068 | let requestApi = { |
1078 | addition: _getProductAdditionInfoAsync(origin), // 预处理所有的数据 | 1069 | addition: _getProductAdditionInfoAsync(origin), // 预处理所有的数据 |
1079 | - fav: _getProductFavoriteDataAsync(uid, result.productId, brandId), // 处理收藏喜欢数据 | 1070 | + fav: _getProductFavoriteDataAsync(uid, result.productI), // 处理收藏喜欢数据 |
1080 | promotion: productAPI.getPromotionAsync(result.skn) // 打折信息 | 1071 | promotion: productAPI.getPromotionAsync(result.skn) // 打折信息 |
1081 | }; | 1072 | }; |
1082 | 1073 |
@@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品 | @@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品 | ||
61 | router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品 | 61 | router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品 |
62 | router.get('/detail/header', detail.productHeader); // 价格数据重新获取接口 | 62 | router.get('/detail/header', detail.productHeader); // 价格数据重新获取接口 |
63 | router.get('/detail/return', detail.detailReturn);// 特殊商品退换货 | 63 | router.get('/detail/return', detail.detailReturn);// 特殊商品退换货 |
64 | +router.get('/index/isfav', favorite.isFavoriteBrand);// 品牌收藏状态 | ||
64 | 65 | ||
65 | // 搜索 | 66 | // 搜索 |
66 | router.get('/search/index', search.index); | 67 | router.get('/search/index', search.index); |
@@ -809,6 +809,20 @@ window.fetchReturn = fetchReturn; | @@ -809,6 +809,20 @@ window.fetchReturn = fetchReturn; | ||
809 | $('.main').html(result); | 809 | $('.main').html(result); |
810 | bindEvent.fire(); | 810 | bindEvent.fire(); |
811 | }); | 811 | }); |
812 | + | ||
813 | + $.ajax({ | ||
814 | + type: 'GET', | ||
815 | + url: '/product/index/isfav', | ||
816 | + dataType: 'html', | ||
817 | + data: { | ||
818 | + brandId: $('#brand-favour').data('id') | ||
819 | + } | ||
820 | + }).then(function(result) { | ||
821 | + if (result.code === 200) { | ||
822 | + $('#brand-favour').toggleClass('coled'); | ||
823 | + } | ||
824 | + }); | ||
825 | + | ||
812 | }()); | 826 | }()); |
813 | 827 | ||
814 | // 数据懒加载 | 828 | // 数据懒加载 |
-
Please register or login to post a comment