client-service.js
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* 客服用户端 service
*
* @author: liqi <qi.li@yoho.cn>
* @date: 2016/11/4
*/
'use strict';
const Promise = require('bluebird');
const _ = require('lodash');
const clientAPI = require('./client-api');
/**
* 在线客服客服端页面
* @param { number } type
* @param { string } encryptedUid
* @return { Object } 客服设置
*/
const getClientData = (type, encryptedUid) => {
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)
];
return Promise.all(apiMethod)
.then(res => {
let csSetting = res[0].data && res[0].data.config;
let records = res[1].data && res[1].data.records || [];
let hasHistory = records.length > 0 || false;
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
};