Skip to content

Commit 5247f32

Browse files
committed
优化 成功/失败 函数默认参数
1 parent 5c494bc commit 5247f32

13 files changed

Lines changed: 71 additions & 71 deletions

File tree

application/admin/controller/App.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function refreshAppSecret() {
9090
if ($id) {
9191
$res = AdminApp::update($data, ['id' => $id]);
9292
if ($res === false) {
93-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
93+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
9494
}
9595
}
9696

@@ -124,9 +124,9 @@ public function add() {
124124
}
125125
$res = AdminApp::create($data);
126126
if ($res === false) {
127-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
127+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
128128
} else {
129-
return $this->buildSuccess([]);
129+
return $this->buildSuccess();
130130
}
131131
}
132132

@@ -144,11 +144,11 @@ public function changeStatus() {
144144
'id' => $id
145145
]);
146146
if ($res === false) {
147-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
147+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
148148
} else {
149149
$appInfo = AdminApp::get($id);
150150
cache('AccessToken:' . $appInfo['app_secret'], null);
151-
return $this->buildSuccess([]);
151+
return $this->buildSuccess();
152152
}
153153
}
154154

@@ -176,11 +176,11 @@ public function edit() {
176176
}
177177
$res = AdminApp::update($data, ['id' => $postData['id']]);
178178
if ($res === false) {
179-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
179+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
180180
} else {
181181
$appInfo = AdminApp::get($postData['id']);
182182
cache('AccessToken:' . $appInfo['app_secret'], null);
183-
return $this->buildSuccess([]);
183+
return $this->buildSuccess();
184184
}
185185
}
186186

@@ -199,6 +199,6 @@ public function del() {
199199

200200
AdminApp::destroy($id);
201201

202-
return $this->buildSuccess([]);
202+
return $this->buildSuccess();
203203
}
204204
}

application/admin/controller/AppGroup.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function changeStatus() {
8080
'id' => $id
8181
]);
8282
if ($res === false) {
83-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
83+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
8484
} else {
85-
return $this->buildSuccess([]);
85+
return $this->buildSuccess();
8686
}
8787
}
8888

@@ -95,9 +95,9 @@ public function add() {
9595
$postData = $this->request->post();
9696
$res = AdminAppGroup::create($postData);
9797
if ($res === false) {
98-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
98+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
9999
} else {
100-
return $this->buildSuccess([]);
100+
return $this->buildSuccess();
101101
}
102102
}
103103

@@ -110,9 +110,9 @@ public function edit() {
110110
$postData = $this->request->post();
111111
$res = AdminAppGroup::update($postData);
112112
if ($res === false) {
113-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
113+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
114114
} else {
115-
return $this->buildSuccess([]);
115+
return $this->buildSuccess();
116116
}
117117
}
118118

@@ -134,6 +134,6 @@ public function del() {
134134

135135
AdminAppGroup::destroy(['hash' => $hash]);
136136

137-
return $this->buildSuccess([]);
137+
return $this->buildSuccess();
138138
}
139139
}

application/admin/controller/Auth.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function add() {
109109
unset($postData['rules']);
110110
$res = AdminAuthGroup::create($postData);
111111
if ($res === false) {
112-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
112+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
113113
} else {
114114
if ($rules) {
115115
$insertData = [];
@@ -124,7 +124,7 @@ public function add() {
124124
(new AdminAuthRule())->saveAll($insertData);
125125
}
126126

127-
return $this->buildSuccess([]);
127+
return $this->buildSuccess();
128128
}
129129
}
130130

@@ -141,9 +141,9 @@ public function changeStatus() {
141141
'status' => $status
142142
]);
143143
if ($res === false) {
144-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
144+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
145145
} else {
146-
return $this->buildSuccess([]);
146+
return $this->buildSuccess();
147147
}
148148
}
149149

@@ -164,9 +164,9 @@ public function edit() {
164164
unset($postData['rules']);
165165
$res = AdminAuthGroup::update($postData);
166166
if ($res === false) {
167-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
167+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
168168
} else {
169-
return $this->buildSuccess([]);
169+
return $this->buildSuccess();
170170
}
171171
}
172172

@@ -199,7 +199,7 @@ public function del() {
199199
AdminAuthGroup::destroy($id);
200200
AdminAuthRule::destroy(['group_id' => $id]);
201201

202-
return $this->buildSuccess([]);
202+
return $this->buildSuccess();
203203
}
204204

