Commit 1c396d89 authored by hujun's avatar hujun

隐私号码优化

parent 5ac421ac
......@@ -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