Commit 1e56b458 authored by hujun's avatar hujun

后台拨打电话接口

parent 90996260
...@@ -20,6 +20,7 @@ class CallPhoneService ...@@ -20,6 +20,7 @@ class CallPhoneService
{ {
private $phone_a = ''; private $phone_a = '';
private $phone_b = ''; private $phone_b = '';
private $phone_x = '';
private $expiry_date = ''; private $expiry_date = '';
private $record = true; private $record = true;
private $release = 1; private $release = 1;
...@@ -35,9 +36,6 @@ class CallPhoneService ...@@ -35,9 +36,6 @@ class CallPhoneService
* @param $phone_b * @param $phone_b
* @param bool $record * @param bool $record
* @return mixed * @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function bindAXB($phone_a, $phone_b, $record = true) public function bindAXB($phone_a, $phone_b, $record = true)
{ {
...@@ -57,78 +55,151 @@ class CallPhoneService ...@@ -57,78 +55,151 @@ class CallPhoneService
$this->phone_b = $phone_b;//客户手机号 $this->phone_b = $phone_b;//客户手机号
$this->record = $record; //是否录音 $this->record = $record; //是否录音
$redis = RedisExt::getRedis(); try {
$this->is_privacy = $redis->get('s_is_privacy'); $redis = RedisExt::getRedis();
$this->is_privacy = $redis->get('s_is_privacy');
//0不使用隐私号码 1阿里云 2容联云 //0不使用隐私号码 1阿里云 2容联云
if ($this->is_privacy == 0) { if ($this->is_privacy == 0) {
$this->originalPhone(); $this->originalPhone();
$result['status'] = 'success'; $result['status'] = 'success';
$result['phone'] = $phone_b; $result['phone'] = $phone_b;
return $result; return $result;
} }
$bind = new BindingPhone(); $bind = new BindingPhone();
$where['a.status'] = 1; $where['a.status'] = 1;
$where['a.phone_a'] = $phone_a; $where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b; $where['a.phone_b'] = $phone_b;
$where['a.type'] = $this->is_privacy; $where['a.type'] = $this->is_privacy;
$phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码 $phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
if (!empty($phone_x['phone_x'])) { if (!empty($phone_x['phone_x'])) {
$result['status'] = 'success'; $result['status'] = 'success';
$result['data']['phone'] = $phone_x['phone_x']; $result['data']['phone'] = $phone_x['phone_x'];
$result['msg'] = '已绑定,返回隐私号码。'; $result['msg'] = '已绑定,返回隐私号码。';
return $result; //绑定过了,返回隐号 return $result; //绑定过了,返回隐号
} }
$day_num = $redis->get('s_day_num'); $day_num = $redis->get('s_day_num');
$this->release = 1; //是否释放 $this->release = 1; //是否释放
if (empty($day_num)) { if (empty($day_num)) {
$this->expiry_date = _EXPIRATION; $this->expiry_date = _EXPIRATION;
} else {
if (empty($this->params['landlord'])) {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
} else { } else {
$day_num = $redis->get('s_landlord_phone_day'); if (empty($this->params['landlord'])) {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
} else {
$day_num = $redis->get('s_landlord_phone_day');
if ($day_num == 0) {
$this->expiry_date = date('Y-m-d H:i:s', time() + 5);
$this->release = 0;
} else {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
}
}
}
if ($day_num == 0) { if ($this->is_privacy == 1) {
$this->expiry_date = date('Y-m-d H:i:s', time() + 5); /*阿里云*/
$this->release = 0; $call_phone = $this->aliYunBind();
if ($call_phone['status'] == 'success') {
$result['status'] = 'success';
$result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg'];
} else { } else {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day")); $result['msg'] = $call_phone['msg'];
}
} elseif ($this->is_privacy == 2) {
$call_phone = $this->yunTongXun();
if ($call_phone['status'] == 'success') {
$result['status'] = 'success';
$result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg'];
} else {
$result['msg'] = $call_phone['msg'];
} }
} }
if ($result['status'] == 'success')
$bind->recordBindPhone($call_phone['phone'], $phone_a, $phone_b, $record, $this->expiry_date, $this->subs_id, $this->request_id, $this->mapping_id, $this->is_privacy, $this->release);
} catch (\Exception $e) {
$data['status'] = 'failed';
$data['msg'] = $e->getMessage();
} }
if ($this->is_privacy == 1) { return $result;
/*阿里云*/ }
$call_phone = $this->aliYunBind();
if ($call_phone['status'] == 'success') { /**
$result['status'] = 'success'; * 解除绑定关系
$result['phone'] = $call_phone['phone']; *
$result['msg'] = $call_phone['msg']; * @param $phone_a
} else { * @param $phone_b
$result['msg'] = $call_phone['msg']; * @param $phone_x
} * @return mixed
} elseif ($this->is_privacy == 2) { */
$call_phone = $this->yunTongXun(); public function agentsUnBind($phone_a, $phone_b, $phone_x)
{
$data['status'] = 'success';
$data['msg'] = '';
if (empty($phone_x) || empty($phone_a) || empty($phone_b)) {
$data['status'] = 'failed';
$data['msg'] = '解除关系参数错误,请联系运营人员!';
return $data;
}
if ($call_phone['status'] == 'success') { $phone = new BindingPhone();
$result['status'] = 'success';
$result['phone'] = $call_phone['phone']; $redis = RedisExt::getRedis();
$result['msg'] = $call_phone['msg']; $is_privacy = $redis->get('s_is_privacy');
$is_privacy = $is_privacy != '0' ? $is_privacy : 0;
try {
if ($is_privacy == 1) {
/*阿里云*/
$subsId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'subsId');
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);/*解绑*/
if ($result->Message == 'OK') {
$phone->unBind($phone_x, $phone_a, $phone_b);
} else {
$data['status'] = 'failed';
$data['msg'] = '解除绑定关系失败,请联系运营!';
}
} else {
$data['msg'] = '没有号码绑定关系,请忽略!';
}
} elseif ($is_privacy == 2) {
/*容联云*/
$mappingId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'mappingId');
$yun_tong_xun = new RongDemo();
if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
if ($result['statusCode'] == '000000') {
$phone->unBind($phone_x, $phone_a, $phone_b);
} else {
$data['status'] = 'failed';
$data['msg'] = '解除绑定关系失败,请联系运营!';
}
} else {
$data['msg'] = '没有号码绑定关系,请忽略!。';
}
} else { } else {
$result['msg'] = $call_phone['msg']; $data['msg'] = '没有号码绑定关系,请忽略!。';
} }
} catch (\Exception $e) {
$data['status'] = 'failed';
$data['msg'] = $e->getMessage();
} }
if ($result['status'] == 'success') return $data;
$bind->recordBindPhone($call_phone['phone'], $phone_a, $phone_b, $record, $this->expiry_date, $this->subs_id, $this->request_id, $this->mapping_id, $this->is_privacy, $this->release);
return $result;
} }
/** /**
......
...@@ -8,19 +8,21 @@ ...@@ -8,19 +8,21 @@
namespace app\index\controller; namespace app\index\controller;
use app\api_broker\service\CallPhoneService;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
use app\model\AliYunPhone; use app\model\AliYunPhone;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport; use app\model\SecretReport;
use Grpc\Call;
use think\Db; use think\Db;
class CellPhone extends Basic class CellPhone extends Basic
{ {
protected $code = 200; protected $code = 200;
protected $data = []; protected $data = [];
protected $msg = ""; protected $msg = "";
/** /**
* 总记录列表、搜索 * 总记录列表、搜索
...@@ -30,55 +32,56 @@ class CellPhone extends Basic ...@@ -30,55 +32,56 @@ class CellPhone extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function callLog() { public function callLog()
{
if ($this->request->isAjax()) { if ($this->request->isAjax()) {
$result['code'] = 200; $result['code'] = 200;
$result['msg'] = ''; $result['msg'] = '';
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$report = new SecretReport(); $report = new SecretReport();
$field = 'agents_id,users_id,call_type,call_time,time,voice_file,user_status,a.id,a.create_time,type'; $field = 'agents_id,users_id,call_type,call_time,time,voice_file,user_status,a.id,a.create_time,type';
$where = []; $where = [];
if (!empty($this->params['start_date'])) { if (!empty($this->params['start_date'])) {
$where['a.call_time'] = ['> time', $this->params['start_date'] . ' 00:00:00']; $where['a.call_time'] = [ '> time', $this->params['start_date'] . ' 00:00:00' ];
} }
if (!empty($this->params['end_date'])) { if (!empty($this->params['end_date'])) {
$where['a.call_time'] = ['< time', $this->params['end_date']. ' 23:59:59']; $where['a.call_time'] = [ '< time', $this->params['end_date'] . ' 23:59:59' ];
} }
if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) { if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) {
$where['a.call_time'] = ['between', [$this->params['start_date'] . ' 00:00:00',$this->params['end_date'] . ' 23:59:59']]; $where['a.call_time'] = [ 'between', [ $this->params['start_date'] . ' 00:00:00', $this->params['end_date'] . ' 23:59:59' ] ];
} }
if (!empty($this->params['call_name'])) { if (!empty($this->params['call_name'])) {
$where['name'] = ['LIKE', $this->params['call_name'] . '%']; $where['name'] = [ 'LIKE', $this->params['call_name'] . '%' ];
} }
if (!empty($this->params['call_phone'])) { if (!empty($this->params['call_phone'])) {
$where['phone_no'] = ['LIKE', $this->params['call_phone'] . '%']; $where['phone_no'] = [ 'LIKE', $this->params['call_phone'] . '%' ];
} }
if (!empty($this->params['client_phone'])) { if (!empty($this->params['client_phone'])) {
$where['c.user_phone'] = ['LIKE', $this->params['client_phone'] . '%']; $where['c.user_phone'] = [ 'LIKE', $this->params['client_phone'] . '%' ];
} }
if (!empty($this->params['user_nick'])) { if (!empty($this->params['user_nick'])) {
$where['c.user_nick'] = ['LIKE', '%'.$this->params['user_nick'] . '%']; $where['c.user_nick'] = [ 'LIKE', '%' . $this->params['user_nick'] . '%' ];
} }
if (!empty($this->params['call_type'])) { if (!empty($this->params['call_type'])) {
$where['a.type'] = $this->params['call_type']; $where['a.type'] = $this->params['call_type'];
} }
$data['list'] = $report->getCallList($pageNo, $pageSize, 'id desc', $field, $where); $data['list'] = $report->getCallList($pageNo, $pageSize, 'id desc', $field, $where);
$data['total'] = $report->getCallListTotal($where); $data['total'] = $report->getCallListTotal($where);
return $this->response($result['code'], $result['msg'], $data); return $this->response($result['code'], $result['msg'], $data);
} else { } else {
return view('cell_phone/index'); return view('cell_phone/index');
} }
} }
/** /**
...@@ -89,39 +92,80 @@ class CellPhone extends Basic ...@@ -89,39 +92,80 @@ class CellPhone extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function callCollectList() { public function callCollectList()
{
if ($this->request->isAjax()) { if ($this->request->isAjax()) {
$result['code'] = 200; $result['code'] = 200;
$result['msg'] = ''; $result['msg'] = '';
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$report = new SecretReport(); $report = new SecretReport();
$field = 'a.id,b.phone,sum(time) as time,agents_id,call_type,release_time,start_time'; $field = 'a.id,b.phone,sum(time) as time,agents_id,call_type,release_time,start_time';
$where = []; $where = [];
if (!empty($this->params['start_date'])) { if (!empty($this->params['start_date'])) {
$where['create_time'] = ['> time', $this->params['start_date']]; $where['create_time'] = [ '> time', $this->params['start_date'] ];
} }
if (!empty($this->params['end_date'])) { if (!empty($this->params['end_date'])) {
$where['create_time'] = ['< time', $this->params['end_date']]; $where['create_time'] = [ '< time', $this->params['end_date'] ];
} }
if (!empty($this->params['agents_name'])) { if (!empty($this->params['agents_name'])) {
$where['realName'] = ['LIKE', $this->params['agents_name'] . '%']; $where['realName'] = [ 'LIKE', $this->params['agents_name'] . '%' ];
} }
if (!empty($this->params['phone'])) { if (!empty($this->params['phone'])) {
$where['phone'] = ['LIKE', $this->params['phone'] . '%']; $where['phone'] = [ 'LIKE', $this->params['phone'] . '%' ];
} }
$data['list'] = $report->getCallCollect($pageNo, $pageSize, 'id desc', $field, $where); $data['list'] = $report->getCallCollect($pageNo, $pageSize, 'id desc', $field, $where);
$data['total'] = $report->getCallCollectTotal($where); $data['total'] = $report->getCallCollectTotal($where);
return $this->response($result['code'], $result['msg'], $data); return $this->response($result['code'], $result['msg'], $data);
} else { } else {
return view('cell_phone/agentIndex'); return view('cell_phone/agentIndex');
} }
}
/**
* 绑定手机号
*
* @return \think\Response
*/
public function bindAXB()
{
$call_phone = new CallPhoneService();
$data = $call_phone->bindAXB($this->params['phone_a'], $this->params['phone_b']);
$result['msg'] = '';
if ($data['status'] == 'success') {
$result['code'] = 200;
$result['data']['phone'] = $data['phone'];
} else {
$result['status'] = 101;
$result['msg'] = $data['msg'];
}
return $this->response($result['code'], $result['msg'], $data);
}
/**
* 解除绑定关系
*
* @return \think\Response
*/
public function agentsUnBind()
{
$call_phone = new CallPhoneService();
$data = $call_phone->agentsUnBind($this->params['phone_a'], $this->params['phone_b'], $this->params['phone_x']);
$result['msg'] = '';
if ($data['status'] == 'success') {
$result['code'] = 200;
$result['data']['phone'] = $data['phone'];
} else {
$result['status'] = 101;
$result['msg'] = $data['msg'];
}
return $this->response($result['code'], $result['msg'], $data);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment