help.js 2.24 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;

    helpModel.helpData().then(result => {
        if (result.other.length === 0 && result.selfService.list.length === 0) {
            return next();
        }

        res.display('help', {
            module: 'help',
            page: 'help-index',
            content: Object.assign({
                siteUrl: siteUrl,
                nav: [
                    {
                        link: siteUrl,
                        name: 'YOHO!BLK首页'
                    },
                    {
                        name: '帮助中心'
                    }
                ]
            }, result)
        });
    }).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,
        url: req.originalUrl,
        page: q.page || 1
    };

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

    helpModel.detailData(params).then(result => {
        if (result.data.menuData.length === 0) {
            return next();
        }

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

        res.display('detail', {
            module: 'help',
            page: 'help',
            content: Object.assign({
                nav: nav,
                helpQuery: req.query.helpQuery
            }, result.data),
            qid: q.helpQuery ? false : params.id
        });
    }).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
};