index.js
1.27 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
'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 newsAvatar(req, res) {
let uid = req.user.uid;
let result = await req.ctx(indexService).newsAvatar(uid);
res.json(result);
}
async function asyncData(req, res) {
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
let channelNum = req.yoho.channelNum;
let data = await Promise.props({
numbers: req.ctx(indexService).numbers(uid),
brands: req.ctx(indexService).brands(),
products: req.ctx(indexService).newArrive(),
rec: req.ctx(indexService).recommend(uid, udid, channelNum)
});
res.json(data);
}
module.exports = {
index,
newsAvatar,
asyncData
};