添加电话号码管理时,调用远程接口

dev
曾超新 5 years ago
parent f6aa1e9ccb
commit 6409db6250
  1. 5
      frontend/config/params.php
  2. 138
      frontend/controllers/PhoneCenterController.php

@ -1,4 +1,9 @@
<?php
return [
'adminEmail' => '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',
],
];

@ -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();
}
}
}

Loading…
Cancel
Save