-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcategory.js
112 lines (108 loc) · 2.59 KB
/
category.js
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
110
111
112
// 引入 models
const models = require('../models');
const code = require('../lib/code');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
indexAction = async (request) => {
try{
const { id: categoryId } = request.query;
// 获取所有的分类
const data = await models.nideshop_category.findAndCountAll({
where: {
"parent_id": 0
},
limit: request.query.limit,
offset: (request.query.page - 1) * request.query.limit,
});
const currentCategory = [];
if (categoryId) {
// 获取分类里的子类
currentCategory = await models.nideshop_category.findAndCountAll({
where: {
"parent_id": categoryId
},
limit: request.query.limit,
offset: (request.query.page - 1) * request.query.limit,
});
};
return {
results: {
"categoryList": data,
},
// totalCount: totalCount,
dataBaseError: false
}
}
catch(e){
return { results: e, dataBaseError: true}
}
}
// 点击右侧分类时获取左侧分类
currentAction = async (request) => {
try{
// 获取分类里的子类
const currentOne = await models.nideshop_category.findAndCountAll({
where: {
"id": request.query.id
},
limit: request.query.limit,
offset: (request.query.page - 1) * request.query.limit,
});
const subList = await models.nideshop_category.findAndCountAll({
where: {
"parent_id": request.query.id
},
limit: request.query.limit,
offset: (request.query.page - 1) * request.query.limit,
});
return {
results: {
data: currentOne,
subList
},
// totalCount: totalCount,
dataBaseError: false
}
}
catch(e){
return { results: e, dataBaseError: true}
}
};
/**
* 获取分类列表
* 1. 需要头部导航包含的分类
* 2. 查找导航上分类对应的商品
*/
categoryNav = async (request) => {
try{
// const categoryId = request.query.id;
// 获得当前分类
const currentNav = await models.nideshop_category.findAndCountAll({
where: {
id: request.query.id
},
});
// 获得它的同类
const navData = await models.nideshop_category.findAndCountAll({
where: {
parent_id: request.query.parent_id
}
});
return {
results: {
navData,
currentNav: currentNav[0],
},
// totalCount: totalCount,
dataBaseError: false
}
}
catch(e){
return { results: e, dataBaseError: true}
}
}
module.exports = {
indexAction,
currentAction,
categoryNav
}