Blame view

apps/service/controllers/chatQa.js 3.68 KB
1 2 3 4 5 6 7 8
/**
 * 服务与反馈
 * <jing.li@yoho.cn>
 * 2016/11/29
 */

'use strict';
郭成尧 authored
9 10
const _ = require('lodash');
const co = Promise.coroutine;
11
const headerModel = require('../../../doraemon/models/header'); // 头部model
lijing authored
12
const chatQaModel = require('../models/chatQa');
13 14 15

exports.qaList = (req, res, next) => {
    let headerData = headerModel.setNav({
lea guo authored
16
        navTitle: '服务与反馈',
17 18 19 20 21 22
    });

    let responseData = {
        pageHeader: headerData,
        module: 'service',
        page: 'chat-qa',
lijing authored
23
        title: '服务与反馈 | Yoho!Buy有货 | 潮流购物逛不停',
24
        width750: true,
lea guo authored
25
        pageFooter: true,
26 27
    };
lea guo authored
28 29 30 31 32 33
    req.ctx(chatQaModel)
        .index({})
        .then(result => {
            res.render('chat/chat-qa', Object.assign(result, responseData));
        })
        .catch(next);
34 35 36 37
};

exports.qaSearch = (req, res, next) => {
    let headerData = headerModel.setNav({
lea guo authored
38
        navTitle: '服务与反馈',
39 40 41 42 43 44
    });

    let responseData = {
        pageHeader: headerData,
        module: 'service',
        page: 'chat-qa',
lijing authored
45
        title: '服务与反馈 | Yoho!Buy有货 | 潮流购物逛不停',
lea guo authored
46
        width750: true,
47 48
    };
lea guo authored
49 50 51 52 53 54
    req.ctx(chatQaModel)
        .qaSearch({})
        .then(result => {
            res.render('chat/qa-search', Object.assign(result, responseData));
        })
        .catch(next);
lijing authored
55 56 57
};

exports.keySearch = (req, res, next) => {
lijing authored
58
    let params = {
lea guo authored
59
        keyword: req.query.keyword,
lijing authored
60 61
    };
lea guo authored
62 63 64 65 66 67
    req.ctx(chatQaModel)
        .keySearch(params)
        .then(result => {
            res.json(result);
        })
        .catch(next);
68 69
};
lijing authored
70
exports.qaDetail = (req, res, next) => {
郭成尧 authored
71
    let title = req.query.title || '问题详情';
郭成尧 authored
72
    let id = req.query.id;
lijing authored
73
    let headerData = headerModel.setNav({
lea guo authored
74
        navTitle: title,
lijing authored
75
    });
王水玲 authored
76 77
    let protocolUrl = '';
王水玲 authored
78
    if (+req.query.sonId === 340) {
lea guo authored
79 80
        protocolUrl =
            'https://cdn.yoho.cn/yohobuy/pdf/YOHO!BUY有货用户服务协议0725.pdf';
王水玲 authored
81 82 83
    }

    if (+req.query.sonId === 352) {
lea guo authored
84
        protocolUrl =
lea guo authored
85
            'https://cdn.yoho.cn/yohobuy/pdf/有货隐私条款(2019.8.7).pdf';
王水玲 authored
86 87
    }
lijing authored
88 89 90 91
    let responseData = {
        pageHeader: headerData,
        module: 'service',
        page: 'chat-qa',
郭成尧 authored
92
        title: `${title} | Yoho!Buy有货 | 潮流购物逛不停`,
lijing authored
93
        width750: true,
郭成尧 authored
94
        pageFooter: true,
王水玲 authored
95
        isApp: req.yoho.isApp,
lea guo authored
96
        protocolUrl: protocolUrl,
lijing authored
97 98
    };
lea guo authored
99
    co(function*() {
郭成尧 authored
100
        let detailData = {};
lijing authored
101
lea guo authored
102 103 104 105 106
        if (id) {
            // 有 ID 直接通过 ID 取数据
            let detailApi = yield req
                .ctx(chatQaModel)
                .getDetailById(req.query.id);
lijing authored
107
郭成尧 authored
108 109 110
            return res.send(`
                <html>
                    <head>
李靖 authored
111
                    <meta charset="utf-8">
lea guo authored
112 113 114 115 116
                    <title>${req.query.keyword ||
                        _.get(
                            detailApi,
                            'data.helpdetail_list[0].caption',
                        )}</title>
李靖 authored
117 118
                    <meta name="viewport" 
                    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
郭成尧 authored
119
                    </head>
李靖 authored
120
                    <body style="margin: 15px;">
郭成尧 authored
121 122
                        ${_.get(detailApi, 'data.helpdetail_list[0].content')}
                    </body>
郭成尧 authored
123
                </html>
郭成尧 authored
124
            `);
郭成尧 authored
125 126 127 128
        } else {
            let params = {
                sonId: req.query.sonId,
                parentId: req.query.parentId,
lea guo authored
129
                keyword: req.query.keyword,
郭成尧 authored
130
            };
lijing authored
131
郝肖肖 authored
132
            detailData = yield req.ctx(chatQaModel).qaDetail(params);
郭成尧 authored
133 134 135
        }
        return res.render('chat/qa-detail', _.assign(responseData, detailData));
    })().catch(next);
lijing authored
136
};