Commit 0ddeafc5 authored by hujun's avatar hujun

隐私号码回调接口优化

parent 395cf1f7
......@@ -149,4 +149,8 @@ class AliYunSecretReport extends BaseModel
->where($where)
->select();
}
public function insertDataAll($data) {
$this->allowField(true)->saveAll($data);
}
}
\ No newline at end of file
......@@ -475,7 +475,7 @@ Route::group('chat', [
Route::group('task', [
'exclusiveExpirationTime' => ['task/exclusive/exclusiveExpirationTime', ['method' => 'get']], //独家过期时间
'addReport' => ['task/PrivacyNumber/addReport', ['method' => 'get|post']], //阿里大于隐私号码回调
'addReport' => ['task/PrivacyNumber/addReportV2', ['method' => 'get|post']], //阿里大于隐私号码回调
'queryRecordFile' => ['task/PrivacyNumber/queryRecordFile', ['method' => 'get']], //下载录音
'releaseNumber' => ['task/PrivacyNumber/releaseNumber', ['method' => 'get']], //释放号码
'checkBindPhone' => ['task/PrivacyNumber/checkBindPhone', ['method' => 'get']], //检查绑定关系,去除表中不存在的绑定关系
......
......@@ -90,10 +90,11 @@ class PrivacyNumber
*/
public function addReportV2()
{
$post_data = Request::instance()->param();
foreach ($post_data as $k=>$v) {
$post_data = Request::instance()->param();
$save_data_arr = $save_data = [];
foreach ($post_data as $k => $v) {
$save_data = $v;
$save_data['report_id'] = $post_data[0]['id'];
$save_data['report_id'] = $v['id'];
unset($save_data['id']); //阿里大于返回是的id改为report_id
if ($v['phone_no']) {
$agent_where['phone'] = $v['phone_no'];
......@@ -106,14 +107,14 @@ class PrivacyNumber
$agent_id = $this->m_agent_phone->getAgentsByWhere($phone_where, 'agents_id');
}
$save_data['agents_id'] = $agent_id;
$save_data['users_id'] = $this->m_user->getUserByWhereValue(['user_phone'=>$save_data['peer_no']], 'id');
$save_data['users_id'] = $this->m_user->getUserByWhereValue('id', ['user_phone' => $save_data['peer_no']]);
}
$call_time = strtotime($save_data['release_time']) - strtotime($save_data['start_time']);
$save_data['time'] = $call_time;
if ($call_time > 0) {
$end_date = date('Y-m-d H:i:s', time());
$end_date = date('Y-m-d H:i:s', time());
$start_date = date('Y-m-d H:i:s', strtotime("-1 day"));
$num = $this->m_secret_report->getCallNumber($post_data[0]['phone_no'], $post_data[0]['peer_no'], $start_date, $end_date);
if (empty($num)) {
......@@ -122,11 +123,11 @@ class PrivacyNumber
}
}
$this->m_secret_report->allowField(true)->save($save_data);
$save_data_arr[] = $save_data;
Log::write(json_encode($save_data), 'AliYunSecretReport'); //记录日志
}
Log::write(json_encode($post_data[0]), 'AliYunSecretReport'); //记录日志
return json_encode([ 'code' => 0, 'msg' => '接收成功' ]);
$this->m_secret_report->insertDataAll($save_data_arr);
return json_encode(['code' => 0, 'msg' => '接收成功']);
}
/**
......@@ -154,12 +155,11 @@ class PrivacyNumber
$where['record_down'] = 1;
}
$m_secret = new AliYunSecretReport();
$fields = 'id,call_id,call_time,voice_file,type,record_down,mp3_url';
$where['time'] = [ '>', 0 ];
$where['type'] = [ '>', 0 ];
$down_data = $m_secret->secretReportAll($fields, $where);
$down_data = $this->m_secret_report->secretReportAll($fields, $where);
$is_down = '';
foreach ($down_data as $k => $v) {
......@@ -189,7 +189,7 @@ class PrivacyNumber
if ($data['record_down'] == 1) {
$data['voice_file'] = date('Ymd') . '/' . basename($is_down);
}
$m_secret->updateDownStatus($v['id'], $data);
$this->m_secret_report->updateDownStatus($v['id'], $data);
}
}
......@@ -204,9 +204,6 @@ class PrivacyNumber
public function releaseNumber()
{
set_time_limit(0);
$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;
......@@ -214,21 +211,20 @@ class PrivacyNumber
$where_count['status'] = 1;
$where_count['expiry_date'] = [ '<=', $date];
$total = $m_bind->getTotal($where_count);
$total = $this->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);
$bind_data = $this->m_bind->getBindingPhoneListLimit($pageNo, $pageSize, $fields, $where);
$binding_phone_id = [];
$phone_id = [];
$bind = new BindingPhone();
foreach ($bind_data['data'] as $k => $v) {
$agent_id = $m_agent->getAgentsByWhereColumn(['status'=>0, 'phone'=>$v['phone_a']], 'id');
$agent_id = $this->m_agent->getAgentsByWhereColumn(['status'=>0, 'phone'=>$v['phone_a']], 'id');
if (empty($agent_id)) {
$agent_id = $m_agent_phone->getAgentsByWhereColumn(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
$agent_id = $this->m_agent_phone->getAgentsByWhereColumn(['status'=>0, 'phone'=>$v['phone_a']], 'agents_id');
}
//解除绑定
......@@ -278,7 +274,7 @@ class PrivacyNumber
}
if (!empty($update)) {
$bind->updateAll($update);
$this->m_bind->updateAll($update);
unset($update);
}
......@@ -313,7 +309,7 @@ class PrivacyNumber
$call_type = 1;
}
$date = [
$data = [
'call_id' => $params['callId'],
'phone_no' => $phone_a,/*A*/
'secret_no' => $params['servingNum'],/*X*/
......@@ -331,21 +327,26 @@ class PrivacyNumber
];
if ($phone_a) {
$agents_id = Db::table('a_agents')->where(['phone'=>$phone_a, 'status'=>0])->value('id');
if (empty($agents_id)) {
$agents_id = Db::table('a_agents_phone')->where(['phone'=>$phone_a,'status'=>0])->value('agents_id');
$agent_where['phone'] = $phone_a;
$agent_where['status'] = 0;
$agent_where['password'] = ['NOT NULL'];
$agent_id = $this->m_agent->getAgentsByWhere($agent_where, 'id');
if (empty($agent_id)) {
$phone_where['phone'] = $phone_a;
$phone_where['status'] = 0;
$agent_id = $this->m_agent_phone->getAgentsByWhere($phone_where, 'agents_id');
}
$date['agents_id'] = $agents_id;
$date['users_id'] = Db::table('u_users')->where('user_phone', $phone_b)->value('id');
$data['agents_id'] = $agent_id;
$data['users_id'] = $this->m_user->getUserByWhereValue('id', ['user_phone' => $phone_b]);
}
$this->m_secret_report->allowField(true)->save($date);
$this->m_secret_report->insertDataAll([0=>$data]);
$str = date('Y-m-d h:i:s') . ' 容联云话单' . var_export($params, true);
if ($params['duration'] > 0 && $date['users_id']) {
if ($params['duration'] > 0 && $data['users_id']) {
$m_service = new ClientService();
$m_service->saveCallNumByUserId($date['users_id']);
$m_service->saveCallNumByUserId($data['users_id']);
}
Log::write($str, 'rongBilledInformUrl'); //记录日志
return json_encode([ "statusCode" => '000000', 'msg' => '接收成功' ]);
......@@ -361,7 +362,7 @@ class PrivacyNumber
$params = Request::instance()->param();
$where['call_id'] = $params['callId'];
$update['mp3_url'] = $params['recordUrl'];
$this->m_secret_report->save($update, $where);
$this->m_secret_report->editData($update, $params['callId'], 'call_id');
$str = date('Y-m-d h:i:s') . ' 容联云录音' . var_export($params, true);
Log::write($str, 'rongRecordingInformUrl'); //记录日志
return json_encode([ "statusCode" => '000000', 'msg' => '接收成功' ]);
......
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