Showing
3 changed files
with
88 additions
and
86 deletions
@@ -33,7 +33,7 @@ const praiseArticle = (req, res, next) => { | @@ -33,7 +33,7 @@ const praiseArticle = (req, res, next) => { | ||
33 | } | 33 | } |
34 | 34 | ||
35 | /* 执行点赞或取消操作 */ | 35 | /* 执行点赞或取消操作 */ |
36 | - return optModel.praiseArticle(udid, id, opt).then((data) => { | 36 | + return req.ctx(optModel).praiseArticle(udid, id, opt).then((data) => { |
37 | res.json(data); | 37 | res.json(data); |
38 | }).catch(next); | 38 | }).catch(next); |
39 | }; | 39 | }; |
@@ -73,7 +73,7 @@ const collectArticle = (req, res, next) => { | @@ -73,7 +73,7 @@ const collectArticle = (req, res, next) => { | ||
73 | } | 73 | } |
74 | 74 | ||
75 | /* 执行收藏或取消操作 */ | 75 | /* 执行收藏或取消操作 */ |
76 | - return optModel.collectArticle(uid, id, opt).then(data => { | 76 | + return req.ctx(optModel).collectArticle(uid, id, opt).then(data => { |
77 | if (!data) { | 77 | if (!data) { |
78 | res.json({ | 78 | res.json({ |
79 | code: 400, | 79 | code: 400, |
@@ -121,7 +121,7 @@ const favoriteBrand = (req, res, next) => { | @@ -121,7 +121,7 @@ const favoriteBrand = (req, res, next) => { | ||
121 | } | 121 | } |
122 | 122 | ||
123 | // 执行收藏或取消操作 | 123 | // 执行收藏或取消操作 |
124 | - return brandModel.favoriteBrand(uid, id, opt, isBrand).then(data => { | 124 | + return req.ctx(brandModel).favoriteBrand(uid, id, opt, isBrand).then(data => { |
125 | if (!data) { | 125 | if (!data) { |
126 | res.json({ | 126 | res.json({ |
127 | code: 400, | 127 | code: 400, |
@@ -6,31 +6,33 @@ | @@ -6,31 +6,33 @@ | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | const api = global.yoho.API; | 7 | const api = global.yoho.API; |
8 | 8 | ||
9 | -/** | ||
10 | - * [收藏品牌或者商品] | ||
11 | - * @param {[int]} uid [用户ID] | ||
12 | - * @param {[int]} id [品牌ID] | ||
13 | - * @param {Boolean} isBrand [是品牌还是商品] | ||
14 | - * @param {string} opt [操作(ok:表示确定,cancel:表示取消)] | ||
15 | - * @return {[array]} | ||
16 | - */ | ||
17 | -const favoriteBrand = (uid, id, opt, isBrand) => { | ||
18 | - let param = { | ||
19 | - uid: uid, | ||
20 | - type: isBrand ? 'brand' : 'product' | ||
21 | - }; | ||
22 | 9 | ||
23 | - if (opt === 'ok') { | ||
24 | - param.id = id; | ||
25 | - param.method = 'app.favorite.add'; | ||
26 | - } else { | ||
27 | - param.fav_id = id; | ||
28 | - param.method = 'app.favorite.cancel'; | 10 | +module.exports = class extends global.yoho.BaseModel { |
11 | + constructor(ctx) { | ||
12 | + super(ctx); | ||
29 | } | 13 | } |
30 | - return api.post('', param); | ||
31 | -}; | ||
32 | 14 | ||
15 | + /** | ||
16 | + * [收藏品牌或者商品] | ||
17 | + * @param {[int]} uid [用户ID] | ||
18 | + * @param {[int]} id [品牌ID] | ||
19 | + * @param {Boolean} isBrand [是品牌还是商品] | ||
20 | + * @param {string} opt [操作(ok:表示确定,cancel:表示取消)] | ||
21 | + * @return {[array]} | ||
22 | + */ | ||
23 | + favoriteBrand(uid, id, opt, isBrand) { | ||
24 | + let param = { | ||
25 | + uid: uid, | ||
26 | + type: isBrand ? 'brand' : 'product' | ||
27 | + }; | ||
33 | 28 | ||
34 | -module.exports = { | ||
35 | - favoriteBrand | 29 | + if (opt === 'ok') { |
30 | + param.id = id; | ||
31 | + param.method = 'app.favorite.add'; | ||
32 | + } else { | ||
33 | + param.fav_id = id; | ||
34 | + param.method = 'app.favorite.cancel'; | ||
35 | + } | ||
36 | + return api.post('', param); | ||
37 | + } | ||
36 | }; | 38 | }; |
@@ -7,75 +7,75 @@ | @@ -7,75 +7,75 @@ | ||
7 | const serviceAPI = global.yoho.ServiceAPI; | 7 | const serviceAPI = global.yoho.ServiceAPI; |
8 | const api = global.yoho.API; | 8 | const api = global.yoho.API; |
9 | 9 | ||
10 | -/** | ||
11 | - * [逛资讯点赞/取消赞] | ||
12 | - * @param {[int]} udid [唯一客户端标识] | ||
13 | - * @param {[int]} id [唯一资讯的ID] | ||
14 | - * @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)] | ||
15 | - * @return {[array]} | ||
16 | - */ | ||
17 | -const praiseArticle = (udid, id, opt) => { | ||
18 | - let param = { | ||
19 | - article_id: id, | ||
20 | - udid: udid | ||
21 | - }; | 10 | +module.exports = class extends global.yoho.BaseModel { |
11 | + constructor(ctx) { | ||
12 | + super(ctx); | ||
13 | + } | ||
14 | + | ||
15 | + /** | ||
16 | + * [逛资讯点赞/取消赞] | ||
17 | + * @param {[int]} udid [唯一客户端标识] | ||
18 | + * @param {[int]} id [唯一资讯的ID] | ||
19 | + * @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)] | ||
20 | + * @return {[array]} | ||
21 | + */ | ||
22 | + praiseArticle(udid, id, opt) { | ||
23 | + let param = { | ||
24 | + article_id: id, | ||
25 | + udid: udid | ||
26 | + }; | ||
22 | 27 | ||
23 | - if (opt === 'cancel') { | ||
24 | - return serviceAPI.get('guang/api/v2/praise/cancel', param); | ||
25 | - } else { | ||
26 | - return serviceAPI.get('guang/api/v2/praise/setPraise', param); | 28 | + if (opt === 'cancel') { |
29 | + return serviceAPI.get('guang/api/v2/praise/cancel', param); | ||
30 | + } else { | ||
31 | + return serviceAPI.get('guang/api/v2/praise/setPraise', param); | ||
32 | + } | ||
27 | } | 33 | } |
28 | -}; | ||
29 | 34 | ||
30 | -/** | ||
31 | - * [逛资讯收藏/取消收藏 (APP里调用)] | ||
32 | - * @param {[int]} uid [用户id] | ||
33 | - * @param {[int]} id [唯一资讯的ID] | ||
34 | - * @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)] | ||
35 | - * @return {[array]} | ||
36 | - */ | ||
37 | -const collectArticle = (uid, id, opt) => { | ||
38 | - let param = { | ||
39 | - article_id: id, | ||
40 | - uid: uid | ||
41 | - }; | 35 | + /** |
36 | + * [逛资讯收藏/取消收藏 (APP里调用)] | ||
37 | + * @param {[int]} uid [用户id] | ||
38 | + * @param {[int]} id [唯一资讯的ID] | ||
39 | + * @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)] | ||
40 | + * @return {[array]} | ||
41 | + */ | ||
42 | + collectArticle(uid, id, opt) { | ||
43 | + let param = { | ||
44 | + article_id: id, | ||
45 | + uid: uid | ||
46 | + }; | ||
42 | 47 | ||
43 | - if (opt === 'cancel') { | ||
44 | - return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', param); | ||
45 | - } else { | ||
46 | - return serviceAPI.get('guang/api/v1/favorite/setFavorite', param); | 48 | + if (opt === 'cancel') { |
49 | + return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', param); | ||
50 | + } else { | ||
51 | + return serviceAPI.get('guang/api/v1/favorite/setFavorite', param); | ||
52 | + } | ||
47 | } | 53 | } |
48 | -}; | ||
49 | 54 | ||
50 | -// 品牌收藏 | 55 | + // 品牌收藏 |
51 | 56 | ||
52 | -const favoriteBrand = (uid, id, opt) => { | ||
53 | - let param; | 57 | + favoriteBrand(uid, id, opt) { |
58 | + let param; | ||
54 | 59 | ||
55 | - if (opt === 'ok') { | ||
56 | - param = { | ||
57 | - id: id, | ||
58 | - uid: uid, | ||
59 | - type: 'brand' | ||
60 | - }; | ||
61 | - } else { | ||
62 | - param = { | ||
63 | - fav_id: id, | ||
64 | - uid: uid, | ||
65 | - type: 'brand' | ||
66 | - }; | ||
67 | - } | 60 | + if (opt === 'ok') { |
61 | + param = { | ||
62 | + id: id, | ||
63 | + uid: uid, | ||
64 | + type: 'brand' | ||
65 | + }; | ||
66 | + } else { | ||
67 | + param = { | ||
68 | + fav_id: id, | ||
69 | + uid: uid, | ||
70 | + type: 'brand' | ||
71 | + }; | ||
72 | + } | ||
68 | 73 | ||
69 | 74 | ||
70 | - if (opt === 'ok') { | ||
71 | - return api.get('app.favorite.add', param); | ||
72 | - } else { | ||
73 | - return api.get('app.favorite.cancel', param); | 75 | + if (opt === 'ok') { |
76 | + return api.get('app.favorite.add', param); | ||
77 | + } else { | ||
78 | + return api.get('app.favorite.cancel', param); | ||
79 | + } | ||
74 | } | 80 | } |
75 | }; | 81 | }; |
76 | - | ||
77 | -module.exports = { | ||
78 | - praiseArticle, | ||
79 | - collectArticle, | ||
80 | - favoriteBrand | ||
81 | -}; |
-
Please register or login to post a comment