index.js
1.6 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
'use strict';
const indexService = require('../models/index-service');
const _ = require('lodash');
const index = (req, res, next)=>{
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
let channel = req.yoho.channel;
let isStudent = req.user.isStudent;
req.ctx(indexService).indexNew(uid, udid, channel, isStudent).then(result => {
_.merge(res.locals, result.header);
return res.render('index', {
module: 'home',
page: 'index',
meIndexPage: true,
me: result.content
});
}).catch(next);
};
// 个人中心-首页-喜欢的品牌
async function brands(req, res) {
let brandsData = await req.ctx(indexService).brands();
res.json({brands: brandsData, more: '/brands'});
}
// 新品上架
async function newArrive(req, res) {
let arrive = await req.ctx(indexService).newArrive();
res.json({newArrive: arrive});
}
// 推荐
async function recommend(req, res) {
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
let channelNum = req.yoho.channelNum;
res.json({recommend: await req.ctx(indexService).recommend(uid, udid, channelNum)});
}
// 头像和左侧菜单我的消息
async function newsAvatar(req, res) {
let uid = req.user.uid;
let result = await req.ctx(indexService).newsAvatar(uid);
res.json(result);
}
async function numbers(req, res) {
let uid = req.user.uid;
let result = await req.ctx(indexService).numbers(uid);
res.json(result);
}
module.exports = {
index,
brands,
newArrive,
recommend,
newsAvatar,
numbers
};