133 lines
5.0 KiB
PHP
133 lines
5.0 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim.
|
|
* User: lcc
|
|
* Desc: 晓致虚拟号
|
|
* Date: 2021/07/26
|
|
* Time: 10:17
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
require_once COMMPATH.'third_party/Xcall/Xcall.php';
|
|
class Xz extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
|
|
$this->load->model('receiver/receiver_customers_model','customers_model');
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->log_file = 'call.log';
|
|
}
|
|
protected function get(){
|
|
$id = $this->input_param('id');
|
|
$type = intval($this->input_param('type'));
|
|
!$type && $type = 0;
|
|
$session = $this->session;
|
|
$admin_id = $session['uid'];
|
|
$cf_title = 'customer';
|
|
$cus_id = $id;
|
|
if($type==1){ //订单
|
|
$order = $this->orders_model->get(['id'=>$id]);
|
|
$cus_id = $order['rid'];
|
|
}
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
if(!$row || !$row['mobile']){
|
|
throw new Hd_Exception('用户不存在', API_CODE_INVILD_PARAM);
|
|
}
|
|
$customer_mobile = $row['mobile'];
|
|
$user_mobile = $session['mobile'];
|
|
$json = $session['jsondata'] ? json_decode($session['jsondata'], true) : array();
|
|
if ($json && $json['hdy'] && $json['hdy']['tel']) {
|
|
$user_mobile = $json['hdy']['tel'];
|
|
}
|
|
$redis = &load_cache('redis');
|
|
$cache_key = "XZ_LICHEB_MOBILEA_{$user_mobile}_MOBILEB_{$customer_mobile}_{$admin_id}";
|
|
$call_mobile = $redis->get($cache_key);
|
|
if (!$call_mobile) {
|
|
$this->config->load('xcall');
|
|
$params = [
|
|
'app_id' => $this->config->item('app_id'),
|
|
'app_key' => $this->config->item('app_key'),
|
|
];
|
|
$seq_id = create_order_no();
|
|
$result = '';
|
|
//循环绑定
|
|
$xcall = new Xcall($params);
|
|
$maxBindingTime = 10;//绑定时间
|
|
$result = $xcall -> ABXbind($user_mobile, $customer_mobile,$seq_id,$maxBindingTime);
|
|
if(!$result['code']){ //绑定失败
|
|
debug_log("xz_failed_bind:customer_mobile【{$customer_mobile}】", $this->log_file);
|
|
debug_log("xz_result:" . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
throw new Hd_Exception($result['msg'], API_CODE_FAIL);
|
|
}else{
|
|
$this->data['middlenumber'] = $result['data']['virtualMobile'];
|
|
$add_data = [
|
|
'call_id' => $seq_id,
|
|
'display_number' => $result['data']['virtualMobile'],
|
|
'biz_id' => $row['biz_id'],
|
|
'cf_id' => $cus_id,
|
|
'cf_uid' => $admin_id,
|
|
'cf_title' => $cf_title,
|
|
'cf_platform' => 'api',
|
|
'json_data' => json_encode(['uname'=>$session['uname']],JSON_UNESCAPED_UNICODE),
|
|
'c_time' => time()
|
|
];
|
|
$this->receiver_xz_model->add($add_data);
|
|
$call_mobile = $result['data']['virtualMobile'];
|
|
$redis->save($cache_key, $call_mobile, $maxBindingTime*60);
|
|
}
|
|
}
|
|
$data['mobile'] = $call_mobile;
|
|
return $data;
|
|
}
|
|
//电话统计
|
|
protected function get_stat(){
|
|
$biz_id = $this->input_param('biz_id');
|
|
$day = $this->input_param('day');
|
|
$admin_id = $this->input_param('admin_id');
|
|
if(!$biz_id){
|
|
throw new Hd_Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
//接通次数
|
|
$where1 = [
|
|
'cf_title' => 'customer',
|
|
'cf_platform' => 'api',
|
|
'biz_id' => $biz_id,
|
|
'status' => 1,
|
|
];
|
|
if($day){
|
|
$s_time = date('Y-m-d 00:00:00',strtotime($day));
|
|
$e_time = date('Y-m-d 23:59:59',strtotime($day));
|
|
$where1["c_time>="] = strtotime($s_time);
|
|
$where1["c_time<="] = strtotime($e_time);
|
|
}
|
|
$admin_id && $where1['cf_uid'] = $admin_id;
|
|
$where2 = [
|
|
'duration' => 0
|
|
];
|
|
$where = array_merge($where1,$where2);
|
|
$num = $this->receiver_xz_model->count($where);
|
|
$where2 = [
|
|
'duration>' => 0
|
|
];
|
|
$where = array_merge($where1,$where2);
|
|
$count_call = $this->receiver_xz_model->count($where); //接通次数
|
|
$sum_call = $this->receiver_xz_model->sum('duration',$where); //接通总时长
|
|
$call_time = $sum_call['duration']/60000;
|
|
if($call_time){
|
|
$avg_time = $call_time/$count_call;
|
|
}
|
|
$data = [
|
|
'call_time' => round($call_time,2),
|
|
'avg_time' => round($avg_time,2),
|
|
'unget_num' => $num
|
|
];
|
|
return $data;
|
|
}
|
|
}
|