205205
/**
@@ -226,9 +226,9 @@ public function delMember() {
226226
'uid' => $uid
227227
]);
228228
if ($res === false) {
229-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
229+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
230230
} else {
231-
return $this->buildSuccess([]);
231+
return $this->buildSuccess();
232232
}
233233
}
234234

application/admin/controller/Base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct() {
2222
$this->userInfo = $this->request->API_ADMIN_USER_INFO;
2323
}
2424

25-
public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) {
25+
public function buildSuccess($data = [], $msg = '操作成功', $code = ReturnCode::SUCCESS) {
2626
$return = [
2727
'code' => $code,
2828
'msg' => $msg,
@@ -56,7 +56,7 @@ public function updateUserInfo($data, $isDetail = false) {
5656
cache('Login:' . $apiAuth, json_encode($this->userInfo), config('apiadmin.ONLINE_TIME'));
5757
}
5858

59-
public function buildFailed($code, $msg, $data = []) {
59+
public function buildFailed($code, $msg = '操作失败', $data = []) {
6060
$return = [
6161
'code' => $code,
6262
'msg' => $msg,

application/admin/controller/Fields.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public function add() {
104104
cache('ResponseFieldsRule:' . $postData['hash'], null);
105105

106106
if ($res === false) {
107-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
107+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
108108
} else {
109-
return $this->buildSuccess('操作成功');
109+
return $this->buildSuccess();
110110
}
111111
}
112112

@@ -127,9 +127,9 @@ public function edit() {
127127
cache('ResponseFieldsRule:' . $postData['hash'], null);
128128

129129
if ($res === false) {
130-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
130+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
131131
} else {
132-
return $this->buildSuccess([]);
132+
return $this->buildSuccess();
133133
}
134134
}
135135

@@ -152,7 +152,7 @@ public function del() {
152152

153153
AdminFields::destroy($id);
154154

155-
return $this->buildSuccess([]);
155+
return $this->buildSuccess();
156156
}
157157

158158
/**
@@ -200,7 +200,7 @@ public function upload() {
200200
cache('RequestFields:Rule:' . $hash, null);
201201
cache('ResponseFieldsRule:' . $hash, null);
202202

203-
return $this->buildSuccess([]);
203+
return $this->buildSuccess();
204204
}
205205

206206
private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') {

application/admin/controller/InterfaceGroup.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function changeStatus() {
7979
'id' => $id
8080
]);
8181
if ($res === false) {
82-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
82+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
8383
} else {
84-
return $this->buildSuccess([]);
84+
return $this->buildSuccess();
8585
}
8686
}
8787

@@ -94,9 +94,9 @@ public function add() {
9494
$postData = $this->request->post();
9595
$res = AdminGroup::create($postData);
9696
if ($res === false) {
97-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
97+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
9898
} else {
99-
return $this->buildSuccess([]);
99+
return $this->buildSuccess();
100100
}
101101
}
102102

@@ -109,9 +109,9 @@ public function edit() {
109109
$postData = $this->request->post();
110110
$res = AdminGroup::update($postData);
111111
if ($res === false) {
112-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
112+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
113113
} else {
114-
return $this->buildSuccess([]);
114+
return $this->buildSuccess();
115115
}
116116
}
117117

@@ -153,6 +153,6 @@ public function del() {
153153

154154
AdminGroup::destroy(['hash' => $hash]);
155155

156-
return $this->buildSuccess([]);
156+
return $this->buildSuccess();
157157
}
158158
}

application/admin/controller/InterfaceList.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public function add() {
7878

7979
$res = AdminList::create($postData);
8080
if ($res === false) {
81-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
81+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
8282
} else {
83-
return $this->buildSuccess([]);
83+
return $this->buildSuccess();
8484
}
8585
}
8686

@@ -98,11 +98,11 @@ public function changeStatus() {
9898
'hash' => $hash
9999
]);
100100
if ($res === false) {
101-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
101+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
102102
} else {
103103
cache('ApiInfo:' . $hash, null);
104104

105-
return $this->buildSuccess([]);
105+
return $this->buildSuccess();
106106
}
107107
}
108108

@@ -119,11 +119,11 @@ public function edit() {
119119

120120
$res = AdminList::update($postData);
121121
if ($res === false) {
122-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
122+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
123123
} else {
124124
cache('ApiInfo:' . $postData['hash'], null);
125125

126-
return $this->buildSuccess([]);
126+
return $this->buildSuccess();
127127
}
128128
}
129129

@@ -166,7 +166,7 @@ public function del() {
166166

167167
cache('ApiInfo:' . $hash, null);
168168

169-
return $this->buildSuccess([]);
169+
return $this->buildSuccess();
170170
}
171171

172172
/**
@@ -191,6 +191,6 @@ public function refresh() {
191191

192192
file_put_contents($apiRoutePath, $tplOriginStr);
193193

194-
return $this->buildSuccess([]);
194+
return $this->buildSuccess();
195195
}
196196
}

application/admin/controller/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function del() {
6464
}
6565
AdminUserAction::destroy($id);
6666

67-
return $this->buildSuccess([]);
67+
return $this->buildSuccess();
6868

6969
}
7070

application/admin/controller/Menu.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function index() {
2727

2828
return $this->buildSuccess([
2929
'list' => $list
30-
], '登录成功');
30+
]);
3131
}
3232

3333
/**
@@ -42,9 +42,9 @@ public function add() {
4242
}
4343
$res = AdminMenu::create($postData);
4444
if ($res === false) {
45-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
45+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
4646
} else {
47-
return $this->buildSuccess([]);
47+
return $this->buildSuccess();
4848
}
4949
}
5050

@@ -61,9 +61,9 @@ public function changeStatus() {
6161
'hide' => $status
6262
]);
6363
if ($res === false) {
64-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
64+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
6565
} else {
66-
return $this->buildSuccess([]);
66+
return $this->buildSuccess();
6767
}
6868
}
6969

@@ -79,9 +79,9 @@ public function edit() {
7979
}
8080
$res = AdminMenu::update($postData);
8181
if ($res === false) {
82-
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
82+
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR);
8383
} else {
84-
return $this->buildSuccess([]);
84+
return $this->buildSuccess();
8585
}
8686
}
8787

@@ -101,7 +101,7 @@ public function del() {
101101
} else {
102102
AdminMenu::destroy($id);
103103

104-
return $this->buildSuccess([]);
104+
return $this->buildSuccess();
105105
}
106106
}
107107

application/admin/controller/Miss.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
class Miss extends Base {
77
public function index() {
88
if ($this->request->isOptions()) {
9-
return $this->buildSuccess([]);
9+
return $this->buildSuccess();
1010
} else {
11-
return $this->buildFailed(ReturnCode::INVALID, '接口地址异常', []);
11+
return $this->buildFailed(ReturnCode::INVALID, '接口地址异常');
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)