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

'use strict';

const Promise = require('bluebird');
const clientAPI = require('./client-api');

/**
 *  在线客服客服端页面
 */
const getClientData = (type, encryptedUid, imgSize) => {
    const logoSize = '136x40';
    const qcSize = '135x135';
    const advSize = '160x335';
    const regExp = /\{width\}x\{height\}/g;

    let apiMethod = [
        clientAPI.getCsSetting(type),
        clientAPI.getMsgHistory(encryptedUid),
        clientAPI.getLastTenOrders(encryptedUid, imgSize)
    ];

    return Promise.all(apiMethod)
        .then(res => {
            let history = res[1].data;
            let hasHistory = history && history.length > 0 || false;
            let csSetting = res[0].data.config;

            csSetting.windowLogo = csSetting.windowLogo.replace(regExp, logoSize);
            csSetting.qrCode = csSetting.qrCode.replace(regExp, qcSize);
            csSetting.pcAdImg = csSetting.pcAdImg.replace(regExp, advSize);

            return {
                csSetting: csSetting,
                hasHistory: hasHistory,
                orders: res[2].data,
                qas: []
            };
        });
};

module.exports = {
    getClientData
};