index.js 1.27 KB
'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
};