Blame view

apps/service/models/client-api.js 2.5 KB
1 2 3 4 5
/**
 * 客服用户端 api
 *
 * @author: liqi <qi.li@yoho.cn>
 * @date: 2016/11/4
6 7 8 9
 */

'use strict';
10 11
let config = require('../../../config/common');
李奇 authored
12 13
let api = new global.yoho.ApiBase(config.domains.imCs, {
    name: 'imCs',
李奇 authored
14 15 16
    cache: global.yoho.cache,
    useCache: false
});
17
18
// api urls
李奇 authored
19
let urls = {
李奇 authored
20 21 22
    qas: '/api/helper/queryAllHelper',
    csSetting: '/api/cs/queryByType',
    makeEval: '/api/evalute/saveEvalute',
23
    lastTen: '/api/order/queryLastTenOrder',
李奇 authored
24
    leaveMsg: '/api/leavemessage/saveLeavemessage',
李奇 authored
25
    msgHistory: '/api/conversationMessage/pageList',
26
    evalReason: '/api/evalute/queryReasonBySettingType'
27 28 29
};

/**
李奇 authored
30
 * 用户最近10笔订单
31
 * @function getLastTenOrders
32
 * @param { string } encryptedUid 用户ID
33
 * @return { Object } 最近10条订单
34
 */
35
const getLastTenOrders = (uid, encryptedUid) => {
李奇 authored
36
    return api.post(urls.lastTen, {
37
        uid,
38
        encryptedUid
李奇 authored
39
    });
40 41 42
};

/**
李奇 authored
43
 * 常见问题
44 45
 * @function getQas
 * @return { Object } 问答列表
46
 */
47 48 49 50 51
const getQas = (uid, encryptedUid) => {
    return api.post(urls.qas, {
        uid,
        encryptedUid
    });
李奇 authored
52 53
};
54 55
/**
 * 客服设置
56 57
 * @param { number } type
 * @return { Object } 客服设置
58 59 60 61 62 63 64
 */
const getCsSetting = (type) => {
    return api.get(urls.csSetting, {
        type
    });
};
65 66 67
/**
 * 最近聊天记录
 * @function getMsgHistory
68
 * @param { string } encryptedUid 用户id
李奇 authored
69
 * @param { string } endTime 截止时间
70 71
 * @return { Array } 历史聊天记录
 */
72 73
const getMsgHistory = (uid, encryptedUid, endTime) => {
李奇 authored
74
    let params = {
75
        uid,
李奇 authored
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
        encryptedUid
    };

    if (endTime) {
        params.endTime = endTime;
    }

    return api.post(urls.msgHistory, params, {timeout: 5000});
};

/**
 * 保存评价
 * @param params
 * @returns {*}
 */
const saveEval = (params) => {
    return api.post(urls.makeEval, params);
};

/**
 * 评价原因
 * @param cvId
 * @returns {*}
 */
100
const queryReason = (uid, encryptedUid, type) => {
李奇 authored
101
    const params = {
102 103 104
        uid,
        type,
        encryptedUid
李奇 authored
105 106 107 108 109 110 111 112 113 114 115 116
    };

    return api.post(urls.evalReason, params);
};

/**
 * 留言
 * @param content 内容
 * @param encId 加密UID
 * @param cvId 会话ID
 * @returns {*}
 */
117
const saveMessage = (content, encId, cvId, uid) => {
李奇 authored
118
    const params = {
119
        uid,
李奇 authored
120 121 122 123 124 125
        content,
        encryptedUid: encId,
        conversationId: cvId
    };

    return api.post(urls.leaveMsg, params);
126 127
};
李奇 authored
128 129
module.exports = {
    getQas,
李奇 authored
130 131
    queryReason,
    saveMessage,
132
    getCsSetting,
李奇 authored
133
    saveEval,
134
    getMsgHistory,
李奇 authored
135
    getLastTenOrders
136
};