help.js 2.49 KB
/**
 * 帮助中心
 * @author: jiangmin
 * @date: 2016/07/25
 */

'use strict';
const helpModel = require('../models/help');

const index = (req, res, next) => {
    let siteUrl = global.yoho.config.siteUrl;
    let channel = req.query.channel ? req.query.channel : 'boys';

    helpModel.helpData(channel).then(result => {
        if (result.content.menuData.length === 0) {
            return next();
        }

        res.render('help', Object.assign({
            module: 'help',
            page: 'help-index',
            content: Object.assign({
                siteUrl: siteUrl,
                isHelp: true,
                pathNav: [
                    {
                        href: siteUrl,
                        name: 'YOHO!BUY 有货首页'
                    },
                    {
                        name: '帮助中心'
                    }
                ]
            }, result.content)
        }, result.headerData));
    }).catch(next);
};

/**
 * 详情
 */
const detail = (req, res, next) => {
    let q = req.query;
    let params = {
        id: parseInt(q.id || 1, 10),
        contId: +req.query.contId || 0,
        keywords: req.query.helpQuery,
        channel: req.query.channel ? req.query.channel : 'boys'
    };

    let nav = [
        {
            href: global.yoho.config.siteUrl,
            name: 'YOHO!BUY 有货首页'
        },
        {
            name: '帮助中心',
            href: '/help/index'
        }
    ];

    helpModel.detailData(params).then(result => {
        let newData = result.newData;
        let headerData = result.headerData;

        if (result.newData.data.menuData.length === 0) {
            return next();
        }

        if (!(typeof (newData.nav) === 'undefined')) {
            nav = nav.concat(newData.nav);
        }

        res.render('detail', Object.assign({
            module: 'help',
            page: 'help',
            content: Object.assign({
                isHelp: true,
                pathNav: nav
            }, newData.data),
            qid: q.helpQuery ? false : params.id
        }, headerData));
    }).catch(next);
};

// 帮助搜索功能
const search = (req, res, next) => {
    helpModel.searchData(req.query).then(result => {
        res.json(result);
    }).catch(next);
};

// 获取在线客服的链接
const onlineService = (req, res, next) => {
    helpModel.onlineService().then(url => {
        res.json(url);
    }).catch(next);
};

module.exports = {
    index,
    detail,
    search,
    onlineService
};