优化 成功/失败 函数默认参数

This commit is contained in:
何秀钢 2019-10-02 23:25:29 +08:00
parent 5c494bc01f
commit 5247f32e27
13 changed files with 71 additions and 71 deletions

View File

@ -90,7 +90,7 @@ class App extends Base {
if ($id) {
$res = AdminApp::update($data, ['id' => $id]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
}
}
@ -124,9 +124,9 @@ class App extends Base {
}
$res = AdminApp::create($data);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -144,11 +144,11 @@ class App extends Base {
'id' => $id
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$appInfo = AdminApp::get($id);
cache('AccessToken:' . $appInfo['app_secret'], null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -176,11 +176,11 @@ class App extends Base {
}
$res = AdminApp::update($data, ['id' => $postData['id']]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$appInfo = AdminApp::get($postData['id']);
cache('AccessToken:' . $appInfo['app_secret'], null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -199,6 +199,6 @@ class App extends Base {
AdminApp::destroy($id);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -80,9 +80,9 @@ class AppGroup extends Base {
'id' => $id
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -95,9 +95,9 @@ class AppGroup extends Base {
$postData = $this->request->post();
$res = AdminAppGroup::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -110,9 +110,9 @@ class AppGroup extends Base {
$postData = $this->request->post();
$res = AdminAppGroup::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -134,6 +134,6 @@ class AppGroup extends Base {
AdminAppGroup::destroy(['hash' => $hash]);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -109,7 +109,7 @@ class Auth extends Base {
unset($postData['rules']);
$res = AdminAuthGroup::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
if ($rules) {
$insertData = [];
@ -124,7 +124,7 @@ class Auth extends Base {
(new AdminAuthRule())->saveAll($insertData);
}
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -141,9 +141,9 @@ class Auth extends Base {
'status' => $status
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -164,9 +164,9 @@ class Auth extends Base {
unset($postData['rules']);
$res = AdminAuthGroup::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -199,7 +199,7 @@ class Auth extends Base {
AdminAuthGroup::destroy($id);
AdminAuthRule::destroy(['group_id' => $id]);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
/**
@ -226,9 +226,9 @@ class Auth extends Base {
'uid' => $uid
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -22,7 +22,7 @@ class Base extends Controller {
$this->userInfo = $this->request->API_ADMIN_USER_INFO;
}
public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) {
public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) {
$return = [
'code' => $code,
'msg' => $msg,
@ -56,7 +56,7 @@ class Base extends Controller {
cache('Login:' . $apiAuth, json_encode($this->userInfo), config('apiadmin.ONLINE_TIME'));
}
public function buildFailed($code, $msg, $data = []) {
public function buildFailed($code, $msg = '操作失败', $data = []) {
$return = [
'code' => $code,
'msg' => $msg,

View File

@ -104,9 +104,9 @@ class Fields extends Base {
cache('ResponseFieldsRule:' . $postData['hash'], null);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess('操作成功');
return $this->buildSuccess();
}
}
@ -127,9 +127,9 @@ class Fields extends Base {
cache('ResponseFieldsRule:' . $postData['hash'], null);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -152,7 +152,7 @@ class Fields extends Base {
AdminFields::destroy($id);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
/**
@ -200,7 +200,7 @@ class Fields extends Base {
cache('RequestFields:Rule:' . $hash, null);
cache('ResponseFieldsRule:' . $hash, null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') {

View File

@ -79,9 +79,9 @@ class InterfaceGroup extends Base {
'id' => $id
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -94,9 +94,9 @@ class InterfaceGroup extends Base {
$postData = $this->request->post();
$res = AdminGroup::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -109,9 +109,9 @@ class InterfaceGroup extends Base {
$postData = $this->request->post();
$res = AdminGroup::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -153,6 +153,6 @@ class InterfaceGroup extends Base {
AdminGroup::destroy(['hash' => $hash]);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -78,9 +78,9 @@ class InterfaceList extends Base {
$res = AdminList::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -98,11 +98,11 @@ class InterfaceList extends Base {
'hash' => $hash
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
cache('ApiInfo:' . $hash, null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -119,11 +119,11 @@ class InterfaceList extends Base {
$res = AdminList::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
cache('ApiInfo:' . $postData['hash'], null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -166,7 +166,7 @@ class InterfaceList extends Base {
cache('ApiInfo:' . $hash, null);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
/**
@ -191,6 +191,6 @@ class InterfaceList extends Base {
file_put_contents($apiRoutePath, $tplOriginStr);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -64,7 +64,7 @@ class Log extends Base {
}
AdminUserAction::destroy($id);
return $this->buildSuccess([]);
return $this->buildSuccess();
}

View File

@ -27,7 +27,7 @@ class Menu extends Base {
return $this->buildSuccess([
'list' => $list
], '登录成功');
]);
}
/**
@ -42,9 +42,9 @@ class Menu extends Base {
}
$res = AdminMenu::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -61,9 +61,9 @@ class Menu extends Base {
'hide' => $status
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -79,9 +79,9 @@ class Menu extends Base {
}
$res = AdminMenu::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -101,7 +101,7 @@ class Menu extends Base {
} else {
AdminMenu::destroy($id);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}

View File

@ -6,9 +6,9 @@ use app\util\ReturnCode;
class Miss extends Base {
public function index() {
if ($this->request->isOptions()) {
return $this->buildSuccess([]);
return $this->buildSuccess();
} else {
return $this->buildFailed(ReturnCode::INVALID, '接口地址异常', []);
return $this->buildFailed(ReturnCode::INVALID, '接口地址异常');
}
}
}

View File

@ -95,14 +95,14 @@ class User extends Base {
}
$res = AdminUser::create($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
AdminAuthGroupAccess::create([
'uid' => $res->id,
'group_id' => $groups
]);
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -160,9 +160,9 @@ class User extends Base {
'status' => $status
]);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -186,7 +186,7 @@ class User extends Base {
}
$res = AdminUser::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$has = AdminAuthGroupAccess::get(['uid' => $postData['id']]);
if ($has) {
@ -202,7 +202,7 @@ class User extends Base {
]);
}
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -232,13 +232,13 @@ class User extends Base {
unset($postData['head_img']);
$res = AdminUser::update($postData);
if ($res === false) {
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
} else {
$userData = AdminUserData::get(['uid' => $postData['id']]);
$userData->head_img = $headImg;
$userData->save();
return $this->buildSuccess([]);
return $this->buildSuccess();
}
}
@ -260,7 +260,7 @@ class User extends Base {
AdminUser::destroy($id);
AdminAuthGroupAccess::destroy(['uid' => $id]);
return $this->buildSuccess([]);
return $this->buildSuccess();
}

View File

@ -20,7 +20,7 @@ class Base extends Controller {
// $this->userInfo = ''; 这部分初始化用户信息可以参考admin模块下的Base去自行处理
}
public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) {
public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) {
$return = [
'code' => $code,
'msg' => $msg,
@ -33,7 +33,7 @@ class Base extends Controller {
return $return;
}
public function buildFailed($code, $msg, $data = []) {
public function buildFailed($code, $msg = '操作失败', $data = []) {
$return = [
'code' => $code,
'msg' => $msg,

View File

@ -20,7 +20,7 @@ class Base extends Controller {
$this->appInfo = $this->request->API_WIKI_USER_INFO;
}
public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) {
public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) {
$return = [
'code' => $code,
'msg' => $msg,
@ -30,7 +30,7 @@ class Base extends Controller {
return $return;
}
public function buildFailed($code, $msg, $data = []) {
public function buildFailed($code, $msg = '操作失败', $data = []) {
$return = [
'code' => $code,
'msg' => $msg,