index.js 1.6 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 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
};