Cloudcall.php
4.7 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace app\admin\model\facrm;
use app\admin\library\Auth;
use think\Cache;
use think\Model;
/**
* 坐席管理
*/
class Cloudcall extends Model
{
protected $name = 'facrm_cloudcall';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 关联员工
*/
public function admin()
{
return $this->hasOne('app\admin\model\Admin', 'id', 'admin_id');
}
/**
* 云呼签入签出
* @param $from_exten 坐席工号
* @param $exten_type 云呼方式 Local/gateway
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function sign($from_exten, $exten_type, $sign = 'SignIn')
{
//获取云呼配置
$all_types = \addons\facrm\library\cloudcall\Call::getProviders();
$keys = "";
foreach ($all_types as $v) {
$keys .= $keys ? ',' . 'cloudcall' . $v : 'cloudcall' . $v;
}
$settingModel = new \app\admin\model\facrm\Setting();
$setting = $settingModel->where('key', 'in', $keys)->where('status', 1)->find();//只找一条云呼通道
if (!$setting) return true;
try {
$setting = $setting->toArray();
$setting['key'] = $setting['describe'];
$setting = array_merge($setting, $setting['values']);
$call = \addons\facrm\library\cloudcall\Call::instance($setting);
$send_data = [
'sign' => $sign,//SignIn / SignOut
'exten' => $from_exten,//座席号
'exten_type' => $exten_type,//Local/sip/gateway外呼时强制坐席使用该接听方式进行外呼。Local为“手机”,”gateway为“语音网关”
];
$result = $call->signInOrOut($send_data);
if (!$result) {
return false;
}
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* 修改坐席号
* @param $cloud
* @param $admin_id
* @param $from_exten
* @param bool $is_add 如果不存在是否添加
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function edit($cloud, $admin_id, $from_exten, $is_add = false)
{
if (!$cloud) {
//获取云呼配置
$all_types = \addons\facrm\library\cloudcall\Call::getProviders();
$keys = "";
foreach ($all_types as $v) {
$keys .= $keys ? ',' . 'cloudcall' . $v : 'cloudcall' . $v;
}
$settingModel = new \app\admin\model\facrm\Setting();
$setting = $settingModel->where('key', 'in', $keys)->where('status', 1)->find();//只找一条云呼通道
if (!$setting) return true;
$cloud = $setting['describe'];
}
if (!$admin_id) {
$auth = Auth::instance();
if (!$auth->id) return false;
$admin_id = $auth->id;
}
$model = new self();
$row = $model->where('cloud', $cloud)->where('admin_id', $admin_id)->find();
$exten_type = strip_tags(\think\Cookie::get("facrm_extentype")); //云呼通话方式
$result = false;
if (!$row && $is_add) {
//添加
$params = [
'cloud' => $cloud,
'admin_id' => $admin_id,
'from_exten' => $from_exten,
'create_time' => time(),
'exten_type' => $exten_type
];
$result = $model->allowField(true)->save($params);
} else if ($row) {
//修改
$result = $row->save(['from_exten' => $from_exten, 'exten_type' => $exten_type]);
}
//签入
try {
$setting = $setting->toArray();
$setting['key'] = $setting['describe'];
$setting = array_merge($setting, $setting['values']);
$call = \addons\facrm\library\cloudcall\Call::instance($setting);
$send_data = array(
'sign' => 'SignIn', //SignIn / SignOut
'exten' => $from_exten, //座席号
'exten_type' => $exten_type, //Local/sip/gateway外呼时强制坐席使用该接听方式进行外呼。Local为“手机”,”gateway为“语音网关”
);
$result = $call->signInOrOut($send_data);
} catch (\Exception $e) {
}
return $result ? true : false;
}
}