From c40851d49e222ff587192e160c92fb0832c99d48 Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Fri, 18 Oct 2019 11:18:16 +0800 Subject: [PATCH] test1 --- common/models/UserT.php | 196 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/common/models/UserT.php b/common/models/UserT.php index 27e1896..ed2e3c2 100644 --- a/common/models/UserT.php +++ b/common/models/UserT.php @@ -2,6 +2,7 @@ namespace common\models; +use common\libs\MyLib; use Yii; /** @@ -288,4 +289,199 @@ class UserT extends \common\models\Base return $pay_chexian + $pay_nochexian + $pay_dz; } + + public function totalCallNum($begin_date,$end_date) + { + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + + return $query->count(); + } + + static public function totalCallTotallNum($begin_date,$end_date,$company_id,$user_id) + { + $query = NetworkPhoneT::find() + ->leftJoin('user_t','user_t.id=network_phone_t.user_id'); + if($begin_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_date.'"'); + } + if($company_id != 0){ + $query = $query->andWhere('user_t.company_id='.$company_id); + } + if($user_id != 0){ + $query = $query->andWhere('user_t.id='.$user_id); + } + + return $query->count(); + } + + public function totalCallTime($begin_date,$end_date) + { + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + $time = $query->sum('call_duration'); + + return MyLib::HMSByTime($time); + } + + public function totalCallTimeOut($begin_date,$end_date) + { + $query = NetworkPhoneT::find()->where('user_id='.$this->id)->andWhere('is_called=0 or is_called is null'); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + $time = $query->sum('call_duration'); + + return MyLib::HMSByTime($time); + } + + static public function allCallTime($begin_date,$end_date,$company_id,$user_id) + { + $query = NetworkPhoneT::find() + ->leftJoin('user_t','user_t.id=network_phone_t.user_id'); + if($begin_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_date.'"'); + } + if($company_id != 0){ + $query = $query->andWhere('user_t.company_id='.$company_id); + } + if($user_id != 0){ + $query = $query->andWhere('user_t.id='.$user_id); + } + $time = $query->sum('network_phone_t.call_duration'); + + return MyLib::HMSByTime($time); + } + static public function allCallTimeOut($begin_date,$end_date,$company_id,$user_id) + { + $query = NetworkPhoneT::find()->where('is_called=0') + ->leftJoin('user_t','user_t.id=network_phone_t.user_id'); + if($begin_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_date.'"'); + } + if($company_id != 0){ + $query = $query->andWhere('user_t.company_id='.$company_id); + } + if($user_id != 0){ + $query = $query->andWhere('user_t.id='.$user_id); + } + $time = $query->sum('network_phone_t.call_duration'); + + return MyLib::HMSByTime($time); + } + + static public function allCallTimeOutBuy($begin_date,$end_date,$company_id,$user_id) + { + $query = NetworkPhoneT::find() + ->leftJoin('user_t','user_t.id=network_phone_t.user_id'); + if($begin_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_date.'"'); + } + if($company_id != 0){ + $query = $query->andWhere('user_t.company_id='.$company_id); + } + if($user_id != 0){ + $query = $query->andWhere('user_t.id='.$user_id); + } + $items = $query->all(); + $i_all = 0; + foreach ($items as $item){ + $i = $item->call_duration; + $i_all += MyLib::HMSByTimeBuy($i); + + } + + return $i_all; + } + + public function callInTotalNum($begin_date,$end_date) + { + $t = NetworkPhoneAssignT::find()->where('user_id='.$this->id)->one(); + $phone = $t?$t->phone:0; + + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + + return $query->andWhere('is_called=1')->count(); + } + + public function callInSucNum($begin_date,$end_date) + { + $t = NetworkPhoneAssignT::find()->where('user_id='.$this->id)->one(); + $phone = $t?$t->phone:0; + + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + + return $query->andWhere('is_called=1')->andWhere('call_result="ANSWERED"')->count(); + } + + public function callOutTotalNum($begin_date,$end_date) + { + $t = NetworkPhoneAssignT::find()->where('user_id='.$this->id)->one(); + $phone = $t?$t->phone:0; + + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + +// return $query->andWhere('caller="'.$phone.'"')->count(); + + return $query->andWhere('is_called=0 or is_called is null')->count(); + } + + public function callOutSucNum($begin_date,$end_date) + { + $t = NetworkPhoneAssignT::find()->where('user_id='.$this->id)->one(); + $phone = $t?$t->phone:0; + + $query = NetworkPhoneT::find()->where('user_id='.$this->id); + if($begin_date != ''){ + $query = $query->andWhere('begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('begin_date<="'.$end_date.'"'); + } + + return $query->andWhere('is_called=0 or is_called is null')->andWhere('call_result="ANSWERED"')->count(); + } }