From 7141eac9bb67ee934dfd4b1241c5f176b08788d6 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Thu, 27 Apr 2017 14:43:46 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E8=A7=84=E5=88=99=E5=85=A8=E9=9D=A2?= =?UTF-8?q?=E7=BC=93=E5=AD=98=EF=BC=8C=E6=8F=90=E5=8D=87Api=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ApiManageController.class.php | 7 ++++ .../FieldsManageController.class.php | 20 ++++++++++- .../Home/Controller/ApiController.class.php | 34 ++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/Application/Admin/Controller/ApiManageController.class.php b/Application/Admin/Controller/ApiManageController.class.php index eb75ac3..5ab64b4 100644 --- a/Application/Admin/Controller/ApiManageController.class.php +++ b/Application/Admin/Controller/ApiManageController.class.php @@ -30,6 +30,7 @@ class ApiManageController extends BaseController { $data = I('post.'); $res = D('ApiList')->where(array('id' => $data['id']))->save($data); if( $res === false ) { + S('ApiInfo_' . $data['hash'], 0); $this->ajaxError('操作失败'); } else { $this->ajaxSuccess('添加成功'); @@ -57,6 +58,8 @@ class ApiManageController extends BaseController { if( IS_POST ) { $id = I('post.id'); if( $id ) { + $hash = D('ApiList')->where(array('id' => $id))->getField('hash'); + S('ApiInfo_' . $hash, 0); D('ApiList')->open(array('id' => $id)); $this->ajaxSuccess('操作成功'); } else { @@ -69,6 +72,8 @@ class ApiManageController extends BaseController { if( IS_POST ) { $id = I('post.id'); if( $id ) { + $hash = D('ApiList')->where(array('id' => $id))->getField('hash'); + S('ApiInfo_' . $hash, 0); D('ApiList')->close(array('id' => $id)); $this->ajaxSuccess('操作成功'); } else { @@ -81,6 +86,8 @@ class ApiManageController extends BaseController { if( IS_POST ) { $id = I('post.id'); if( $id ) { + $hash = D('ApiList')->where(array('id' => $id))->getField('hash'); + S('ApiInfo_' . $hash, 0); D('ApiList')->del(array('id' => $id)); $this->ajaxSuccess('操作成功'); } else { diff --git a/Application/Admin/Controller/FieldsManageController.class.php b/Application/Admin/Controller/FieldsManageController.class.php index a966a38..5264ab7 100644 --- a/Application/Admin/Controller/FieldsManageController.class.php +++ b/Application/Admin/Controller/FieldsManageController.class.php @@ -77,6 +77,11 @@ class FieldsManageController extends BaseController { if ($res === false) { $this->ajaxError('操作失败'); } else { + if ($data['type'] == 0) { + S('ApiRequest_' . $data['hash'], 0); + } else { + S('ApiResponse_' . $data['hash'], 0); + } $this->ajaxSuccess('添加成功'); } } else { @@ -94,6 +99,12 @@ class FieldsManageController extends BaseController { if (IS_POST) { $id = I('post.id'); if ($id) { + $detail = D('ApiFields')->where(array('id' => $id))->find(); + if ($detail['type'] == 0) { + S('ApiRequest_' . $detail['hash'], 0); + } else { + S('ApiResponse_' . $detail['hash'], 0); + } D('ApiFields')->where(array('id' => $id))->delete(); $this->ajaxSuccess('操作成功'); } else { @@ -105,6 +116,7 @@ class FieldsManageController extends BaseController { public function upload() { if (IS_POST) { $hash = I('post.hash'); + $type = I('post.type'); $jsonStr = I('post.jsonStr'); $jsonStr = html_entity_decode($jsonStr); $data = json_decode($jsonStr, true); @@ -112,7 +124,7 @@ class FieldsManageController extends BaseController { $this->handle($data['data'], $dataArr); $old = D('ApiFields')->where(array( 'hash' => $hash, - 'type' => I('post.type') + 'type' => $type ))->select(); $oldArr = array_column($old, 'showName'); $newArr = array_column($dataArr, 'showName'); @@ -130,6 +142,12 @@ class FieldsManageController extends BaseController { } D('ApiFields')->addAll($addData); } + if ($type) { + S('ApiRequest_' . $hash, 0); + } else { + S('ApiResponse_' . $hash, 0); + } + S('ApiReturnType_' . $hash, 0); $this->ajaxSuccess('操作成功'); } else { $this->display(); diff --git a/Application/Home/Controller/ApiController.class.php b/Application/Home/Controller/ApiController.class.php index 99a293c..9ad439a 100644 --- a/Application/Home/Controller/ApiController.class.php +++ b/Application/Home/Controller/ApiController.class.php @@ -25,16 +25,42 @@ class ApiController extends BaseController { public function index() { $getArr = I('get.'); $postArr = I('post.'); - $this->apiDetail = M('ApiList')->where(array('hash' => $getArr['hash'], 'status' => 1))->find(); + + //获取ApiInfo根据 + $this->apiDetail = S('ApiInfo_' . $getArr['hash']); + if (!$this->apiDetail) { + $this->apiDetail = M('ApiList')->where(array('hash' => $getArr['hash'], 'status' => 1))->find(); + S('ApiInfo_' . $getArr['hash'], json_encode($this->apiDetail)); + } else { + $this->apiDetail = json_decode($this->apiDetail, true); + } if (empty($this->apiDetail)) { Response::error(ReturnCode::NOT_EXISTS, '非法的API标识'); } ApiLog::setApiInfo($this->apiDetail); - $this->apiRequest = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 0))->select(); - $this->apiResponse = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 1))->select(); - $returnType = M('ApiFields')->where(array('hash' => $getArr['hash'], 'showName' => 'data', 'type' => 1))->find(); + $this->apiRequest = S('ApiRequest_' . $getArr['hash']); + if (!$this->apiRequest) { + $this->apiRequest = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 0))->select(); + S('ApiRequest_' . $getArr['hash'], json_encode($this->apiRequest)); + } else { + $this->apiRequest = json_decode($this->apiRequest, true); + } + + $this->apiResponse = S('ApiResponse_' . $getArr['hash']); + if (!$this->apiResponse) { + $this->apiResponse = M('ApiFields')->where(array('hash' => $getArr['hash'], 'type' => 1))->select(); + S('ApiResponse_' . $getArr['hash'], json_encode($this->apiResponse)); + } else { + $this->apiResponse = json_decode($this->apiResponse, true); + } + + $returnType = S('ApiReturnType_' . $getArr['hash']); + if (!$returnType) { + $returnType = M('ApiFields')->where(array('hash' => $getArr['hash'], 'showName' => 'data', 'type' => 1))->getField('dataType'); + S('ApiReturnType_' . $getArr['hash'], $returnType); + } Response::setDataType($returnType['dataType']); $this->header = apache_request_headers();