favorite.js
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* 个人中心我的收藏
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/08/16
*/
'use strict';
const favoriteModel = require('../models/favorite');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const favorite = (req, res, next) => {
let tab = req.query.tab || '';
let uid = req.user.uid;
let page = 1;
let limit = 10;
req.ctx(favoriteModel).index(uid, page, limit, tab === 'brand').then((result)=>{
res.render('favorite', {
module: 'home',
page: 'favorite',
pageHeader: headerModel.setNav({
navTitle: '我的收藏'
}),
title: '我的收藏',
pageFooter: true,
localCss: true,
favorite: Object.assign(result, {
productUrl: '//m.yohobuy.com/product/new',
brandUrl: '//m.yohobuy.com/product/new',
brandTab: tab === 'brand' ? true : false // 是否为品牌收藏页
})
});
}).catch(next);
};
let favProduct = (req, res, next) => {
let uid = req.user.uid;
let page = req.query.page || 1;
let limit = 10;
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,
hasFavProduct: result.hasFavProduct
});
} else {
res.json(result);
}
}).catch(next);
};
let favfavBrand = (req, res, next) => {
let uid = req.user.uid;
let page = req.query.page || 1;
let limit = 10;
req.ctx(favoriteModel).favfavBrand(uid, page, limit).then((result) => {
if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') {
res.render('favorite/favorite-brand', {
layout: false,
hasFavBrand: result.hasFavBrand
});
} else {
res.json(result);
}
}).catch(next);
};
let favoriteDelete = (req, res, next) => {
let uid = req.user.uid;
let type = 'product';
let favId = req.body.id;
req.ctx(favoriteModel).favoriteDelete(uid, type, favId).then((result) => {
res.json(result);
}).catch(next);
};
module.exports = {
favorite,
favProduct,
favfavBrand,
favoriteDelete
};