From 6409db6250025ec22bd341c5887cbc204ee8d5e3 Mon Sep 17 00:00:00 2001 From: zengchaoxin Date: Thu, 14 Nov 2019 15:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=B5=E8=AF=9D=E5=8F=B7?= =?UTF-8?q?=E7=A0=81=E7=AE=A1=E7=90=86=E6=97=B6=EF=BC=8C=E8=B0=83=E7=94=A8?= =?UTF-8?q?=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(); } } }