From 6409db6250025ec22bd341c5887cbc204ee8d5e3 Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 15:13:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=B5=E8=AF=9D?= =?UTF-8?q?=E5=8F=B7=E7=A0=81=E7=AE=A1=E7=90=86=E6=97=B6=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E8=BF=9C=E7=A8=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/config/params.php | 5 + .../controllers/PhoneCenterController.php | 138 +++++++++++++++++- 2 files changed, 137 insertions(+), 6 deletions(-) diff --git a/frontend/config/params.php b/frontend/config/params.php index 7f754b9..86488a5 100644 --- a/frontend/config/params.php +++ b/frontend/config/params.php @@ -1,4 +1,9 @@ 'admin@example.com', + 'userPanel' => [ + 'token' => 'ff7dc73536475c11981a1c52531f2ff7', + 'phone_url' => 'http://userpanel.banmacar.com/api/phone/op', + 'sms_url' => 'http://user.banmacar.com/api/sms/single-send', + ], ]; diff --git a/frontend/controllers/PhoneCenterController.php b/frontend/controllers/PhoneCenterController.php index 4d7b850..ad879f1 100644 --- a/frontend/controllers/PhoneCenterController.php +++ b/frontend/controllers/PhoneCenterController.php @@ -10,6 +10,7 @@ namespace frontend\controllers; use common\models\FixCarT; use common\models\UserT; +use GuzzleHttp\Client; use yii\base\Controller; use common\libs\MyLib; use common\models\AppointmentT; @@ -338,6 +339,28 @@ public function actionDownload(){ $row = null; if($id > 0) { $row = NetworkPhoneAssignT::findOne(['id'=>$id]); + + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + + $params = [ + 'token' => $token, + 'op' => 'edit', + 'phone' => $phone, + 'old_phone' => $row->phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } } else { if($is_double == 0) { $t = NetworkPhoneAssignT::findOne(['phone' => $phone]); @@ -346,6 +369,26 @@ public function actionDownload(){ return $result; } } + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + + $params = [ + 'token' => $token, + 'op' => 'add', + 'phone' => $phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } $row = new NetworkPhoneAssignT(); } $row->user_id = $user_id; @@ -386,6 +429,27 @@ public function actionDownload(){ return $result; } $row = NetworkPhoneAssignT::findOne(['id'=>$id]); + + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + + $params = [ + 'token' => $token, + 'op' => 'delete', + 'phone' => $row->phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } $row->delete(); $result['success'] = true; @@ -394,7 +458,7 @@ public function actionDownload(){ $tran->commit(); } catch(\Exception $e) { $tran->rollBack(); - throw $e; + $result['msg'] = $e->getMessage(); } } } @@ -412,7 +476,6 @@ public function actionDownload(){ $info = new NetworkPhoneSubT(); } - return $this->render('sub-edit',[ 'info' => $info, 'assign_id'=>$assign_id @@ -434,13 +497,12 @@ public function actionDownload(){ $is_called = $request->post('is_called'); $is_double = $request->post('is_double'); - - if($phone == '') { $result['msg'] = '请输入电话号码!'; return $result; } + $phone_info = NetworkPhoneAssignT::findOne(['id'=>$assign_id]); $tran = NetworkPhoneSubT::getDb()->beginTransaction(); @@ -448,6 +510,28 @@ public function actionDownload(){ $row = null; if($id > 0) { $row = NetworkPhoneSubT::findOne(['id'=>$id]); + + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + $params = [ + 'token' => $token, + 'op' => 'sub_edit', + 'phone' => $phone_info->phone, + 'sub_phone' => $phone, + 'old_sub_phone' => $row->phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } } else { if($is_double == 0) { $t = NetworkPhoneSubT @@ -457,6 +541,28 @@ public function actionDownload(){ return $result; } } + + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + $params = [ + 'token' => $token, + 'op' => 'sub_add', + 'phone' => $phone_info->phone, + 'sub_phone' => $phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } + $row = new NetworkPhoneSubT(); } $row->assign_id = $assign_id; @@ -467,7 +573,7 @@ public function actionDownload(){ $tran->commit(); } catch(\Exception $e) { $tran->rollBack(); - throw $e; + $result['msg'] = $e->getMessage(); } $result['success'] = true; @@ -492,6 +598,26 @@ public function actionDownload(){ try { $row = NetworkPhoneSubT::findOne(['id'=>$id]); if($row->bind_id == ''){ + $url = Yii::$app->params['userPanel']['phone_url']; + $token = Yii::$app->params['userPanel']['token']; + $params = [ + 'token' => $token, + 'op' => 'sub_delete', + 'sub_phone' => $row->phone + ]; + $client = new Client(); + $res = $client->request('POST', $url, [ + 'form_params' => $params, + 'http_errors' => false, + ]); + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody()); + if($obj->code == 400) { + $result['msg'] = $obj->msg; + return $result; + } + } + $row->delete(); $result['success'] = true; @@ -502,7 +628,7 @@ public function actionDownload(){ $tran->commit(); } catch(\Exception $e) { $tran->rollBack(); - throw $e; + $result['msg'] = $e->getMessage(); } } } From 0cf4dc87cef7d1e5abe26523d225a3af9c160a4f Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 15:19:14 +0800 Subject: [PATCH 2/5] test1 --- frontend/controllers/PhoneCenterController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/controllers/PhoneCenterController.php b/frontend/controllers/PhoneCenterController.php index ad879f1..5ca5d58 100644 --- a/frontend/controllers/PhoneCenterController.php +++ b/frontend/controllers/PhoneCenterController.php @@ -320,7 +320,6 @@ public function actionDownload(){ $phone = $request->post('phone',''); $is_double = $request->post('is_double',0); - if($user_id == 0) { $result['msg'] = '请输入人员名称!'; return $result; @@ -331,10 +330,7 @@ public function actionDownload(){ return $result; } - - $tran = NetworkPhoneAssignT::getDb()->beginTransaction(); - try { $row = null; if($id > 0) { @@ -377,6 +373,9 @@ public function actionDownload(){ 'op' => 'add', 'phone' => $phone ]; + echo $url."||"; + var_dump($params); + exit; $client = new Client(); $res = $client->request('POST', $url, [ 'form_params' => $params, From b6a61a449d5fadc5cb74168c59f2c26bf48eb809 Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 15:21:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/controllers/PhoneCenterController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/controllers/PhoneCenterController.php b/frontend/controllers/PhoneCenterController.php index 5ca5d58..457f868 100644 --- a/frontend/controllers/PhoneCenterController.php +++ b/frontend/controllers/PhoneCenterController.php @@ -373,9 +373,6 @@ public function actionDownload(){ 'op' => 'add', 'phone' => $phone ]; - echo $url."||"; - var_dump($params); - exit; $client = new Client(); $res = $client->request('POST', $url, [ 'form_params' => $params, From cd25c606fc608655167f2938ed64759067bf7db7 Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 15:23:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E8=BF=9C=E7=A8=8B=E8=B0=83=E7=94=A8=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/config/params.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/config/params.php b/frontend/config/params.php index 86488a5..c1b5516 100644 --- a/frontend/config/params.php +++ b/frontend/config/params.php @@ -3,7 +3,7 @@ return [ 'adminEmail' => 'admin@example.com', 'userPanel' => [ 'token' => 'ff7dc73536475c11981a1c52531f2ff7', - 'phone_url' => 'http://userpanel.banmacar.com/api/phone/op', + 'phone_url' => 'http://user.banmacar.com/api/phone/op', 'sms_url' => 'http://user.banmacar.com/api/sms/single-send', ], ]; From a877e4f28feaf8bb2b1854928023d02a8b1a741d Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 23:01:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9C=A8=E6=8B=A8?= =?UTF-8?q?=E5=8F=B7=E6=97=B6=EF=BC=8C=E6=A3=80=E6=9F=A5=E8=AF=9D=E8=B4=B9?= =?UTF-8?q?=E5=89=A9=E4=BD=99=E6=97=B6=E9=97=B4=E5=88=A4=E6=96=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/config/params.php | 1 + frontend/controllers/PhoneController.php | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/config/params.php b/frontend/config/params.php index c1b5516..acf5d51 100644 --- a/frontend/config/params.php +++ b/frontend/config/params.php @@ -5,5 +5,6 @@ return [ 'token' => 'ff7dc73536475c11981a1c52531f2ff7', 'phone_url' => 'http://user.banmacar.com/api/phone/op', 'sms_url' => 'http://user.banmacar.com/api/sms/single-send', + 'myinfo_url' => 'http://user.banmacar.com/api/user/myinfo', ], ]; diff --git a/frontend/controllers/PhoneController.php b/frontend/controllers/PhoneController.php index 83eba69..b9029d0 100644 --- a/frontend/controllers/PhoneController.php +++ b/frontend/controllers/PhoneController.php @@ -16,6 +16,7 @@ use common\models\NetworkPhoneAssignT; use common\models\NetworkPhoneSubT; use common\models\NetworkPhoneT; +use GuzzleHttp\Client; use Yii; use yii\console\Request; use yii\web\Response; @@ -723,11 +724,30 @@ class PhoneController extends \yii\web\Controller $phone = $request->get('phone',''); $user_id = $request->get('user_id',0); + //检查通话剩余分钟 + $url = Yii::$app->params['userPanel']['myinfo_url']; + $token = Yii::$app->params['userPanel']['token']; + + $client = new Client(); + $res = $client->request('GET', $url.'?token='.$token); + $phone_time = 0; + if($res->getStatusCode() == 200) { + $obj = json_decode($res->getBody(), true); + if($obj['code'] == 400) { + $result['msg'] = $obj['msg']; + return $result; + } + $phone_time = intval($obj['data']['phone_time']); + } + + if($phone_time <= 0) { + $result['msg'] = '电话剩余话费不足,请联系管理员充值'; + return $result; + } + $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';