Showing
2 changed files
with
22 additions
and
21 deletions
@@ -15,7 +15,7 @@ const favorite = (req, res, next) => { | @@ -15,7 +15,7 @@ const favorite = (req, res, next) => { | ||
15 | let page = 1; | 15 | let page = 1; |
16 | let limit = 10; | 16 | let limit = 10; |
17 | 17 | ||
18 | - favoriteModel.index(uid, page, limit, tab === 'brand').then((result)=>{ | 18 | + req.ctx(favoriteModel).index(uid, page, limit, tab === 'brand').then((result)=>{ |
19 | res.render('favorite', { | 19 | res.render('favorite', { |
20 | module: 'home', | 20 | module: 'home', |
21 | page: 'favorite', | 21 | page: 'favorite', |
@@ -39,7 +39,7 @@ let favProduct = (req, res, next) => { | @@ -39,7 +39,7 @@ let favProduct = (req, res, next) => { | ||
39 | let page = req.query.page || 1; | 39 | let page = req.query.page || 1; |
40 | let limit = 10; | 40 | let limit = 10; |
41 | 41 | ||
42 | - favoriteModel.favProduct(uid, page, limit).then((result) => { | 42 | + req.ctx(favoriteModel).favProduct(uid, page, limit).then((result) => { |
43 | if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') { | 43 | if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') { |
44 | res.render('favorite/favorite-product', { | 44 | res.render('favorite/favorite-product', { |
45 | layout: false, | 45 | layout: false, |
@@ -56,7 +56,7 @@ let favfavBrand = (req, res, next) => { | @@ -56,7 +56,7 @@ let favfavBrand = (req, res, next) => { | ||
56 | let page = req.query.page || 1; | 56 | let page = req.query.page || 1; |
57 | let limit = 10; | 57 | let limit = 10; |
58 | 58 | ||
59 | - favoriteModel.favfavBrand(uid, page, limit).then((result) => { | 59 | + req.ctx(favoriteModel).favfavBrand(uid, page, limit).then((result) => { |
60 | 60 | ||
61 | if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') { | 61 | if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') { |
62 | res.render('favorite/favorite-brand', { | 62 | res.render('favorite/favorite-brand', { |
@@ -75,7 +75,7 @@ let favoriteDelete = (req, res, next) => { | @@ -75,7 +75,7 @@ let favoriteDelete = (req, res, next) => { | ||
75 | let type = 'product'; | 75 | let type = 'product'; |
76 | let favId = req.body.id; | 76 | let favId = req.body.id; |
77 | 77 | ||
78 | - favoriteModel.favoriteDelete(uid, type, favId).then((result) => { | 78 | + req.ctx(favoriteModel).favoriteDelete(uid, type, favId).then((result) => { |
79 | res.json(result); | 79 | res.json(result); |
80 | }).catch(next); | 80 | }).catch(next); |
81 | }; | 81 | }; |
@@ -15,7 +15,12 @@ const _ = require('lodash'); | @@ -15,7 +15,12 @@ const _ = require('lodash'); | ||
15 | const config = global.yoho.config; | 15 | const config = global.yoho.config; |
16 | const helpers = global.yoho.helpers; | 16 | const helpers = global.yoho.helpers; |
17 | 17 | ||
18 | -const favProduct = (uid, page, limit) => { | 18 | +class favoriteIndexModel extends global.yoho.BaseModel { |
19 | + constructor(ctx) { | ||
20 | + super(ctx); | ||
21 | + } | ||
22 | + | ||
23 | + favProduct(uid, page, limit) { | ||
19 | 24 | ||
20 | return api.get('', { | 25 | return api.get('', { |
21 | method: 'app.favorite.product', | 26 | method: 'app.favorite.product', |
@@ -115,10 +120,9 @@ const favProduct = (uid, page, limit) => { | @@ -115,10 +120,9 @@ const favProduct = (uid, page, limit) => { | ||
115 | }; | 120 | }; |
116 | } | 121 | } |
117 | }); | 122 | }); |
118 | -}; | ||
119 | - | ||
120 | -const favfavBrand = (uid, page, limit) => { | 123 | + } |
121 | 124 | ||
125 | + favfavBrand(uid, page, limit) { | ||
122 | return api.get('', { | 126 | return api.get('', { |
123 | method: 'app.favorite.brand', | 127 | method: 'app.favorite.brand', |
124 | uid: uid, | 128 | uid: uid, |
@@ -199,9 +203,9 @@ const favfavBrand = (uid, page, limit) => { | @@ -199,9 +203,9 @@ const favfavBrand = (uid, page, limit) => { | ||
199 | }; | 203 | }; |
200 | } | 204 | } |
201 | }); | 205 | }); |
202 | -}; | 206 | + } |
203 | 207 | ||
204 | -const favoriteDelete = (uid, type, favId) => { | 208 | + favoriteDelete(uid, type, favId) { |
205 | 209 | ||
206 | return api.get('', { | 210 | return api.get('', { |
207 | method: 'app.favorite.cancel', | 211 | method: 'app.favorite.cancel', |
@@ -209,28 +213,25 @@ const favoriteDelete = (uid, type, favId) => { | @@ -209,28 +213,25 @@ const favoriteDelete = (uid, type, favId) => { | ||
209 | type: type, | 213 | type: type, |
210 | fav_id: favId | 214 | fav_id: favId |
211 | }); | 215 | }); |
212 | -}; | ||
213 | -const index = (uid, page, limit, isbrand) => { | 216 | + } |
217 | + | ||
218 | + index(uid, page, limit, isbrand) { | ||
214 | if (isbrand) { | 219 | if (isbrand) { |
215 | - return favfavBrand(uid, page, limit).then(result=> { | 220 | + return this.favfavBrand(uid, page, limit).then(result=> { |
216 | if (result.total === 0) { | 221 | if (result.total === 0) { |
217 | result = {nobrandData: 1}; | 222 | result = {nobrandData: 1}; |
218 | } | 223 | } |
219 | return result; | 224 | return result; |
220 | }); | 225 | }); |
221 | } else { | 226 | } else { |
222 | - return favProduct(uid, page, limit).then(result=> { | 227 | + return this.favProduct(uid, page, limit).then(result=> { |
223 | if (result.total === 0) { | 228 | if (result.total === 0) { |
224 | result = {noproductData: 1}; | 229 | result = {noproductData: 1}; |
225 | } | 230 | } |
226 | return result; | 231 | return result; |
227 | }); | 232 | }); |
228 | } | 233 | } |
229 | -}; | 234 | + } |
235 | +} | ||
230 | 236 | ||
231 | -module.exports = { | ||
232 | - favProduct, | ||
233 | - favfavBrand, | ||
234 | - favoriteDelete, | ||
235 | - index | ||
236 | -}; | 237 | +module.exports = favoriteIndexModel; |
-
Please register or login to post a comment