Commit 1c396d89 authored by hujun's avatar hujun

隐私号码优化

parent 5ac421ac
...@@ -38,6 +38,7 @@ class CallPhoneService ...@@ -38,6 +38,7 @@ class CallPhoneService
private $landlord_phone_day = 0; //房东号码绑定有效期 private $landlord_phone_day = 0; //房东号码绑定有效期
private $city; private $city;
public $redis; public $redis;
private $m_bind;
public function __construct(string $city = '上海市') public function __construct(string $city = '上海市')
{ {
...@@ -50,6 +51,7 @@ class CallPhoneService ...@@ -50,6 +51,7 @@ class CallPhoneService
$this->is_privacy = empty($this->is_privacy) ? 0 : $this->is_privacy; $this->is_privacy = empty($this->is_privacy) ? 0 : $this->is_privacy;
$this->day_num = empty($this->day_num) ? 1 : $this->day_num + 1; $this->day_num = empty($this->day_num) ? 1 : $this->day_num + 1;
$this->landlord_phone_day = empty($this->landlord_phone_day) ? 1 : $this->landlord_phone_day + 1; $this->landlord_phone_day = empty($this->landlord_phone_day) ? 1 : $this->landlord_phone_day + 1;
$this->m_bind = new BindingPhone();
} }
/** /**
...@@ -70,7 +72,7 @@ class CallPhoneService ...@@ -70,7 +72,7 @@ class CallPhoneService
public function bindAXB($phone_a, $phone_b, $record = true, int $user_id, $agent_id, string $agent_name, int $landlord, int $house_id) public function bindAXB($phone_a, $phone_b, $record = true, int $user_id, $agent_id, string $agent_name, int $landlord, int $house_id)
{ {
$result['status'] = 'failed'; $result['status'] = 'failed';
$type = '';
if (strlen($phone_a) != 11) { if (strlen($phone_a) != 11) {
$result['msg'] = '本机号码格式错误,请重新编辑!'; $result['msg'] = '本机号码格式错误,请重新编辑!';
return $result; return $result;
...@@ -103,7 +105,6 @@ class CallPhoneService ...@@ -103,7 +105,6 @@ class CallPhoneService
return $result; return $result;
} }
$call_phone = [];
$this->phone_a = $phone_a;//经纪人手机号 $this->phone_a = $phone_a;//经纪人手机号
$this->phone_b = $phone_b;//客户手机号 $this->phone_b = $phone_b;//客户手机号
$this->record = $record; //是否录音 $this->record = $record; //是否录音
...@@ -124,7 +125,6 @@ class CallPhoneService ...@@ -124,7 +125,6 @@ class CallPhoneService
} }
$call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy; $call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy;
$phone_x = $this->redis->get($call_key); $phone_x = $this->redis->get($call_key);
$bind = new BindingPhone();
if (!empty($phone_x)) { if (!empty($phone_x)) {
$result['status'] = 'success'; $result['status'] = 'success';
...@@ -159,7 +159,7 @@ class CallPhoneService ...@@ -159,7 +159,7 @@ class CallPhoneService
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
$type = 'AliYunBindAxb'; $type = 'AliYunBindAxb';
$this->redis->set($call_key, $call_phone['phone'], strtotime($this->expiry_date) - time()); $this->redis->set($call_key, $call_phone['phone'], strtotime($this->expiry_date) - time());
$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); $this->m_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);
} else { } else {
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
} }
...@@ -172,7 +172,7 @@ class CallPhoneService ...@@ -172,7 +172,7 @@ class CallPhoneService
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
$type = 'YunTongXunBindAxb'; $type = 'YunTongXunBindAxb';
$this->redis->set($call_key, $call_phone['phone'], strtotime($this->expiry_date) - time()); $this->redis->set($call_key, $call_phone['phone'], strtotime($this->expiry_date) - time());
$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); $this->m_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);
} else { } else {
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
} }
...@@ -237,16 +237,14 @@ class CallPhoneService ...@@ -237,16 +237,14 @@ class CallPhoneService
return $data; return $data;
} }
$phone = new BindingPhone();
try { try {
if ($this->is_privacy == 1) { if ($this->is_privacy == 1) {
/*阿里云*/ /*阿里云*/
$subsId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'subsId'); $subsId = $this->m_bind->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'subsId');
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/ $result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
$phone->unBind($this->phone_x, $this->phone_a, $this->phone_b); $this->m_bind->unBind($this->phone_x, $this->phone_a, $this->phone_b);
} else { } else {
$data['status'] = 'failed'; $data['status'] = 'failed';
$data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!'; $data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!';
...@@ -256,17 +254,17 @@ class CallPhoneService ...@@ -256,17 +254,17 @@ class CallPhoneService
} }
} elseif ($this->is_privacy == 2) { } elseif ($this->is_privacy == 2) {
/*容联云*/ /*容联云*/
$mappingId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'mappingId'); $mappingId = $this->m_bind->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'mappingId');
$yun_tong_xun = new RongDemo(); $yun_tong_xun = new RongDemo();
if ($mappingId) { if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/ $result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
if ($result['statusCode'] == '000000') { if ($result['statusCode'] == '000000') {
$phone->unBind($this->phone_x, $this->phone_a, $this->phone_b); $this->m_bind->unBind($this->phone_x, $this->phone_a, $this->phone_b);
} else { } else {
$yun_result = $yun_tong_xun->getBindInfo($this->phone_a, $this->phone_b, $this->phone_x, $mappingId); $yun_result = $yun_tong_xun->getBindInfo($this->phone_a, $this->phone_b, $this->phone_x, $mappingId);
if (empty($yun_result['data']['mappingId'])) { if (empty($yun_result['data']['mappingId'])) {
$phone->unBind($this->phone_x, $this->phone_a, $this->phone_b); $this->m_bind->unBind($this->phone_x, $this->phone_a, $this->phone_b);
} }
} }
} else { } else {
...@@ -293,7 +291,7 @@ class CallPhoneService ...@@ -293,7 +291,7 @@ class CallPhoneService
* @param $agent_id * @param $agent_id
* @return mixed * @return mixed
*/ */
public function agentsUnBindRedis($phone_a, $phone_b, $phone_x, $user_id, $agent_id) public function agentsUnBindRedis($phone_a, $phone_b, $phone_x, $user_id = 0, $agent_id = 0)
{ {
$data['status'] = 'success'; $data['status'] = 'success';
$data['msg'] = ''; $data['msg'] = '';
...@@ -334,16 +332,14 @@ class CallPhoneService ...@@ -334,16 +332,14 @@ class CallPhoneService
return $data; return $data;
} }
$phone = new BindingPhone();
$call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy; $call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy;
try { try {
if ($this->is_privacy == 1) { if ($this->is_privacy == 1) {
/*阿里云*/ /*阿里云*/
$subsId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'subsId'); $subsId = $this->m_bind->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'subsId');
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/ $result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/
if ($result->Message != 'OK') { if ($result->Message != 'OK') {
// } else {
$data['status'] = 'failed'; $data['status'] = 'failed';
$data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!'; $data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!';
} }
...@@ -352,14 +348,11 @@ class CallPhoneService ...@@ -352,14 +348,11 @@ class CallPhoneService
} }
} elseif ($this->is_privacy == 2) { } elseif ($this->is_privacy == 2) {
/*容联云*/ /*容联云*/
$mappingId = $phone->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'mappingId'); $mappingId = $this->m_bind->getSubsId($this->phone_x, $this->phone_a, $this->phone_b, 1, 'mappingId');
$yun_tong_xun = new RongDemo(); $yun_tong_xun = new RongDemo();
if ($mappingId) { if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/ $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
// if ($result['statusCode'] == '000000') {
// $this->redis->del($call_key);
// }
} else { } else {
$data['msg'] = '没有号码绑定关系,请忽略!。'; $data['msg'] = '没有号码绑定关系,请忽略!。';
} }
...@@ -393,7 +386,22 @@ class CallPhoneService ...@@ -393,7 +386,22 @@ class CallPhoneService
$this->subs_id = $result->SecretBindDTO->SubsId; $this->subs_id = $result->SecretBindDTO->SubsId;
$this->request_id = $result->RequestId; $this->request_id = $result->RequestId;
} elseif ($result->Code == 'isv.NO_AVAILABLE_NUMBER') { } elseif ($result->Code == 'isv.NO_AVAILABLE_NUMBER') {
$where['a.status'] = 1;
$where['a.phone_a'] = $this->phone_a;
$where['a.type'] = $this->is_privacy;
$agent_call = $this->m_bind->getPhoneX('a.phone_a,a.phone_b,b.phone_x', $where);
$result_unbind = $this->agentsUnBindRedis($agent_call['phone_a'], $agent_call['phone_b'], $agent_call['phone_x']);
$data['msg'] = '号码使用完,请联系运营人员。'; $data['msg'] = '号码使用完,请联系运营人员。';
if ($result_unbind['status'] == 'successful') {
$result = PlsDemo::bindAxb($this->phone_a, $this->phone_b, $this->expiry_date, $this->record, '', $this->city);
$data['status'] = 'success';
$data['msg'] = '绑定成功。';
$data['phone'] = $result->SecretBindDTO->SecretNo;
$this->subs_id = $result->SecretBindDTO->SubsId;
$this->request_id = $result->RequestId;
$this->m_bind->unBind($agent_call['phone_x'], $agent_call['phone_a'], $agent_call['phone_b']);
}
} else { } else {
$data['msg'] = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!'; $data['msg'] = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
} }
...@@ -413,7 +421,7 @@ class CallPhoneService ...@@ -413,7 +421,7 @@ class CallPhoneService
public function yunTongXun() public function yunTongXun()
{ {
$yun_tong_xun = new RongDemo(); $yun_tong_xun = new RongDemo();
$data = [];
if ($this->record) { if ($this->record) {
$record = 'true'; $record = 'true';
} else { } else {
...@@ -446,6 +454,25 @@ class CallPhoneService ...@@ -446,6 +454,25 @@ class CallPhoneService
//绑定失败返回错误信息 //绑定失败返回错误信息
$data['status'] = 'failed'; $data['status'] = 'failed';
$data['msg'] = $result['code_msg']; $data['msg'] = $result['code_msg'];
if ($result['code_msg'] == '无空闲号码') {
$where['a.status'] = 1;
$where['a.phone_a'] = $this->phone_a;
$where['a.type'] = $this->is_privacy;
$agent_call = $this->m_bind->getPhoneX('a.phone_a,a.phone_b,b.phone_x', $where);
$result_unbind = $this->agentsUnBindRedis($agent_call['phone_a'], $agent_call['phone_b'], $agent_call['phone_x']);
if ($result_unbind['status'] == 'successful') {
$result = $yun_tong_xun->setNumber($this->phone_a, $this->phone_b, $area, $this->expiry_date, $record);
if ($result['statusCode'] == '000000') {
$data['status'] = 'success';
$data['msg'] = '绑定成功。';
$data['phone'] = $result['data']['xNumber'];
$this->mapping_id = $result['data']['mappingId'];
}
$this->m_bind->unBind($agent_call['phone_x'], $agent_call['phone_a'], $agent_call['phone_b']);
}
}
} }
} }
...@@ -489,8 +516,7 @@ class CallPhoneService ...@@ -489,8 +516,7 @@ class CallPhoneService
*/ */
public function getBindNum($phone_b, $phone_a, $status = 1) public function getBindNum($phone_b, $phone_a, $status = 1)
{ {
$m_bind = new BindingPhone(); return $this->m_bind->getCallNumber($phone_a, $phone_b, $status);
return $m_bind->getCallNumber($phone_a, $phone_b, $status);
} }
/** /**
......
...@@ -132,6 +132,33 @@ class BindingPhone extends BaseModel ...@@ -132,6 +132,33 @@ class BindingPhone extends BaseModel
return $data; return $data;
} }
/**
* 获取绑定信息
*
* @param $pageNo
* @param $pageSize
* @param $field
* @param $where
* @return mixed
*/
public function getBindingPhoneListLimit($pageNo, $pageSize, $field, $where)
{
$data['data'] = [];
try {
$data['data'] = $this->field($field)->alias('a')
->join('aliYun_phone b', 'a.aliYun_phone_id = b.id', 'left')
->where($where)
->page($pageNo)
->limit($pageSize)
->select();
$data['status'] = 'successful';
} catch (\Exception $e) {
$data['status'] = 'fail';
$data['msg'] = $e->getMessage();
}
return $data;
}
/** /**
* 更新绑定号码与阿里云绑定不一致的问题 * 更新绑定号码与阿里云绑定不一致的问题
* *
......
...@@ -147,17 +147,25 @@ class PrivacyNumber ...@@ -147,17 +147,25 @@ class PrivacyNumber
$m_bind = new BindingPhone(); $m_bind = new BindingPhone();
$m_agent = new AAgents(); $m_agent = new AAgents();
$m_agent_phone = new AAgentsPhone(); $m_agent_phone = new AAgentsPhone();
$date = date('Y-m-d') . ' 23:59:59';
$fields = 'a.id,aliYun_phone_id,expiry_date,phone_x,phone_a,phone_b,subsId,a.type,a.mappingId'; $fields = 'a.id,aliYun_phone_id,expiry_date,phone_x,phone_a,phone_b,subsId,a.type,a.mappingId';
$where['a.status'] = 1; $where['a.status'] = 1;
$where['a.expiry_date'] = [ '<=', date('Y-m-d') . ' 23:59:59' ]; $where['a.expiry_date'] = [ '<=', $date];
$bind_data = $m_bind->getBindingPhoneList($fields, $where);
$where_count['status'] = 1;
$where_count['expiry_date'] = [ '<=', $date];
$total = $m_bind->getTotal($where_count);
$pageSize = 5000;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$bind_data = $m_bind->getBindingPhoneListLimit($pageNo, $pageSize, $fields, $where);
$binding_phone_id = []; $binding_phone_id = [];
$phone_id = []; $phone_id = [];
$bind = new BindingPhone(); $bind = new BindingPhone();
$redis = RedisExt::getRedis(); $redis = RedisExt::getRedis();
foreach ($bind_data['data'] as $k => $v) { foreach ($bind_data['data'] as $k => $v) {
$agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id'); $agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id');
if (empty($agent_id)) { if (empty($agent_id)) {
$agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id'); $agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
...@@ -198,6 +206,8 @@ class PrivacyNumber ...@@ -198,6 +206,8 @@ class PrivacyNumber
$id['aliYun_binding_phone'] = implode(',', $binding_phone_id); $id['aliYun_binding_phone'] = implode(',', $binding_phone_id);
$id['aliYun_phone'] = implode(',', array_unique($phone_id)); $id['aliYun_phone'] = implode(',', array_unique($phone_id));
Log::write(json_encode($id), 'AliYunReleaseNumber'); //记录日志 Log::write(json_encode($id), 'AliYunReleaseNumber'); //记录日志
}
return; return;
} }
......
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