router.js 10.2 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 commentController = require(`${cRoot}/comment`);

// const consultController = require(`${cRoot}/consult`);
// const complaintsController = require(`${cRoot}/complaints`);
// const messageController = require(`${cRoot}/message`);
// const returnsController = require(`${cRoot}/returns`);
// const IndexController = require(`${cRoot}/Index`);
// const CurrencyController = require(`${cRoot}/Currency`);
const personalController = require(`${cRoot}/qrcode`);

// const RedenvelopesController = require(`${cRoot}/Redenvelopes`);
// const VipController = require(`${cRoot}/vip`);
// const FavoriteController = require(`${cRoot}/Favorite`);
// const CouponsController = require(`${cRoot}/coupons`);

const UserController = require(`${cRoot}/user`);
const bindController = require(`${cRoot}/3party-bind`);

// const AccountController = require(`${cRoot}/account`);
// const AddressController = require(`${cRoot}/address`);
// const GiftController = require(`${cRoot}/gift`);

const homeNav = (req) => {
    return [
        {
            title: '交易管理',
            subNav: [
                        {name: '我的订单', href: '/home/orders', catchs: ['/home/orders', '/home/index']},
                        {name: '我的收藏', href: '/home/favorite'},
                        {name: '我的有货币', href: '/home/currency'},
                        {name: '我的红包', href: '/home/redenvelopes'},
                        {name: '我的优惠券', href: '/home/coupons'},
                        {name: '我的VIP', href: '/home/vip'}
            ]
        },
        {
            title: '服务中心',
            subNav: [
                        {name: '我的退/换货', href: '/home/returns'},
                        {name: '我的咨询', href: '/home/consult'},
                        {name: '我的评论', href: '/home/comment'},

                        /* {name: '我的投诉', href: '/home/complaints'}, */
                        {name: '我的信息', href: '/home/message', count: 0},
                {
                    name: '在线客服',
                    href: _.get(req.app.locals.pc, 'clientService.new', false) ?
                            '/service/client' : 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409',
                    isBlank: true
                }
            ]
        },
        {
            title: '个人信息管理',
            subNav: [
                        {name: '编辑个人资料', href: '/home/user'},
                        {name: '账号安全', href: '/home/account'},
                        {name: '地址管理', href: '/home/address'},
                        {name: '兑换礼品卡', href: '/home/gift'}
            ]
        }
    ];
};

const getActiveNav = (req)=>{

    let mHomeNav = _.cloneDeep(homeNav(req));

    return mHomeNav.map((item) => {
        item.subNav = item.subNav.map((nav) => {

            let curMatchPath = req.originalUrl;

            if (!nav.matchQuery && curMatchPath.indexOf('?') >= 0) { // 严格的路径匹配,包含后面的参数
                curMatchPath = curMatchPath.substr(0, curMatchPath.indexOf('?'));
            }

            if (nav.catchs) {
                if (nav.catchs.indexOf(curMatchPath) > -1) {
                    nav.active = true;
                }
            } else {
                if (curMatchPath === nav.href) {
                    nav.active = true;
                }
            }

            nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
            return nav;
        });
        return item;
    });
};

const getHomeNav = (req, res, next) => {
    res.locals.path = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}, {name: '个人中心'}];
    res.locals.homeNav = getActiveNav(req);
    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();
    });
};

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


// 我的评论
router.get('/comment', [getCommonHeader, getHomeNav], commentController.index);
router.post('/comment/saveComment', commentController.saveComment);
router.get('/comment/order', [getCommonHeader, getHomeNav], commentController.commentList4Order);

// 我的咨询
// router.get('/consult', [getCommonHeader, getHomeNav], consultController.index);

// 我的投诉
// router.get('/complaints', [getCommonHeader, getHomeNav], complaintsController.index);
// router.post('/complaints/submit', complaintsController.submit);
// router.post('/complaints/cancel', complaintsController.cancel);

// 我的消息
// router.get('/message', messageController.index);
// router.get('/message/detail', messageController.detail);
// router.get('/message/del', messageController.delMsg);
// router.get('/message/read', messageController.readMsg);
// router.get('/message/pickCoupon', messageController.pickCoupon);

// 我的退/换货
// router.get('/returns', returnsController.index);
// router.get('/refund/apply', returnsController.refundApply);
// router.get('/refund/detail', returnsController.refundDetail);
// router.get('/exchange/apply', returnsController.exchangeApply);
// router.get('/exchange/detail', returnsController.refundDetail);
// router.get('/returns/success', returnsController.index);

