Authored by 李靖

收藏

... ... @@ -15,7 +15,7 @@ const favorite = (req, res, next) => {
let page = 1;
let limit = 10;
favoriteModel.index(uid, page, limit, tab === 'brand').then((result)=>{
req.ctx(favoriteModel).index(uid, page, limit, tab === 'brand').then((result)=>{
res.render('favorite', {
module: 'home',
page: 'favorite',
... ... @@ -39,7 +39,7 @@ let favProduct = (req, res, next) => {
let page = req.query.page || 1;
let limit = 10;
favoriteModel.favProduct(uid, page, limit).then((result) => {
req.ctx(favoriteModel).favProduct(uid, page, limit).then((result) => {
if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') {
res.render('favorite/favorite-product', {
layout: false,
... ... @@ -56,7 +56,7 @@ let favfavBrand = (req, res, next) => {
let page = req.query.page || 1;
let limit = 10;
favoriteModel.favfavBrand(uid, page, limit).then((result) => {
req.ctx(favoriteModel).favfavBrand(uid, page, limit).then((result) => {
if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') {
res.render('favorite/favorite-brand', {
... ... @@ -75,7 +75,7 @@ let favoriteDelete = (req, res, next) => {
let type = 'product';
let favId = req.body.id;
favoriteModel.favoriteDelete(uid, type, favId).then((result) => {
req.ctx(favoriteModel).favoriteDelete(uid, type, favId).then((result) => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -15,7 +15,12 @@ const _ = require('lodash');
const config = global.yoho.config;
const helpers = global.yoho.helpers;
const favProduct = (uid, page, limit) => {
class favoriteIndexModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
favProduct(uid, page, limit) {
return api.get('', {
method: 'app.favorite.product',
... ... @@ -115,10 +120,9 @@ const favProduct = (uid, page, limit) => {
};
}
});
};
const favfavBrand = (uid, page, limit) => {
}
favfavBrand(uid, page, limit) {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
... ... @@ -199,9 +203,9 @@ const favfavBrand = (uid, page, limit) => {
};
}
});
};
}
const favoriteDelete = (uid, type, favId) => {
favoriteDelete(uid, type, favId) {
return api.get('', {
method: 'app.favorite.cancel',
... ... @@ -209,28 +213,25 @@ const favoriteDelete = (uid, type, favId) => {
type: type,
fav_id: favId
});
};
const index = (uid, page, limit, isbrand) => {
}
index(uid, page, limit, isbrand) {
if (isbrand) {
return favfavBrand(uid, page, limit).then(result=> {
return this.favfavBrand(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {nobrandData: 1};
}
return result;
});
} else {
return favProduct(uid, page, limit).then(result=> {
return this.favProduct(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {noproductData: 1};
}
return result;
});
}
};
}
}
module.exports = {
favProduct,
favfavBrand,
favoriteDelete,
index
};
module.exports = favoriteIndexModel;
... ...