shop.js
2.96 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* 店铺相关页面
*
* 首页、列表页
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
*/
'use strict';
const _ = require('lodash');
const camelCase = global.yoho.camelCase;
const cookie = global.yoho.cookie;
const Search = require('../models/search');
const DataHelper = require('../models/helpers');
const ShopData = require('../models/shop-service');
const shop = {
index(req, res, next) {
let domain = req.params.domain;
let uid = cookie.getUid(req);
let data = {
module: 'product',
page: 'shop',
title: domain
};
ShopData.getShopHeadData(domain, uid).then(result => {
if (result.shopId) {
let nav = [DataHelper.getChannelNav()];
nav.push({
name: result.name
});
data.navPath = {
nav: nav
};
data.banner = result;
res.display('shop-index', data);
} else {
shop.list(req, res, next);
}
});
},
list(req, res, next) {
let data = {
module: 'product',
page: 'shop-list',
title: '店铺列表'
};
let nav = [DataHelper.getChannelNav()];
let domain = req.params.domain;
let uid = cookie.getUid(req);
let q = req.query;
q.page = q.page || 1;
ShopData.getShopHeadData(domain, uid).then(result => {
data.banner = result;
if (result.brandId) {
q.brand = result.brandId;
q.shop_id = result.shopId;
nav.push({
name: result.name
});
} else {
res.status(404);
return Promise.reject('brand not found');
}
}).then(() => {
return Search.queryProductOfBrand(q).then(result => {
if (result && result.code === 200 && result.data) {
let ret = camelCase(result.data);
if (ret.filter) {
delete q.brand;
data.filter = DataHelper.filterHandle(ret.filter, req.query);
}
data.paginationData = {
page: q.page,
limit: ret.limit || 45,
total: ret.total,
pageTotal: ret.pageTotal,
queryParams: req.query
};
data.navPath = {
nav: nav
};
res.display('shop-list', _.assign(data, {
products: ret.productList,
order: q.order
}));
} else {
return Promise.reject('query shop index error');
}
});
}).catch(next);
}
};
module.exports = shop;