client-api.js 2.5 KB
/**
 * 客服用户端 api
 *
 * @author: liqi <qi.li@yoho.cn>
 * @date: 2016/11/4
 */

'use strict';

let config = require('../../../config/common');

let api = new global.yoho.ApiBase(config.domains.imCs, {
    name: 'imCs',
    cache: global.yoho.cache,
    useCache: false
});

// api urls
let urls = {
    qas: '/api/helper/queryAllHelper',
    csSetting: '/api/cs/queryByType',
    makeEval: '/api/evalute/saveEvalute',
    lastTen: '/api/order/queryLastTenOrder',
    leaveMsg: '/api/leavemessage/saveLeavemessage',
    msgHistory: '/api/conversationMessage/pageList',
    evalReason: '/api/evalute/queryReasonBySettingType'
};

/**
 * 用户最近10笔订单
 * @function getLastTenOrders
 * @param { string } encryptedUid 用户ID
 * @return { Object } 最近10条订单
 */
const getLastTenOrders = (uid, encryptedUid) => {
    return api.post(urls.lastTen, {
        uid,
        encryptedUid
    });
};

/**
 * 常见问题
 * @function getQas
 * @return { Object } 问答列表
 */
const getQas = (uid, encryptedUid) => {
    return api.post(urls.qas, {
        uid,
        encryptedUid
    });
};

/**
 * 客服设置
 * @param { number } type
 * @return { Object } 客服设置
 */
const getCsSetting = (type) => {
    return api.get(urls.csSetting, {
        type
    });
};

/**
 * 最近聊天记录
 * @function getMsgHistory
 * @param { string } encryptedUid 用户id
 * @param { string } endTime 截止时间
 * @return { Array } 历史聊天记录
 */
const getMsgHistory = (uid, encryptedUid, endTime) => {

    let params = {
        uid,
        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 {*}
 */
const queryReason = (uid, encryptedUid, type) => {
    const params = {
        uid,
        type,
        encryptedUid
    };

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

/**
 * 留言
 * @param content 内容
 * @param encId 加密UID
 * @param cvId 会话ID
 * @returns {*}
 */
const saveMessage = (content, encId, cvId, uid) => {
    const params = {
        uid,
        content,
        encryptedUid: encId,
        conversationId: cvId
    };

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

module.exports = {
    getQas,
    queryReason,
    saveMessage,
    getCsSetting,
    saveEval,
    getMsgHistory,
    getLastTenOrders
};