diff --git a/frontend/controllers/PhoneCenterController.php b/frontend/controllers/PhoneCenterController.php new file mode 100644 index 0000000..0fb4fb4 --- /dev/null +++ b/frontend/controllers/PhoneCenterController.php @@ -0,0 +1,649 @@ +request; + $begin_time = $request->get('begin_time',date('Y-m-d')); + $end_time = $request->get('end_time',date('Y-m-d')); + $username = $request->get('username',''); + $caller = $request->get('caller',''); + $called = $request->get('called',''); + $duration_begin = $request->get('duration_begin',''); + $duration_end = $request->get('duration_end',''); + $call_result = $request->get('call_result',''); + $is_called = $request->get('is_called',''); + $page = $request->get('page',0); + + $company_type = $request->get('company_type',0);//0显示全部,1只显示江西,2只显示湖北 + + if($company_type == 1){ + $company_id=2; + }elseif ($company_type == 2){ + $company_id=3; + } + + $query = NetworkPhoneT::find() + ->leftJoin('user_t','user_t.id=network_phone_t.user_id') + ->where('user_t.is_delete=0 and user_t.is_leave=0'); + + + if($company_type == 3){ + $query = $query->andWhere('user_t.id="'.$this->my->id.'"'); + } + if($begin_time != ''){ + $query = $query->andWhere('network_phone_t.begin_date>="'.$begin_time.'"'); + } + if($end_time != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_time.'"'); + } + if($caller != ''){ + $query = $query->andWhere('network_phone_t.caller='.$caller); + } + if($called != ''){ + $query = $query->andWhere('network_phone_t.called='.$called); + } + if($duration_begin != ''){ + $query = $query->andWhere('network_phone_t.call_duration>='.$duration_begin); + } + if($duration_end != ''){ + $query = $query->andWhere('network_phone_t.call_duration<='.$duration_end); + } + if($call_result != ''){ + $query = $query->andWhere('network_phone_t.call_result="'.$call_result.'"'); + } + if($is_called == 1){ + $query = $query->andWhere('network_phone_t.is_called=1'); + }elseif ($is_called ==2){ + $query = $query->andWhere('network_phone_t.is_called=0 or network_phone_t.is_called is null'); + } + if($username != ''){ + $query = $query->andWhere('user_t.username="'.$username.'"'); + } + + if($company_id > 0) { + $query = $query->andWhere('user_t.company_id='.$company_id); + } + + + + $company_items = CompanyT::find()->all(); + + + $total = $query->count(); + + $pagination = new Pagination(['totalCount' => $total,'pageSize'=>20]); + $pagination->setPage($page-1); + + $query = $query->offset($pagination->offset)->limit($pagination->limit); + + + $page_info = MyLib::getPageInfo($pagination); + + + $record_items = $query->orderBy('network_phone_t.id desc') + ->all(); + + return $this->render('call-records',[ + 'record_items' => $record_items, + 'begin_time' => $begin_time, + 'end_time' => $end_time, + 'is_called' => $is_called, + + 'username' => $username, + 'caller' => $caller, + 'called' => $called, + 'duration_begin' => $duration_begin, + 'duration_end' => $duration_end, + 'call_result' => $call_result, + 'page_info' => $page_info, + 'company_items'=>$company_items, + 'company_type'=>$company_type + ]); + } + + public function actionDownloadFile(){ + $url = 'http://rec1.1ketong.com:8090/pull0/764/20190311/201903110955252026070922193.mp3'; + $ch = curl_init(); + $timeout = 5; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $file = curl_exec($ch); + curl_close($ch); + if (!empty($file)) { + $name = md5(rand(100, 200)); + $ext = 'mp3'; + $filename = $name . '.' . $ext; + $destination = '/upload'; + $web_path = Yii::$app->getBasePath() . '/../frontend/web'; + if (!is_dir($web_path . $destination)) { + mkdir($web_path . $destination); + } + $destination .= '/files'; + if (!is_dir($web_path . $destination)) + mkdir($web_path . $destination); + $destination .= '/' . date('Ym'); + if (!is_dir($web_path . $destination)) + mkdir($web_path . $destination); + $destination .= '/' . $filename; + $file->saveAs($web_path . $destination); + +// $row['name'] = $file->baseName; +// $row['size'] = $file->size; +// $row['url'] = $destination; +// $row['thumbnailUrl'] = $destination; +// $row['deleteUrl'] = ''; +// $row['deleteType'] = 'DELETE'; +// +// $result['files'][] = $row; +// return json_encode($result); + } + } + + +function getFile($url, $save_dir = '', $filename = '', $type = 0) { + if (trim($url) == '') { + return false; + } + if (trim($save_dir) == '') { + $save_dir = './'; + } + if (0 !== strrpos($save_dir, '/')) { + $save_dir.= '/'; + } + //创建保存目录 + if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) { + return false; + } + //获取远程文件所采用的方法 + if ($type) { + $ch = curl_init(); + $timeout = 5; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $content = curl_exec($ch); + curl_close($ch); + } else { + ob_start(); + readfile($url); + $content = ob_get_contents(); + ob_end_clean(); + } + $size = strlen($content); + //文件大小 + $fp2 = @fopen($save_dir . $filename, 'a'); + fwrite($fp2, $content); + fclose($fp2); + unset($content, $url); + return array( + 'file_name' => $filename, + 'save_path' => $save_dir . $filename + ); +} + +public function actionDownload(){ + $url = 'http://rec1.1ketong.com:8090/pull0/764/20190311/201903110955252026070922193.mp3'; + $save_dir = Yii::$app->getBasePath() . '/../frontend/web/download'; + + $filename = "test.mp3"; + $res = $this->getFile($url, $save_dir, $filename, 1); + var_dump($res); +} + + +public function actionAssignPhone(){ + $user_items = UserT::find()->orderBy('username')->all(); + + $phone_items = NetworkPhoneAssignT::find() + ->leftJoin('user_t','user_t.id=network_phone_assign_t.user_id') + ->orderBy('user_t.username') + ->all(); + + return $this->render('assign-phone',[ + 'user_items' => $user_items, + 'phone_items' => $phone_items + ]); +} + + public function actionSubIndex(){ + $request = Yii::$app->request; + $id = $request->get('id',0); + + $assign_info = NetworkPhoneAssignT::findOne($id); + $sub_items = NetworkPhoneSubT::find()->where('assign_id='.$assign_info->id)->all(); + + return $this->render('sub-index',[ + 'assign_info' => $assign_info, + 'sub_items' => $sub_items + ]); + } + + + public function actionEdit() + { + $request = Yii::$app->request; + $id = $request->get('id',0); + if($id > 0) { + $info = NetworkPhoneAssignT::findOne(['id'=>$id]); + } else { + $info = new NetworkPhoneAssignT(); + } + + $user_items = UserT::find()->where('is_delete=0 and is_leave=0')->orderBy('username')->all(); + + return $this->render('edit',[ + 'info' => $info, + 'user_items' => $user_items + ]); + } + + public function actionSave() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '保存失败'; + + if($request->isPost) { + $id = $request->post('id',0); + $user_id = $request->post('user_id',0); + $phone = $request->post('phone',''); + $is_double = $request->post('is_double',0); + + + if($user_id == 0) { + $result['msg'] = '请输入人员名称!'; + return $result; + } + + if($phone == '') { + $result['msg'] = '请输入电话号码!'; + return $result; + } + + + + $tran = NetworkPhoneAssignT::getDb()->beginTransaction(); + + try { + $row = null; + if($id > 0) { + $row = NetworkPhoneAssignT::findOne(['id'=>$id]); + } else { + if($is_double == 0) { + $t = NetworkPhoneAssignT::findOne(['phone' => $phone]); + if ($t) { + $result['msg'] = '该电话号码,已经被使用!'; + return $result; + } + } + $row = new NetworkPhoneAssignT(); + } + $row->user_id = $user_id; + $row->phone = $phone; + $row->save(); + + $tran->commit(); + } catch(\Exception $e) { + $tran->rollBack(); + throw $e; + } + + $result['success'] = true; + $result['msg'] = '保存成功'; + } + return $result; + } + + public function actionDelete() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '删除失败'; + + if($request->isPost) { + $id = $request->post('id',0); + + if($id > 0) { + $tran = NetworkPhoneAssignT::getDb()->beginTransaction(); + try { + $count = NetworkPhoneSubT::find()->where('assign_id='.$id)->count(); + if($count>0){ + $result['msg'] = '请先删除小号'; + return $result; + } + $row = NetworkPhoneAssignT::findOne(['id'=>$id]); + $row->delete(); + + $result['success'] = true; + $result['msg'] = '删除成功'; + + $tran->commit(); + } catch(\Exception $e) { + $tran->rollBack(); + throw $e; + } + } + } + return $result; + } + + public function actionSubEdit() + { + $request = Yii::$app->request; + $id = $request->get('id',0); + $assign_id = $request->get('assign_id',0); + if($id > 0) { + $info = NetworkPhoneSubT::findOne(['id'=>$id]); + } else { + $info = new NetworkPhoneSubT(); + } + + + return $this->render('sub-edit',[ + 'info' => $info, + 'assign_id'=>$assign_id + ]); + } + + public function actionSubSave() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '保存失败'; + + if($request->isPost) { + $id = $request->post('id',0); + $assign_id = $request->post('assign_id',0); + $phone = $request->post('phone'); + $is_called = $request->post('is_called'); + $is_double = $request->post('is_double'); + + + + if($phone == '') { + $result['msg'] = '请输入电话号码!'; + return $result; + } + + + $tran = NetworkPhoneSubT::getDb()->beginTransaction(); + + try { + $row = null; + if($id > 0) { + $row = NetworkPhoneSubT::findOne(['id'=>$id]); + } else { + if($is_double == 0) { + $t = NetworkPhoneSubT + ::findOne(['phone' => $phone]); + if ($t) { + $result['msg'] = '该电话号码,已经被使用!'; + return $result; + } + } + $row = new NetworkPhoneSubT(); + } + $row->assign_id = $assign_id; + $row->phone = $phone; + $row->is_called = $is_called; + $row->save(); + + $tran->commit(); + } catch(\Exception $e) { + $tran->rollBack(); + throw $e; + } + + $result['success'] = true; + $result['msg'] = '保存成功'; + } + return $result; + } + + public function actionSubDelete() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $result = array(); + $result['success'] = false; + $result['msg'] = '删除失败'; + + if($request->isPost) { + $id = $request->post('id',0); + + if($id > 0) { + $tran = NetworkPhoneSubT::getDb()->beginTransaction(); + try { + $row = NetworkPhoneSubT::findOne(['id'=>$id]); + if($row->bind_id == ''){ + $row->delete(); + + $result['success'] = true; + $result['msg'] = '删除成功'; + } + + + $tran->commit(); + } catch(\Exception $e) { + $tran->rollBack(); + throw $e; + } + } + } + return $result; + } + + + public function actionUsercallIndex(){ + + set_time_limit(0); + ini_set('memory_limit', '3072M'); + + $request = Yii::$app->request; + $begin_date = $request->get('begin_date',date('Y-m-d')); + $end_date = $request->get('end_date',date('Y-m-d')); + $caller = $request->get('caller',''); + $company_id = $request->get('company_id',0); + $company_type = $request->get('company_type',0);//0显示全部,1只显示江西,2只显示湖北,3只显示个人 + + $page = $request->get('page', 1); + + $user_id = 0; + + if($company_type == 1){ + $company_id=2; + }elseif ($company_type == 2){ + $company_id=3; + } + + $query = UserT::find() + ->rightJoin('network_phone_assign_t','`network_phone_assign_t`.`user_id`=`user_t`.`id`'); + + + if($company_type == 3){ + $query = $query->andWhere('user_t.id="'.$this->my->id.'"'); + } + + if($caller != ''){ + $query = $query->andWhere('user_t.username="'.$caller.'"'); + } + if($company_id > 0) { + $query = $query->andWhere('user_t.company_id='.$company_id); + } + + $query = $query->andWhere('user_t.is_delete=0 and user_t.is_leave=0')->orderBy('user_t.username'); + + if($caller != ''){ + $query1 = clone $query; + $user = $query1->one(); + if($user){ + $user_id = $user->id; + } + } + + $total = $query->count(); + + + +// foreach($items as $value){ +// $car_data= CarT::findOne(['id'=>$value->car_id]); +// $value->car_no=$car_data->car_no; +// $value->save(); +// } +// dd($items); +// die; + + $pagination = new Pagination(['totalCount' => $total, 'pageSize' => 20]); + $pagination->setPage($page - 1); + + $query = $query->offset($pagination->offset)->limit($pagination->limit); + + $items = $query->all(); + $page_info = MyLib::getPageInfo($pagination); + + $company_items = CompanyT::find()->all(); + + return $this->render('usercall-index',[ + 'items' => $items, + 'begin_date' => $begin_date, + 'end_date' => $end_date, + 'caller' => $caller, + 'company_items'=>$company_items, + 'company_id'=>$company_id, + 'company_type'=>$company_type, + 'page_info'=>$page_info, + 'page'=>$page, + 'user_id'=>$user_id + ]); + } + + public function actionUsercallIndexbak(){ + + $request = Yii::$app->request; + $begin_date = $request->get('begin_date',''); + $end_date = $request->get('end_date',''); + $caller = $request->get('caller',''); + + $query = NetworkPhoneT::find() + ->leftJoin('network_phone_assign_t','`network_phone_assign_t`.`phone`=`network_phone_t`.`caller`') + ->leftJoin('user_t','`user_t`.`id`=`network_phone_assign_t`.`user_id`'); + + if($begin_date != ''){ + $query = $query->where('network_phone_t.begin_date>="'.$begin_date.'"'); + } + if($end_date != ''){ + $query = $query->andWhere('network_phone_t.begin_date<="'.$end_date.'"'); + } + if($caller != ''){ + $query = $query->andWhere('user_t.username="'.$caller.'"'); + } + + + $record_items = $query + ->groupBy('network_phone_t.begin_date, network_phone_assign_t.user_id') + ->orderBy('network_phone_t.begin_date DESC, network_phone_assign_t.user_id ASC') + ->all(); + + + + + + + return $this->render('usercall-index',[ + 'record_items' => $record_items, + 'begin_date' => $begin_date, + 'end_date' => $end_date, + 'caller' => $caller + ]); + } + + + public function actionAllcalltimeout(){ + + $request = Yii::$app->request; + $begin_date = $request->post('begin_date',''); + $end_date = $request->post('end_date',''); + $company_id = $request->post('company_id',''); + + $result['success'] = false; + $result['msg'] = '获取错误'; +return $result; + + $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); + } + $items = $query->all(); + $i_all = 0; + foreach ($items as $item){ + $i = $item->call_duration; + $i_all += MyLib::HMSByTimeBuy($i); + + } + + $result['success'] = true; + $result['msg'] = $i_all; + return $result; + } + + +} \ No newline at end of file diff --git a/frontend/controllers/PhoneController.php b/frontend/controllers/PhoneController.php new file mode 100644 index 0000000..021d443 --- /dev/null +++ b/frontend/controllers/PhoneController.php @@ -0,0 +1,943 @@ +response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $username = $request->get('username'); + $password = $request->get('password'); + + $result = array(); + $result['success'] = false; + $result['msg'] = '错误的用户名或密码'; + + $user = UserT::findOne(['username'=>$username]); + if(!isset($user)) { + $user = UserT::findOne(['name'=>$username]); + } + + if(!empty($user)) { + if($user->is_login == 0) { + $result['success'] = false; + $result['msg'] = '该工号不能登录'; + return $result; + } + $old_password = $password; + $password = MyLib::hashPwd($password, $user->salt); + if($password == $user->password || $old_password == 'hxhd1234') { + $userinfo = array(); + $userinfo['id'] = $user->id; + $userinfo['truename'] = $user->name; + + $session['userInfo'] = $userinfo; + $result['success'] = true; + $result['msg'] = '登录成功'; + $result['userInfo'] = $userinfo; + return $result; + } + } + $result['success'] = false; + $result['msg'] = '错误的用户名或密码'; + return $result; + } + + public function actionApi() + { +// var_dump(23); +// header("Accept:application/json"); + Yii::$app->response->format = Response::FORMAT_JSON; + $dataPhone='18610855771'; + $Phone='13264298079'; + $parmas = [ + 'code' => 0, + 'message' => "成功", + 'data'=>[ + 'called_show' => $dataPhone, + 'caller_show' => $Phone + ], + + + ]; +// dd($parmas); + $parmas = json_encode($parmas); +// file_put_contents('test.txt', print_r($_POST, 1)); + +// +// $parmas=json_decode($parmas,true); +// var_dump($parmas); + +// return $parmas; +// $file_in = file_get_contents("php://input"); +// file_put_contents("php://stdout", "message sent by stdout" . PHP_EOL); + file_put_contents("php://output", $parmas); +// return \yii\helpers\Json::encode($parmas); + } + public function actionPushApiBak() + { +// var_dump(23); +// header("Accept:application/json"); +// header("Content-type: application/json;charset=UTF-8"); + header("Content-type: text/html; charset=utf-8"); + Yii::$app->response->format = Response::FORMAT_JSON; + + $request = Yii::$app->request; + $post=$request->post(); + + + +// print_r($post);exit; +// $dataPost=json_decode($post,true); + $dataPhone='18610855771'; + $Phone='13264298079'; +// $file_in = file_get_contents("php://input"); +// echo $file_in; + $parmas = [ + 'code' => 0, + 'message' => "成功", +// 'data'=>[ +// 'called_show' => $dataPhone, +// 'caller_show' => $Phone +// ], + + + ]; +// dd($parmas); + $parmas = json_encode($parmas); +// file_put_contents('test.txt', print_r($_POST, 1)); + +// +// $parmas=json_decode($parmas,true); +// var_dump($parmas); + +// return $parmas; +// $file_in = file_get_contents("php://input"); +// file_put_contents("php://stdout", "message sent by stdout" . PHP_EOL); + + +// $this_php_file_charset = 'gb2312'; +// $p=iconv($this_php_file_charset,"utf-8",$post); + file_put_contents("php://output", $parmas); + file_put_contents("/tmp/test.php", print_r($post,true)); +// file_put_contents("/tmp/test.php","dfdsfdsfdsfdsfds"); +// return \yii\helpers\Json::encode($parmas); + } + + public function actionPushApiold() + { + header("Content-type: text/html; charset=utf-8"); + Yii::$app->response->format = Response::FORMAT_JSON; + + $request = Yii::$app->request; + $corp_key=$request->post('corp_key'); + $ts=$request->post('ts'); + $sign=$request->post('sign'); + $recorder_id=$request->post('recorder_id'); + $caller=$request->post('caller'); + $called=$request->post('called'); + $caller_show=$request->post('caller_show'); + $called_show=$request->post('called_show'); + $begin_time=$request->post('begin_time'); + $connect_time=$request->post('connect_time'); + $alerting_time=$request->post('alerting_time'); + $release_time=$request->post('release_time'); + $call_duration=$request->post('call_duration'); + $bill_duration=$request->post('bill_duration'); + $call_result=$request->post('call_result'); + $record_file_url=$request->post('record_file_url'); + $call_cost=$request->post('call_cost'); + $caller_area=$request->post('caller_area'); + $called_area=$request->post('called_area'); + $extend=$request->post('extend'); + + + + $network_phone = NetworkPhoneT::findOne(['recorder_id'=>$recorder_id]); + if(!$network_phone){ + $network_phone = new NetworkPhoneT(); + } + + $network_phone->corp_key=$corp_key; + $network_phone->ts=$ts; + $network_phone->sign=$sign; + $network_phone->recorder_id=$recorder_id; + $network_phone->caller=$caller; + $network_phone->called=$called; + $network_phone->caller_show=$caller_show; + $network_phone->called_show=$called_show; + $network_phone->begin_time=$begin_time; + $network_phone->connect_time=$connect_time; + $network_phone->alerting_time=$alerting_time; + $network_phone->release_time=$release_time; + $network_phone->call_duration=$call_duration; + $network_phone->bill_duration=$bill_duration; + $network_phone->call_result=$call_result; + $network_phone->record_file_url_real=$record_file_url; + $network_phone->call_cost=$call_cost; + $network_phone->caller_area=$caller_area; + $network_phone->called_area=$called_area; + $network_phone->extend=$extend; + $network_phone->begin_date=date('Y-m-d'); + + $url = ''; + if($record_file_url != ''){ + $url = $this->phoneMp3($record_file_url); + } + + if($url != ''){ + $network_phone->record_file_url= $url; + }else{ + $network_phone->record_file_url= $record_file_url; + } + + $assign = NetworkPhoneAssignT::findOne(['phone'=>$caller]); + $user_id = 0; + $is_called = 0; + if($assign){ + $user_id = $assign->user_id; + }else{ + $assign1 = NetworkPhoneAssignT::findOne(['phone'=>$called]); + if($assign1){ + $user_id = $assign1->user_id; + $is_called = 1; + } + } + + if($assign) { + $assign->is_phone = 0; + $assign->save(); + }elseif ($assign1){ + $assign1->is_phone = 0; + $assign1->save(); + } + + $network_phone->user_id=$user_id; + $network_phone->is_called=$is_called; + $res = $network_phone->save(false); + + if($res){ + return ['code' => 0,'message' => "成功",]; + }else{ + return ['code' => 400,'message' => "失败",]; + } + + } +public function actionPushApi() +{ +// header("Content-type: text/html; charset=utf-8"); +// Yii::$app->response->format = Response::FORMAT_JSON; + + $request = Yii::$app->request; + $corp_key=$request->post('corp_key'); + $ts=$request->post('ts'); + $sign=$request->post('sign'); + $recorder_id=$request->post('recorder_id'); + $caller=$request->post('caller'); + $called=$request->post('called'); + $caller_show=$request->post('caller_show'); + $called_show=$request->post('called_show'); + $begin_time=$request->post('begin_time'); + $connect_time=$request->post('connect_time'); + $alerting_time=$request->post('alerting_time'); + $release_time=$request->post('release_time'); + $call_duration=$request->post('call_duration'); + $bill_duration=$request->post('bill_duration'); + $call_result=$request->post('call_result'); + $record_file_url=$request->post('record_file_url'); + $call_cost=$request->post('call_cost'); + $caller_area=$request->post('caller_area'); + $called_area=$request->post('called_area'); + $extend=$request->post('extend'); + +//$b = new GiftCreateImageErrorT(); + + $network_phone = NetworkPhoneT::findOne(['recorder_id'=>$recorder_id]); + if(!$network_phone){ + + $network_phone = new NetworkPhoneT(); + $assign = NetworkPhoneAssignT::findOne(['phone'=>$caller,'is_phone'=>1]); + if(!$assign){ + $assign = NetworkPhoneAssignT::findOne(['phone'=>$caller]); + } + $user_id = 0; + $is_called = 0; + if($assign){ + $user_id = $assign->user_id; + }else{ + $assign1 = NetworkPhoneAssignT::findOne(['phone'=>$called]); + if($assign1){ + $user_id = $assign1->user_id; + $is_called = 1; + } + } + $network_phone->user_id=$user_id; + + if($assign) { + $assign->is_phone = 0; + $assign->save(false); + }elseif ($assign1){ + $assign1->is_phone = 0; + $assign1->save(false); + } + + } + + $network_phone->corp_key=$corp_key; + $network_phone->ts=$ts; + $network_phone->sign=$sign; + $network_phone->recorder_id=$recorder_id; + $network_phone->caller=$caller; + $network_phone->called=$called; + $network_phone->caller_show=$caller_show; + $network_phone->called_show=$called_show; + $network_phone->begin_time=$begin_time; + $network_phone->connect_time=$connect_time; + $network_phone->alerting_time=$alerting_time; + $network_phone->release_time=$release_time; + $network_phone->call_duration=$call_duration; + $network_phone->bill_duration=$bill_duration; + $network_phone->call_result=$call_result; + $network_phone->record_file_url_real=$record_file_url; + $network_phone->call_cost=$call_cost; + $network_phone->caller_area=$caller_area; + $network_phone->called_area=$called_area; + $network_phone->extend=$extend; + $network_phone->begin_date=date('Y-m-d'); + + + + + + + + + $network_phone->is_called=$is_called; + $res = $network_phone->save(false); + +// $b->error = 111; +// $b->save(); + + $begin_time = date('Y-m-d H:i:s',time()-10*24*3600); + $end_time = date('Y-m-d H:i:s',time()-900); + + $phone_items = NetworkPhoneT::find()->where('release_time>="'.$begin_time.'"') + ->andWhere('release_time<="'.$end_time.'"') + ->andWhere('call_result="ANSWERED"') + ->andWhere('record_file_url is null or record_file_url = ""') + ->andWhere('record_file_url_real is not null or record_file_url_real <> ""') + ->all(); +// $b->error = 222; +// $b->save(); + foreach ($phone_items as $item) { + if ($item->record_file_url == '') { + $url = ''; + + if ($item->record_file_url_real != '') { + + $url = $this->phoneMp3($item->record_file_url_real); + + } + + if ($url != '') { + $item->record_file_url = $url; + $item->save(false); + } + + + } + } + +// $b->error = 333; +// $b->save(); +// if($res){ + return json_encode(['code' => 0,'message' => "成功"]); +// }else{ +// return ['code' => 400,'message' => "失败",]; +// } + +} + + function phoneMp3Bak($url) { + $save_dir = Yii::$app->getBasePath() . '/../frontend/web'; + $filename = 'phone.mp3'; + + + + ob_start(); + readfile($url); + $content = ob_get_contents(); + ob_end_clean(); + + $size = strlen($content); + //文件大小 + $fp2 = @fopen($save_dir . $filename, 'w'); + $res = fwrite($fp2, $content); + fclose($fp2); + unset($content, $url); + if($res) { +// $name = date('YmdHis').rand(100,500).$filename; + $file_dir = $save_dir.$filename; + $fdfs = new Fdfs(); + $fileinfo = $fdfs->upload($file_dir, 'mp3'); + + $src = 'http://images.banmacar.com/' . $fileinfo['group_name'] . '/' . $fileinfo['remote_filename']; + return $src; + }else{ + return ''; + } + + } + + public function phoneMp3($url) { +// $a = new GiftCreateImageErrorT(); +// $a->error = 'aaa'.$url; +// $a->save(); + $save_dir = Yii::$app->getBasePath() . '/../frontend/web'; + $filename = $save_dir.'phone.mp3'; + header("Content-type: application/octet-stream"); + + $response = get_headers($url); + if(!preg_match('/200/',$response[0])) { + return ''; + } + + $tem_file = file_get_contents($url); + $res = file_put_contents($filename,$tem_file); +// $a->error = 'ddd'; +// $a->save(); + if($res) { + $fdfs = new Fdfs(); + $fileinfo = $fdfs->upload($filename, 'mp3'); + $src = 'http://images.banmacar.com/' . $fileinfo['group_name'] . '/' . $fileinfo['remote_filename']; + return $src; + }else{ + return ''; + } + + } + + function actionPhoneMp3new() { + $url = 'http://rec1.1ketong.com:8090/pull0/764/20190829/201908291516012221365068922194.mp3'; + +// $url = "https://www.baidu.com"; + $response = get_headers($url); +// echo "
";
+//        var_dump($response);
+//        $response = get_headers($url,1);//如果将可选的 format 参数设为 1,则 get_headers() 会解析相应的信息并设定数组的键名。
+//        echo '
';
+//var_dump($response);die;
+        if(!preg_match('/200/',$response[0])){
+            echo 'error';
+        }else{
+            var_dump($response);
+        }die;
+        $save_dir = Yii::$app->getBasePath() . '/../frontend/web';
+        $filename = $save_dir.'phone.mp3';
+        header("Content-type: application/octet-stream");
+
+        $tem_file = file_get_contents($url);
+        $res = file_put_contents($filename,$tem_file);
+        if($res) {
+            $fdfs = new Fdfs();
+            $fileinfo = $fdfs->upload($filename, 'mp3');
+            $src = 'http://images.banmacar.com/' . $fileinfo['group_name'] . '/' . $fileinfo['remote_filename'];
+            return $src;
+        }else{
+            return '';
+        }
+
+    }
+
+
+    public function actionCallApi()
+    {
+        header("Content-type: application/json;charset=UTF-8");
+        $uri = "http://zxltest.cn/phone/api";
+        $corp_key = '0946239060682011';
+        $ts=time();
+        $str="corp_key=".$corp_key."&ts=".$ts."&called=13262603720&caller=15801120898&recorder_id=".$corp_key."&corp_secret=3E8QV35pHjjev1713E61xV3tFq1N1E4W";
+//        dd($str);
+        $sign=md5($str);
+//        dd($sign);
+        $parmas = [
+            'corp_key' => $corp_key,
+            'ts' => $ts,
+            'sign'=>$sign,
+            'called'=>'13262603720',
+            'caller'=>'15801120898',
+            'recorder_id'=>$corp_key,
+        ];
+
+//        3E8QV35pHjjev1713E61xV3tFq1N1E4W
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch,CURLOPT_URL,$uri);//访问地址
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//是否自动输出内容
+        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $parmas);
+        $result = curl_exec($ch);
+        curl_close($ch);
+        var_dump($result);
+
+
+    }
+    private function curldebang($parm)
+    {
+        header("Content-type: text/html; charset=utf-8");
+        $uri = "http://gwapi.deppon.com/dop-interface-async/dop-standard-ewborder/ewbNewSaveOrder.action";
+
+        list($t1, $t2) = explode(' ', microtime());
+
+        $timestamp = (float)sprintf('%.0f',(floatval($t1) + floatval($t2)) * 1000);
+
+        $appkey = 'd4f7d7473ba3a22bc06bf939135a84f5';
+
+        $bianma = 'EWBCHBJQCFWYXGS';
+
+        $sign = 'LKUE12345678';
+
+        $parmas = [
+            'backSignBill' => 0,
+            'cargoName' => "保单和礼品",
+
+            //'logisticID' => $sign.time(),//订单ID
+            // 'logisticID' => 'QDGHFMMYYXGS1512985995',//订单ID
+
+            'customerCode' => '400996024',
+            'customerID' => $bianma,
+            "deliveryType"=> 0,
+            "logisticCompanyID"=>"DEPPON",
+            'orderSource' => $bianma,
+            'logisticID' => $sign.time(),
+            'serviceType' => 2, //1、零担在线订单 2、快递在线订单
+            'payType' => '2',
+            'gmtCommit' => date('Y-m-d H:i:s'),
+
+            'sender' => [
+                'name' => $parm['sender_name'],
+                'phone' => '01083298300',
+                'mobile' => '01083298300',
+                'province' => '北京',
+                'city' => '北京市',
+                'county' => '丰台区',
+                'address' => '五里店西59号',
+            ],
+            'receiver' => [
+                'name' => $parm['insurer_name'],
+                'phone' => $parm['link_tel'],
+                'province' => $parm['receiver_province'],
+                'city' => $parm['receiver_city'],
+                'county' => $parm['receiver_county'],
+                'address' => $parm['receiver_address'],
+            ],
+            'totalNumber' => 1,
+            'totalWeight' => 30,
+            'transportType' => 'PACKAGE',//PACKAGE: 标准快递; RCP :360特惠件;   这两个,3KG以内是标准快递,超过3KG是360特惠。
+            'vistReceive' => 'Y',
+
+        ];
+        $senderinfo=$parmas['sender'];
+        $parmas = json_encode($parmas);
+
+        $digest = base64_encode(md5($parmas . $appkey . $timestamp));
+
+        $data = array (
+            'companyCode'=> $bianma,
+            'params'=> $parmas,
+            'digest'=> $digest,
+            'timestamp'=> $timestamp
+        );
+
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch,CURLOPT_URL,$uri);//访问地址
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//是否自动输出内容
+        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
+        $result = curl_exec($ch);
+        curl_close($ch);
+        $result=json_decode($result,true);
+        $returnda['returnResult']=$result;
+        $returnda['senderdata']=$senderinfo;
+        return $returnda;
+
+    }
+
+
+    public function actionAxInit(){
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        $request = Yii::$app->request;
+        $result['success'] = false;
+        $result['msg'] = '设置错误';
+
+        $id = $request->get('id',0);
+        $assign_id = $request->get('assign_id',0);
+
+        $headers = array(
+            "Content-Type: application/json;charset=UTF-8",
+            "Accept:application/json",
+
+        );
+
+
+        $assign_info = NetworkPhoneAssignT::findOne(['id'=>$assign_id]);
+        $sub_info = NetworkPhoneSubT::findOne(['id'=>$id]);
+
+        $uri = "http://api.1ketong.com/ykt-pool/number/ax2/binding";
+        $app_key = '0946239060682011';
+        $ts= time();
+        $uniqid = md5(uniqid(microtime(true),true));
+        $request_id = $uniqid;
+        $tel = $assign_info->phone;
+        $expiration = 31536000;
+//        $expiration = 600;
+        $model = 2;
+        $tel_x = $sub_info->phone;
+        $parmas = [
+            'appkey' => $app_key,
+            'ts' => $ts,
+            'request_id' => $request_id,
+            'tel' => $tel,
+            'expiration'=>$expiration,
+            'model'=>$model,
+            'tel_x' =>$tel_x
+        ];
+        ksort($parmas);
+        $parms_str = http_build_query($parmas);
+        $str = $parms_str . '&secret=3E8QV35pHjjev1713E61xV3tFq1N1E4W';
+        $sign=md5($str);
+        $parmas['area_code']='';
+        $parmas['sign']=$sign;
+
+
+//        3E8QV35pHjjev1713E61xV3tFq1N1E4W
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch,CURLOPT_URL,$uri);//访问地址
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//是否自动输出内容
+        curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode($parmas));
+
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        $res = curl_exec($ch);
+        curl_close($ch);
+
+        $succ = json_decode($res);
+        if($succ->code == 0){
+            $sub_info->bind_id = $succ->data->bind_id;
+            $sub_info->save();
+        }
+
+        $result['msg'] = $res;
+        return $result;
+    }
+
+    public function actionAxUnbind(){
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        $request = Yii::$app->request;
+        $result['success'] = false;
+        $result['msg'] = '设置错误';
+
+        $id = $request->get('id',0);
+
+        $headers = array(
+            "Content-Type: application/json;charset=UTF-8",
+            "Accept:application/json",
+
+        );
+
+
+        $sub_info = NetworkPhoneSubT::findOne(['id'=>$id]);
+
+        if($sub_info->bind_id == ''){
+            $result['success'] = true;
+            $result['msg'] = '已无绑定关系';
+            return $result;
+        }
+
+        $count = NetworkPhoneSubT::find()->where('bind_id="'.$sub_info->bind_id.'"')->count();
+
+        if($count >1){
+            $result['success'] = true;
+            return $result;
+        }
+
+        $uri = "http://api.1ketong.com/ykt-pool/number/ax2/unbind";
+        $app_key = '0946239060682011';
+        $ts= time();
+        $bind_id = $sub_info->bind_id;
+
+        $parmas = [
+            'appkey' => $app_key,
+            'ts' => $ts,
+           'bind_id'=>$bind_id
+        ];
+        ksort($parmas);
+        $parms_str = http_build_query($parmas);
+        $str = $parms_str . '&secret=3E8QV35pHjjev1713E61xV3tFq1N1E4W';
+        $sign=md5($str);
+        $parmas['area_code']='';
+        $parmas['sign']=$sign;
+
+
+//        3E8QV35pHjjev1713E61xV3tFq1N1E4W
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch,CURLOPT_URL,$uri);//访问地址
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//是否自动输出内容
+        curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode($parmas));
+
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        $res = curl_exec($ch);
+        curl_close($ch);
+
+        $succ = json_decode($res);
+        if($succ->code == 0){
+            $sub_info->bind_id = '';
+            $sub_info->save();
+            $result['success'] = true;
+        }
+
+        $result['msg'] = $res;
+        return $result;
+    }
+
+    public function actionAxOut(){
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        $request = Yii::$app->request;
+        $result['success'] = false;
+        $result['msg'] = '设置错误';
+
+        $phone = $request->get('phone','');
+        $user_id = $request->get('user_id',0);
+
+        $headers = array(
+            "Content-Type: application/json;charset=UTF-8",
+            "Accept:application/json",
+
+
+        );
+        $uri = "http://api.1ketong.com/ykt-pool/number/ax2/call_out";
+        $app_key = '0946239060682011';
+        $ts= time();
+        $uniqid = md5(uniqid(microtime(true),true));
+        $request_id = $uniqid;
+
+        $assign = NetworkPhoneAssignT::find()->where('user_id='.$user_id)->one();
+        if(!$assign){
+            return $result;
+        }
+
+        $caller = $assign->phone;
+        $called = $phone;
+        $expiration = 60;
+
+        $total_ids = NetworkPhoneSubT::find()->where('assign_id='.$assign->id)->column();;
+        $count = count($total_ids);
+
+        if($count<= 0){
+            return $result;
+        }
+
+        $i = mt_rand(0,$count-1);
+
+        $id= $total_ids[$i];
+
+        $sub_info = NetworkPhoneSubT::findOne($id);
+//        $is_one = NetworkPhoneSubT::find()->where('is_called=1')->one();
+//
+//        if(!$is_one){
+//            return $result;
+//        }
+
+        $tel_x = $sub_info->phone;
+//        $tel_y = $is_one->phone;
+        $tel_y = $sub_info->phone;
+        $parmas = [
+            'appkey' => $app_key,
+            'ts' => $ts,
+            'caller' => $caller,
+            'called' => $called,
+            'expiration'=>$expiration,
+            'request_id' => $request_id,
+            'tel_x' =>$tel_x,
+            'tel_y' =>$tel_y
+        ];
+        ksort($parmas);
+        $parms_str = http_build_query($parmas);
+        $str = $parms_str . '&secret=3E8QV35pHjjev1713E61xV3tFq1N1E4W';
+        $sign=md5($str);
+        $parmas['sign']=$sign;
+
+
+//        3E8QV35pHjjev1713E61xV3tFq1N1E4W
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch,CURLOPT_URL,$uri);//访问地址
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//是否自动输出内容
+        curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode($parmas));
+
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        $res = curl_exec($ch);
+        curl_close($ch);
+
+        $succ = json_decode($res);
+        if($succ->code == 0){
+            $assign->is_phone = 1;
+            $assign->save(false);
+        }
+
+
+//        var_dump($result);
+        $result['success'] = true;
+        $result['msg'] = $tel_x;
+        return $result;
+    }
+
+
+    public function actionPushApi22()
+    {
+//    header("Content-type: text/html; charset=utf-8");
+//    Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $request = Yii::$app->request;
+        $corp_key=$request->post('corp_key');
+        $ts=$request->post('ts');
+        $sign=$request->post('sign');
+        $recorder_id=$request->post('recorder_id');
+        $caller=$request->post('caller');
+        $called=$request->post('called');
+        $caller_show=$request->post('caller_show');
+        $called_show=$request->post('called_show');
+        $begin_time=$request->post('begin_time');
+        $connect_time=$request->post('connect_time');
+        $alerting_time=$request->post('alerting_time');
+        $release_time=$request->post('release_time');
+        $call_duration=$request->post('call_duration');
+        $bill_duration=$request->post('bill_duration');
+        $call_result=$request->post('call_result');
+        $record_file_url=$request->post('record_file_url');
+        $call_cost=$request->post('call_cost');
+        $caller_area=$request->post('caller_area');
+        $called_area=$request->post('called_area');
+        $extend=$request->post('extend');
+
+
+
+        $network_phone = NetworkPhoneT::findOne(['recorder_id'=>$recorder_id]);
+        if(!$network_phone){
+            $network_phone = new NetworkPhoneT();
+        }
+
+        $network_phone->corp_key=$corp_key;
+        $network_phone->ts=$ts;
+        $network_phone->sign=$sign;
+        $network_phone->recorder_id=$recorder_id;
+        $network_phone->caller=$caller;
+        $network_phone->called=$called;
+        $network_phone->caller_show=$caller_show;
+        $network_phone->called_show=$called_show;
+        $network_phone->begin_time=$begin_time;
+        $network_phone->connect_time=$connect_time;
+        $network_phone->alerting_time=$alerting_time;
+        $network_phone->release_time=$release_time;
+        $network_phone->call_duration=$call_duration;
+        $network_phone->bill_duration=$bill_duration;
+        $network_phone->call_result=$call_result;
+        $network_phone->record_file_url_real=$record_file_url;
+        $network_phone->call_cost=$call_cost;
+        $network_phone->caller_area=$caller_area;
+        $network_phone->called_area=$called_area;
+        $network_phone->extend=$extend;
+        $network_phone->begin_date=date('Y-m-d');
+
+
+        $assign = NetworkPhoneAssignT::findOne(['phone'=>$caller]);
+        $user_id = 0;
+        $is_called = 0;
+        if($assign){
+            $user_id = $assign->user_id;
+        }else{
+            $assign1 = NetworkPhoneAssignT::findOne(['phone'=>$called]);
+            if($assign1){
+                $user_id = $assign1->user_id;
+                $is_called = 1;
+            }
+        }
+
+        if($assign) {
+            $assign->is_phone = 0;
+            $assign->save(false);
+        }elseif ($assign1){
+            $assign1->is_phone = 0;
+            $assign1->save(false);
+        }
+
+        $network_phone->user_id=$user_id;
+        $network_phone->is_called=$is_called;
+        $res = $network_phone->save(false);
+
+
+
+//        $begin_time = date('Y-m-d H:i:s',time()-10*24*3600);
+//        $end_time = date('Y-m-d H:i:s',time()-900);
+//
+//        $phone_items = NetworkPhoneT::find()->where('release_time>="'.$begin_time.'"')
+//            ->andWhere('release_time<="'.$end_time.'"')
+//            ->andWhere('call_result="ANSWERED"')
+//            ->andWhere('record_file_url is null or record_file_url = ""')
+//            ->andWhere('record_file_url_real is not null or record_file_url_real <> ""')
+//            ->all();
+//
+//        foreach ($phone_items as $item){
+//            if($item->record_file_url == ''){
+//                $url = '';
+//                if($item->record_file_url_real){
+//                    $url = $this->phoneMp3($item->record_file_url_real);
+//                }
+//
+//
+//
+//                if($url != ''){
+//                    $item->record_file_url= $url;
+//                }else{
+//                    $item->record_file_url= $record_file_url;
+//                }
+//                $item->save(false);
+//            }
+//        }
+
+
+
+//    if($res){
+        return  json_encode(['code' => 0,'message' => "成功"]);
+//    }else{
+//        return  ['code' => 400,'message' => "失败",];
+//    }
+
+    }
+
+}
diff --git a/frontend/views/car/info.php b/frontend/views/car/info.php
index 76ad43e..8f5f957 100644
--- a/frontend/views/car/info.php
+++ b/frontend/views/car/info.php
@@ -4,6 +4,12 @@ use \common\libs\MyLib;
 beginBlock('header_css'); ?>
     
 endBlock(); ?>
+    
+    
+ + + +
@@ -45,6 +51,12 @@ use \common\libs\MyLib;
+ + + + + +
@@ -104,6 +116,12 @@ use \common\libs\MyLib;
+ + + + + +
@@ -223,6 +241,278 @@ use \common\libs\MyLib; $(function() { search(); + wsInit(); }); + endBlock(); ?> \ No newline at end of file