router.js 3.09 KB
/**
 * router of sub app product
 * @author: weiqingting<qingting.wei@yoho.cn>
 * @date: 2016/05/06
 */
'use strict';

const express = require('express');
const router = express.Router(); // eslint-disable-line
const cRoot = './controllers';
const headerModel = require('../../doraemon/models/header');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const config = global.yoho.config;

const personalController = require(`${cRoot}/qrcode`);

const homeNav = [
    {
        title: '交易管理',
        subNav: [
                    {name: '我的订单', href: helpers.urlFormat('/home/orders'), active: true},
                    {name: '我的收藏', href: helpers.urlFormat('/home/favorite')},
                    {name: '我的YOHO币', href: helpers.urlFormat('/home/currency')},
                    {name: '我的红包', href: helpers.urlFormat('/home/redenvelopes')},
                    {name: '我的优惠券', href: helpers.urlFormat('/home/coupons')},
                    {name: '我的VIP', href: helpers.urlFormat('/home/vip')}
        ]
    },
    {
        title: '服务中心',
        subNav: [
                    {name: '我的退/换货', href: helpers.urlFormat('/home/returns')},
                    {name: '我的咨询', href: helpers.urlFormat('/home/consult')},
                    {name: '我的评论', href: helpers.urlFormat('/home/comment')},
                    {name: '我的投诉', href: helpers.urlFormat('/home/complaints')},
                    {name: '我的信息', href: helpers.urlFormat('/home/message'), count: 0},
                    {name: '在线客服', href: 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info=', isBlank: true}
        ]
    },
    {
        title: '个人信息管理',
        subNav: [
                    {name: '编辑个人资料', href: helpers.urlFormat('/home/user')},
                    {name: '账号安全', href: helpers.urlFormat('/home/account')},
                    {name: '地址管理', href: helpers.urlFormat('/home/address')},
                    {name: '兑换礼品卡', href: helpers.urlFormat('/home/gift')}
        ]
    }
];

const getHomeNav = (req, res, next) => {
    res.locals.homeNav = homeNav;
    res.locals.userThumb = '//img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
    next();
};
const getCommonHeader = (req, res, next) => {
    let channel = req.query.channel ? req.query.channel : 'boys';

    headerModel.requestHeaderData(channel).then((result)=>{
        _.merge(res.locals,result);
        next();
    });
};
const sessionEffective = (req, res, next) => {
    let refer = req.cookies.refer;

    if (req.user.uid) {
        next();
        return;
    }

    if (refer) {
        refer = decodeURI(req.cookies.refer);
    } else {
        refer = config.siteUrl;
    }

    res.redirect(helpers.urlFormat('/signin.html', {
           refer: refer
       }));
};

// 查看二维码
router.get('/QRcode',sessionEffective,[getHomeNav,getCommonHeader],personalController.QRcode);

module.exports = router;