Skip to content

Commit 4248539

Browse files
committed
fix:优化
1 parent 0573741 commit 4248539

11 files changed

Lines changed: 34 additions & 42 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"webman/event": "^1.0",
1313
"webman/captcha": "^1.0.0",
1414
"guzzlehttp/guzzle": "^7.5",
15-
"laravel/serializable-closure": "^1.0"
15+
"laravel/serializable-closure": "^1.0",
16+
"ext-json": "*"
1617
},
1718
"autoload": {
1819
"psr-4": {

src/plugin/admin/api/Menu.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<?php
22
namespace plugin\admin\api;
33

4-
use plugin\admin\app\model\Role;
54
use plugin\admin\app\model\Rule;
6-
use support\exception\BusinessException;
7-
use function admin;
85

96
/**
107
* 对外提供的菜单接口

src/plugin/admin/app/common/Auth.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
namespace plugin\admin\app\common;
33

44

5-
use plugin\admin\app\model\Admin;
65
use plugin\admin\app\model\AdminRole;
76
use plugin\admin\app\model\Role;
8-
use plugin\admin\app\model\Rule;
97

108
class Auth
119
{
1210
/**
1311
* 获取权限范围内的所有角色id
1412
* @param bool $with_self
1513
* @return array
14+
* @throws \Exception
1615
*/
1716
public static function getScopeRoleIds(bool $with_self = false): array
1817
{
@@ -35,6 +34,7 @@ public static function getScopeRoleIds(bool $with_self = false): array
3534
* 获取权限范围内的所有管理员id
3635
* @param bool $with_self
3736
* @return array
37+
* @throws \Exception
3838
*/
3939
public static function getScopeAdminIds(bool $with_self = false): array
4040
{
@@ -62,6 +62,7 @@ public static function isSupperAdmin(int $admin_id = 0): bool
6262
* 是否是超级管理员
6363
* @param int $admin_id
6464
* @return bool
65+
* @throws \Exception
6566
*/
6667
public static function isSuperAdmin(int $admin_id = 0): bool
6768
{

src/plugin/admin/app/common/Layui.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace plugin\admin\app\common;
33

4-
use plugin\admin\app\common\Util;
54
use support\exception\BusinessException;
65

76
class Layui

src/plugin/admin/app/common/Util.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static function passwordHash($password, string $algo = PASSWORD_DEFAULT)
2727

2828
/**
2929
* 验证密码哈希
30-
* @param $password
31-
* @param $hash
30+
* @param string $password
31+
* @param string $hash
3232
* @return bool
3333
*/
3434
public static function passwordVerify(string $password, string $hash): bool
@@ -109,7 +109,7 @@ public static function formatBytes($file_size): string
109109
*/
110110
public static function pdoQuote($var)
111111
{
112-
return Util::db()->getPdo()->quote($var, \PDO::PARAM_STR);
112+
return Util::db()->getPdo()->quote($var);
113113
}
114114

115115
/**

src/plugin/admin/app/controller/DevController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace plugin\admin\app\controller;
44

5-
use support\Request;
65
use support\Response;
76
use Throwable;
87

src/plugin/admin/app/controller/InstallController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Database\Capsule\Manager;
66
use plugin\admin\app\common\Util;
7-
use plugin\admin\app\model\Admin;
87
use support\exception\BusinessException;
98
use support\Request;
109
use support\Response;

src/plugin/admin/app/controller/PluginController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\GuzzleException;
77
use plugin\admin\app\common\Util;
8-
use plugin\admin\app\controller\Base;
98
use process\Monitor;
109
use support\exception\BusinessException;
1110
use support\Log;

src/plugin/admin/app/controller/RoleController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function delete(Request $request): Response
188188
* 获取角色权限
189189
* @param Request $request
190190
* @return Response
191+
* @throws \Exception
191192
*/
192193
public function rules(Request $request): Response
193194
{

src/plugin/admin/app/controller/UploadController.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use Exception;
66
use Intervention\Image\ImageManagerStatic as Image;
7-
use plugin\admin\app\controller\Base;
8-
use plugin\admin\app\controller\Crud;
97
use plugin\admin\app\model\Upload;
10-
use Random\RandomException;
118
use support\exception\BusinessException;
129
use support\Request;
1310
use support\Response;
@@ -106,7 +103,7 @@ public function insert(Request $request): Response
106103
if (!$file || !$file->isValid()) {
107104
return $this->json(1, '未找到文件');
108105
}
109-
$data = $this->base($request, '/upload/files/'.date('Ymd'));
106+
$data = $this->base($request, '/upload/files/' . date('Ymd'));
110107
$upload = new Upload;
111108
$upload->admin_id = admin_id();
112109
$upload->name = $data['name'];
@@ -150,7 +147,7 @@ public function file(Request $request): Response
150147
if (in_array($file->getUploadExtension(), $img_exts)) {
151148
return $this->image($request);
152149
}
153-
$data = $this->base($request, '/upload/files/'.date('Ymd'));
150+
$data = $this->base($request, '/upload/files/' . date('Ymd'));
154151
return $this->json(0, '上传成功', [
155152
'url' => $data['url'],
156153
'name' => $data['name'],
@@ -166,7 +163,7 @@ public function file(Request $request): Response
166163
*/
167164
public function image(Request $request): Response
168165
{
169-
$data = $this->base($request, '/upload/img/'.date('Ymd'));
166+
$data = $this->base($request, '/upload/img/' . date('Ymd'));
170167
$realpath = $data['realpath'];
171168
try {
172169
$img = Image::make($realpath);
@@ -178,17 +175,17 @@ public function image(Request $request): Response
178175
if ($height > $max_height || $width > $max_width) {
179176
$ratio = $width > $height ? $max_width / $width : $max_height / $height;
180177
}
181-
$img->resize($width*$ratio, $height*$ratio)->save($realpath);
178+
$img->resize($width * $ratio, $height * $ratio)->save($realpath);
182179
} catch (Exception $e) {
183180
unlink($realpath);
184-
return json( [
185-
'code' => 500,
186-
'msg' => '处理图片发生错误'
181+
return json([
182+
'code' => 500,
183+
'msg' => '处理图片发生错误'
187184
]);
188185
}
189-
return json( [
190-
'code' => 0,
191-
'msg' => '上传成功',
186+
return json([
187+
'code' => 0,
188+
'msg' => '上传成功',
192189
'data' => [
193190
'url' => $data['url'],
194191
'name' => $data['name'],
@@ -220,7 +217,7 @@ public function avatar(Request $request): Response
220217
if (!is_dir($real_path)) {
221218
mkdir($real_path, 0777, true);
222219
}
223-
$name = bin2hex(pack('Nn',time(), random_int(1, 65535)));
220+
$name = bin2hex(pack('Nn', time(), random_int(1, 65535)));
224221
$ext = $file->getUploadExtension();
225222

226223
$image->crop($size, $size)->resize(300, 300);
@@ -254,21 +251,22 @@ public function avatar(Request $request): Response
254251
* 删除附件
255252
* @param Request $request
256253
* @return Response
254+
* @throws BusinessException
257255
*/
258256
public function delete(Request $request): Response
259257
{
260258
$ids = $this->deleteInput($request);
261259
$primary_key = $this->model->getKeyName();
262260
$files = $this->model->whereIn($primary_key, $ids)->get()->toArray();
263261
$file_list = array_map(function ($item) {
264-
$path =$item['url'];
265-
if (preg_match("#^/app/admin#",$path)){
266-
$admin_public_path = config('plugin.admin.app.public_path') ?: base_path() . "/plugin/admin/public";
267-
return $admin_public_path . str_replace("/app/admin", "", $item['url']);
268-
}
269-
return null;
270-
},$files);
271-
$file_list = array_filter($file_list,function ($item){
262+
$path = $item['url'];
263+
if (preg_match("#^/app/admin#", $path)) {
264+
$admin_public_path = config('plugin.admin.app.public_path') ?: base_path() . "/plugin/admin/public";
265+
return $admin_public_path . str_replace("/app/admin", "", $item['url']);
266+
}
267+
return null;
268+
}, $files);
269+
$file_list = array_filter($file_list, function ($item) {
272270
return !empty($item);
273271
});
274272
$result = parent::delete($request);
@@ -285,7 +283,7 @@ public function delete(Request $request): Response
285283
* @param Request $request
286284
* @param $relative_dir
287285
* @return array
288-
* @throws BusinessException|RandomException
286+
* @throws BusinessException|\Random\RandomException
289287
*/
290288
protected function base(Request $request, $relative_dir): array
291289
{
@@ -318,7 +316,7 @@ protected function base(Request $request, $relative_dir): array
318316
throw new BusinessException('不支持该格式的文件上传', 400);
319317
}
320318

321-
$relative_path = $relative_dir . '/' . bin2hex(pack('Nn',time(), random_int(1, 65535))) . ".$ext";
319+
$relative_path = $relative_dir . '/' . bin2hex(pack('Nn', time(), random_int(1, 65535))) . ".$ext";
322320
$full_path = $base_dir . $relative_path;
323321
$file->move($full_path);
324322
$image_with = $image_height = 0;
@@ -327,10 +325,10 @@ protected function base(Request $request, $relative_dir): array
327325
$mime_type = $img_info['mime'];
328326
}
329327
return [
330-
'url' => "/app/admin/$relative_path",
331-
'name' => $file_name,
328+
'url' => "/app/admin/$relative_path",
329+
'name' => $file_name,
332330
'realpath' => $full_path,
333-
'size' => $file_size,
331+
'size' => $file_size,
334332
'mime_type' => $mime_type,
335333
'image_with' => $image_with,
336334
'image_height' => $image_height,

0 commit comments

Comments
 (0)