152 lines
7.0 KiB
PHP
152 lines
7.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Desc: 晓致拨号回调
|
|
* Date: 2021/4/14
|
|
* Time: 19:15
|
|
*/
|
|
class Xzcall extends HD_Controller
|
|
{
|
|
|
|
private $log_file;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->log_file = 'call_xz.log';
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
|
$this->load->model('receiver/order/receiver_orders_model', 'orders_model');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
debug_log("start function:" . __FUNCTION__, $this->log_file);
|
|
$data = $this->input->post();
|
|
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
if ($data && $data['seqId']) {
|
|
$row = $this->receiver_xz_model->get(array('call_id' => $data['seqId']));
|
|
if ($row) {
|
|
$jsondata = json_decode($row['json_data'], true);
|
|
$data['uname'] = $jsondata['uname'];
|
|
$data['brand_id'] = $jsondata['brand_id'];
|
|
$up_data['caller_state'] = $data['status'];
|
|
$up_data['status'] = 1;
|
|
$data['mid'] && $up_data['mid'] = $data['mid'];
|
|
$data['to'] && $up_data['called_num'] = $data['to'];
|
|
$data['from'] && $up_data['caller_num'] = $data['from'];
|
|
if ($data['callAnswer']) {
|
|
$up_data['duration'] = $data['callEnd'] - $data['callAnswer'];
|
|
$up_data['answer_time'] = $this->getMsecToMescdate($data['callAnswer']);
|
|
}
|
|
$data['callStart'] && $up_data['start_time'] = $this->getMsecToMescdate($data['callStart']);
|
|
$data['callEnd'] && $up_data['end_time'] = $this->getMsecToMescdate($data['callEnd']);
|
|
$up_data['json_data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
|
|
if ($row['cf_id'] && $row['cf_platform'] == 'admin') { //后台
|
|
$admin_id = $row['cf_uid'];
|
|
$this->load->model('sys/sys_admin_model');
|
|
$admin = $this->sys_admin_model->get(array('id' => $admin_id));
|
|
$addData = array(
|
|
'uid' => $admin_id,
|
|
'uname' => $admin['username'] ? $admin['username'] : '',
|
|
'type' => 2,//类型 0 普通 1短信 2电话
|
|
'log' => $row['id'],
|
|
'c_time' => time()
|
|
);
|
|
if ($row['cf_title'] == 'clues') {//线索拨打电话回调
|
|
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
|
|
$addData['clue_id'] = $row['cf_id'];
|
|
} else if ($row['cf_title'] == 'customer') {//客户拨打电话回调
|
|
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdOplogs');
|
|
$addData['customer_id'] = $row['cf_id'];
|
|
}
|
|
$this->mdOplogs->add($addData);
|
|
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
|
|
$xcall = new Xcall();
|
|
//解绑
|
|
$xcall->SWunbind($data['to'], $data['virtualMobile']);
|
|
} elseif ($row['cf_id'] && $row['cf_platform'] == 'api') { //狸车宝
|
|
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
|
|
$xcall = new Xcall();
|
|
//解绑
|
|
$result = $xcall->SWunbind($data['to'], $data['virtualMobile']);
|
|
if ($row['cf_title'] == 'order') { //订单
|
|
$order = $this->orders_model->get(['id' => $row['cf_id']]);
|
|
$cust = $this->customers_model->get(['id' => $order['rid']]);
|
|
//$this->load->library('receiver/orders_entity');
|
|
//$this->orders_entity->add_log($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2);
|
|
} else { //客户
|
|
$cust = $this->customers_model->get(['id' => $row['cf_id']]);
|
|
}
|
|
$this->load->library('receiver/customers_entity');
|
|
$this->customers_entity->add_log($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2);
|
|
//删除redis
|
|
$cache_key = "XZ_LICHEB_MOBILEB_{$cust['mobile']}_{$row['cf_uid']}";
|
|
$redis = &load_cache('redis');
|
|
$redis->delete($cache_key);
|
|
}
|
|
} else {
|
|
debug_log("error: 未找到拨打记录", $this->log_file);
|
|
}
|
|
}
|
|
debug_log("end " . __FUNCTION__, $this->log_file);
|
|
echo '{"result":"0","error":""}';
|
|
}
|
|
|
|
//录音推送地址
|
|
public function video()
|
|
{
|
|
$data = $this->input->post();
|
|
debug_log("start function:" . __FUNCTION__, $this->log_file);
|
|
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
$row = $this->receiver_xz_model->get(array('mid' => $data['mid']));
|
|
if ($row) {
|
|
$jsondata = json_decode($row['json_data'], true);
|
|
if ($data['getFileUrl']) {
|
|
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
|
|
$xcall = new Xcall();
|
|
$result = $xcall->getFile($data['readUrl'], $data['mid'], $data['tag']);
|
|
if ($result['code']) { //上传七牛
|
|
$this->load->library('qiniu');
|
|
$qiniu = new Qiniu(['type' => 'video']);
|
|
$filename = $qiniu->getFileName($data['mid'], 'mp3', 'xz_video_');
|
|
$q_res = $qiniu->save($filename, $result['data']);
|
|
if (!$q_res) {
|
|
debug_log('error:文件上传七牛失败', $this->log_file);
|
|
} else {
|
|
$up_data['rec_url'] = $q_res['url'];
|
|
}
|
|
} else {
|
|
debug_log('error:' . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
}
|
|
}
|
|
$jsondata['file_info'] = $data;
|
|
$up_data['json_data'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
|
|
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
|
|
}
|
|
debug_log("end " . __FUNCTION__, $this->log_file);
|
|
echo '{"result":"0","error":""}';
|
|
}
|
|
|
|
/**
|
|
* 毫秒转日期
|
|
*/
|
|
private function getMsecToMescdate($msectime)
|
|
{
|
|
$msectime = $msectime * 0.001;
|
|
if (strstr($msectime, '.')) {
|
|
sprintf("%01.3f", $msectime);
|
|
list($usec, $sec) = explode(".", $msectime);
|
|
$sec = str_pad($sec, 3, "0", STR_PAD_RIGHT);
|
|
} else {
|
|
$usec = $msectime;
|
|
$sec = "000";
|
|
}
|
|
$date = date("Y-m-d H:i:s.x", $usec);
|
|
return $mescdate = str_replace('x', $sec, $date);
|
|
}
|
|
}
|