// // 地址管理
// router.get('address', addressController.index);
// router.get('address/area', addressController.area);


// router.get('/index', [getCommonHeader, getHomeNav], IndexController.index);

// router.get('/currency', CurrencyController.index);

/* 我的红包*/
// router.get('/redenvelopes', RedenvelopesController.index);

/* 我的VIP*/
// router.get('/vip', VipController.index);
//
// router.get('/favorite', FavoriteController.index);
//
// router.get('/coupons', CouponsController.index);

router.get('/user', [getCommonHeader, getHomeNav], UserController.index);

router.post('/user/edituserinfo', UserController.editUserInfo);

router.post('/user/editusercontactinfo', UserController.editUserContactInfo);

router.post('/user/edituserhabitsinfo', UserController.editUserHabitsInfo);

router.post('/user/edituserlikebrand', UserController.editUserLikeBrand);

router.post('/user/isbrandname', UserController.isBrandName);

// 二维码登录
// router.post('/passport/login/qrcode/refresh', bindController.local.qrcode.refresh);           // 刷新二维码
// router.post('/passport/login/qrcode/check', bindController.local.qrcode.check);       // 验证二维码的状态

// 微信登录
router.get('/bind/wechat', bindController.wechat.login); // 微信登录, 兼容 PHP 的路径
router.get('/bind/wechat/callback', bindController.wechat.callback);

// sina登录
router.get('/bind/sina', bindController.sina.login);
router.get('/bind/sina/callback', bindController.sina.callback);

// qq登录
router.get('/bind/qq', bindController.qq.login);
router.get('/bind/qq/callback', bindController.qq.callback);

// alipay登录
router.get('/bind/alipay', bindController.alipay.login);
router.get('/bind/alipay/callback', bindController.alipay.callback);

// douban登录
router.get('/bind/douban', bindController.douban.login);

// router.get('/bind/douban/callback', bindController.douban.callback);

// renren登录
router.get('/bind/renren', bindController.renren.login);
router.get('/bind/renren/callback', bindController.renren.callback);

router.post('/cancelbind/:type', bindController.cancelBind);


//
// router.get('/address/area', UserController.getProviceList);
//
// router.get('/account', [getCommonHeader, getHomeNav], AccountController.index);
//
// router.get('/account/userpwd', [getCommonHeader, getHomeNav], AccountController.userPwd);
//
// router.get('/account/email', [getCommonHeader, getHomeNav], AccountController.userEmail);
//
// router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.userMobile);
//
// router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode);
//
// router.post('/account/checkpassword', [getCommonHeader, getHomeNav], AccountController.checkPassword);
//
// router.post('/account/verifypassword', [getCommonHeader, getHomeNav], AccountController.verifyPassword);
//
// router.post('/account/modifypwd', [getCommonHeader, getHomeNav], AccountController.modifyPwd);
//
// router.post('/account/sendemail', AccountController.sendEmail);
//
// router.post('/account/checkemail', [getCommonHeader, getHomeNav], AccountController.checkEmail);
//
// router.post('/account/modifyemail', [getCommonHeader, getHomeNav], AccountController.modifyEmail);
//
// router.get('/account/sendemailsuccess', [getCommonHeader, getHomeNav], AccountController.sendEmailSuccess);
//
// router.get('/account/mailresult', [getCommonHeader, getHomeNav], AccountController.mailResult);
//
// router.post('/account/checkmobile', AccountController.checkMobile);
//
// router.post('/account/checkmobilemsg', AccountController.checkMobileMsg);
//
// router.post('/account/sendmobilemsg', AccountController.sendMobileMsg);
//
// router.post('/account/modifymobile', AccountController.modifyMobile);
//
// router.get('/address', [getCommonHeader, getHomeNav], AddressController.index);
//
// router.get('/address/editAddress', AddressController.editAddress);
//
// router.post('/address/saveAddress', AddressController.saveAddress);
//
// router.get('/address/delAddress', AddressController.delAddress);
//
// router.get('/address/defaultAddress', AddressController.defaultAddress);
//
// router.get('/gift', [getCommonHeader, getHomeNav], GiftController.index);
//
// router.post('/gift/exchange', GiftController.exchange);

module.exports = router;