Commit 1c396d89 authored by hujun's avatar hujun

隐私号码优化

parent 5ac421ac
...@@ -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,57 +147,67 @@ class PrivacyNumber ...@@ -147,57 +147,67 @@ 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;
$binding_phone_id = []; $where_count['expiry_date'] = [ '<=', $date];
$phone_id = []; $total = $m_bind->getTotal($where_count);
$bind = new BindingPhone();
$redis = RedisExt::getRedis(); $pageSize = 5000;
foreach ($bind_data['data'] as $k => $v) { $pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id'); $bind_data = $m_bind->getBindingPhoneListLimit($pageNo, $pageSize, $fields, $where);
if (empty($agent_id)) {
$agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id'); $binding_phone_id = [];
} $phone_id = [];
$bind = new BindingPhone();
//解除绑定 $redis = RedisExt::getRedis();
if ($v['type'] == 1 && !empty($v['subsId'])) { foreach ($bind_data['data'] as $k => $v) {
//释放阿里云隐私号码 $agent_id = $m_agent->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'id');
$result = PlsDemo::unbindSubscription($v['subsId'], $v['phone_x']); if (empty($agent_id)) {
if ($result->Message == 'OK') { $agent_id = $m_agent_phone->getAgentsByWhere(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
$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); if ($v['type'] == 1 && !empty($v['subsId'])) {
} elseif ($v['type'] == 2 && !empty($v['mappingId'])) { //释放阿里云隐私号码
//释放容联云隐私号码 $result = PlsDemo::unbindSubscription($v['subsId'], $v['phone_x']);
$tong_xun = new RongDemo(); if ($result->Message == 'OK') {
$result = $tong_xun->releaseNumber($v['mappingId']);/*解绑*/ $bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b'], $result->RequestId);
if ($result['statusCode'] == '000000') { $binding_phone_id[$k] = $v['id'];
$bind->unBind($v['phone_x'], $v['phone_a'], $v['phone_b']); $phone_id[$k] = $v['aliYun_phone_id'];
$binding_phone_id[$k] = $v['id']; }
$phone_id[$k] = $v['aliYun_phone_id'];
} else { $call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_1';
$yun_result = $tong_xun->getBindInfo($v['phone_a'], $v['phone_b'], $v['phone_x'], $v['mappingId']); $redis->del($call_key);
if (empty($yun_result['data']['mappingId'])) { } 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']); $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'; $call_key = 'call_'.$agent_id.'_'.$v['phone_a'].'_'.$v['phone_b'].'_2';
$redis->del($call_key); $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; 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