Commit 1c396d89 authored by hujun's avatar hujun

隐私号码优化

parent 5ac421ac
......@@ -38,6 +38,7 @@ class CallPhoneService
private $landlord_phone_day = 0; //房东号码绑定有效期
private $city;
public $redis;
private $m_bind;
public function __construct(string $city = '上海市')
{
......@@ -50,6 +51,7 @@ class CallPhoneService
$this->is_privacy = empty($this->is_privacy) ? 0 : $this->is_privacy;
$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->m_bind = new BindingPhone();
}
/**
......@@ -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)
{
$result['status'] = 'failed';
$type = '';
if (strlen($phone_a) != 11) {
$result['msg'] = '本机号码格式错误,请重新编辑!';
return $result;
......@@ -103,7 +105,6 @@ class CallPhoneService
return $result;
}
$call_phone = [];
$this->phone_a = $phone_a;//经纪人手机号
$this->phone_b = $phone_b;//客户手机号
$this->record = $record; //是否录音
......@@ -124,7 +125,6 @@ class CallPhoneService
}
$call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy;
$phone_x = $this->redis->get($call_key);
$bind = new BindingPhone();
if (!empty($phone_x)) {
$result['status'] = 'success';
......@@ -159,7 +159,7 @@ class CallPhoneService
$result['msg'] = $call_phone['msg'];
$type = 'AliYunBindAxb';
$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 {
$result['msg'] = $call_phone['msg'];
}
......@@ -172,7 +172,7 @@ class CallPhoneService
$result['msg'] = $call_phone['msg'];
$type = 'YunTongXunBindAxb';
$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 {
$result['msg'] = $call_phone['msg'];
}
......@@ -237,16 +237,14 @@ class CallPhoneService
return $data;
}
$phone = new BindingPhone();
try {
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) {
$result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/
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 {
$data['status'] = 'failed';
$data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!';
......@@ -256,17 +254,17 @@ class CallPhoneService
}
} 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();
if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
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 {
$yun_result = $yun_tong_xun->getBindInfo($this->phone_a, $this->phone_b, $this->phone_x, $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 {
......@@ -293,7 +291,7 @@ class CallPhoneService
* @param $agent_id
* @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['msg'] = '';
......@@ -334,16 +332,14 @@ class CallPhoneService
return $data;
}
$phone = new BindingPhone();
$call_key = 'call_'.$agent_id.'_'.$this->phone_a.'_'.$this->phone_b.'_'.$this->is_privacy;
try {
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) {
$result = PlsDemo::unbindSubscription($subsId, $this->phone_x);/*解绑*/
if ($result->Message != 'OK') {
// } else {
$data['status'] = 'failed';
$data['msg'] = '解除失败,如果需要继续与客户沟通,请联系运营!';
}
......@@ -352,14 +348,11 @@ class CallPhoneService
}
} 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();
if ($mappingId) {
$result = $yun_tong_xun->releaseNumber($mappingId);/*解绑*/
// if ($result['statusCode'] == '000000') {
// $this->redis->del($call_key);
// }
$yun_tong_xun->releaseNumber($mappingId);/*解绑*/
} else {
$data['msg'] = '没有号码绑定关系,请忽略!。';
}
......@@ -393,7 +386,22 @@ class CallPhoneService
$this->subs_id = $result->SecretBindDTO->SubsId;
$this->request_id = $result->RequestId;
} 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'] = '号码使用完,请联系运营人员。';
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 {
$data['msg'] = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
}
......@@ -413,7 +421,7 @@ class CallPhoneService
public function yunTongXun()
{
$yun_tong_xun = new RongDemo();
$data = [];
if ($this->record) {
$record = 'true';
} else {
......@@ -446,6 +454,25 @@ class CallPhoneService
//绑定失败返回错误信息
$data['status'] = 'failed';
$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
*/
public function getBindNum($phone_b, $phone_a, $status = 1)
{
$m_bind = new BindingPhone();
return $m_bind->getCallNumber($phone_a, $phone_b, $status);
return $this->m_bind->getCallNumber($phone_a, $phone_b, $status);
}
/**
......
......@@ -132,6 +132,33 @@ class BindingPhone extends BaseModel
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,57 +147,67 @@ class PrivacyNumber
$m_bind = new BindingPhone();
$m_agent = new AAgents();
$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';
$where['a.status'] = 1;
$where['a.expiry_date'] = [ '<=', date('Y-m-d') . ' 23:59:59' ];
$bind_data = $m_bind->getBindingPhoneList($fields, $where);
$binding_phone_id = [];
$phone_id = [];
$bind = new BindingPhone();
$redis = RedisExt::getRedis();
foreach ($bind_data['data'] as $k => $v) {
$agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id');
if (empty($agent_id)) {
$agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
}
//解除绑定
if ($v['type'] == 1 && !empty($v['subsId'])) {
//释放阿里云隐私号码
$result = PlsDemo::unbindSubscription($v['subsId'], $v['phone_x']);
if ($result->Message == 'OK') {
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b'], $result->RequestId);
$binding_phone_id[$k] = $v['id'];
$phone_id[$k] = $v['aliYun_phone_id'];
$where['a.expiry_date'] = [ '<=', $date];
$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 = [];
$phone_id = [];
$bind = new BindingPhone();
$redis = RedisExt::getRedis();
foreach ($bind_data['data'] as $k => $v) {
$agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id');
if (empty($agent_id)) {
$agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
}
$call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_1';
$redis->del($call_key);
} elseif ($v['type'] == 2 && !empty($v['mappingId'])) {
//释放容联云隐私号码
$tong_xun = new RongDemo();
$result = $tong_xun->releaseNumber($v['mappingId']);/*解绑*/
if ($result['statusCode'] == '000000') {
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b']);
$binding_phone_id[$k] = $v['id'];
$phone_id[$k] = $v['aliYun_phone_id'];
} else {
$yun_result = $tong_xun->getBindInfo($v['phone_a'], $v['phone_b'], $v['phone_x'], $v['mappingId']);
if (empty($yun_result['data']['mappingId'])) {
//解除绑定
if ($v['type'] == 1 && !empty($v['subsId'])) {
//释放阿里云隐私号码
$result = PlsDemo::unbindSubscription($v['subsId'], $v['phone_x']);
if ($result->Message == 'OK') {
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b'], $result->RequestId);
$binding_phone_id[$k] = $v['id'];
$phone_id[$k] = $v['aliYun_phone_id'];
}
$call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_1';
$redis->del($call_key);
} elseif ($v['type'] == 2 && !empty($v['mappingId'])) {
//释放容联云隐私号码
$tong_xun = new RongDemo();
$result = $tong_xun->releaseNumber($v['mappingId']);/*解绑*/
if ($result['statusCode'] == '000000') {
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b']);
$binding_phone_id[$k] = $v['id'];
$phone_id[$k] = $v['aliYun_phone_id'];
} else {
$yun_result = $tong_xun->getBindInfo($v['phone_a'], $v['phone_b'], $v['phone_x'], $v['mappingId']);
if (empty($yun_result['data']['mappingId'])) {
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b']);
}
}
}
$call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_2';
$redis->del($call_key);
$call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_2';
$redis->del($call_key);
}
}
$id['aliYun_binding_phone'] = implode(',', $binding_phone_id);
$id['aliYun_phone'] = implode(',', array_unique($phone_id));
Log::write(json_encode($id), 'AliYunReleaseNumber'); //记录日志
}
$id['aliYun_binding_phone'] = implode(',', $binding_phone_id);
$id['aliYun_phone'] = implode(',', array_unique($phone_id));
Log::write(json_encode($id), 'AliYunReleaseNumber'); //记录日志
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