From d40c4b02fc1c3caa926e8a369ec8b52e9fec6dd5 Mon Sep 17 00:00:00 2001 From: "lilong@dgg.net" <123456789> Date: Thu, 10 Sep 2020 20:49:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=B5=E8=AF=9D=E7=9B=91?= =?UTF-8?q?=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/eslListen.php | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/eslListen.php b/app/Console/Commands/eslListen.php index ad1e3a43..6846b229 100644 --- a/app/Console/Commands/eslListen.php +++ b/app/Console/Commands/eslListen.php @@ -32,6 +32,8 @@ class eslListen extends Command protected $recording_dir = 'recordings'; public $url = null; public $hash_table = 'esl_listen'; + public $cdr_table = 'cdr'; + public $asr_table = 'asr'; /** * Create a new command instance. @@ -154,7 +156,7 @@ class eslListen extends Command unset($halffile_b); //更新B接听时间 - DB::table('cdr')->where('uuid',$otherUuid)->update([ + DB::table($this->cdr_table)->where('uuid',$otherUuid)->update([ 'bleg_answer_at' => date('Y-m-d H:i:s'), 'record_file' => str_replace($this->fs_dir,$this->url,$fullfile), 'updated_at' => date('Y-m-d H:i:s'), @@ -163,7 +165,7 @@ class eslListen extends Command }else{ //更新A接听时间 - DB::table('cdr')->where('uuid',$uuid)->update([ + DB::table($this->cdr_table)->where('uuid',$uuid)->update([ 'aleg_answer_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); @@ -187,8 +189,7 @@ class eslListen extends Command $data = json_decode(Redis::hget($this->hash_table,$uuid),true); $data['is_prologue'] += 1; if (isset($data['record_file'])&&file_exists($data['record_file'])){ - $table = 'asr'; - DB::table($table)->insert([ + DB::table($this->asr_table)->insert([ 'uuid' => $data['pid'], 'leg_uuid' => $data['unique_id'], 'start_at' => $data['start_time'], @@ -217,17 +218,30 @@ class eslListen extends Command case 'CHANNEL_HANGUP_COMPLETE': if (Redis::hexists($this->hash_table,$uuid)){ $data = json_decode(Redis::hget($this->hash_table,$uuid),true); - Redis::hdel($this->hash_table, $uuid); - $table = 'cdr'; - $cdr = DB::table($table)->where('uuid',$data['pid'])->whereNull('aleg_end_at')->first(); + Redis::hdel($this->hash_table, $data['pid']); + Redis::hdel($this->hash_table, $data['unique_id']); + $cdr = DB::table($this->cdr_table) + >where(function ($q) use($uuid){ + return $q->where('aleg_uuid',$uuid)->orWhere('bleg_uuid',$uuid); + }) + ->whereNull('aleg_end_at') + ->first(); if ($cdr != null){ - $callsec = $cdr->bleg_answer_at != null ? time()-strtotime($cdr->bleg_answer_at) : 0; + if ($uuid == $data['pid']){ // A的挂断事件 + $callsec = $cdr->bleg_answer_at != null ? time()-strtotime($cdr->bleg_answer_at) : 0; + }else{ // B的挂断事件 + $callsec = Arr::get($info,'variable_billsec',0); + } + $hanguptime = Arr::get($info,'variable_end_stamp',null); + $hanguptime = $hanguptime != null ? urldecode($hanguptime) : null; + //更新通话时长 - DB::table($table)->where('uuid',$data['pid'])->update([ - 'aleg_end_at' => date('Y-m-d H:i:s'), + DB::table($this->cdr_table)->where('uuid',$data['pid'])->update([ + 'aleg_end_at' => $hanguptime, 'billsec' => $callsec, ]); unset($callsec); + unset($hanguptime); } unset($data); unset($table); @@ -243,8 +257,8 @@ class eslListen extends Command } public function setTable(){ - $this->cdr_table = 'cdr'; - $this->asr_table = 'asr'; + //$this->cdr_table = 'cdr'.date('Ym'); + //$this->asr_table = 'asr'.date('Ym'); } }