Skip to content

Commit 63bab7b

Browse files
liaodeitygitee-org
authored andcommitted
!9 v8.3.3支持七牛云及阿里云OSS上传附件图片
Merge pull request !9 from liaodeity/8.x
2 parents 31c4f9f + 5a8f0f7 commit 63bab7b

20 files changed

+1472
-216
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,17 @@ PUSHER_APP_CLUSTER=mt1
4848

4949
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
5050
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
51+
52+
UPLOAD_YUN_DRIVER=
53+
QINIU_ACCESS_KEY=
54+
QINIU_SECRET_KEY=
55+
QINIU_DEFAULT_REGION=
56+
QINIU_BUCKET=
57+
QINIU_URL=
58+
QINIU_PREFIX=demo
59+
ALIYUN_OSS_KEY_ID=
60+
ALIYUN_OSS_KEY_SECRET=
61+
ALIYUN_OSS_BUCKET=
62+
ALIYUN_OSS_ENDPOINT=
63+
ALIYUN_OSS_URL=
64+
ALIYUN_OSS_PREFIX=demo

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.3.0...8.x)
3+
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.3.2...8.x)
4+
5+
## [v8.3.2](https://github.com/liaodeity/laravel-admin-cms/compare/v8.3.1...v8.3.2)
6+
7+
### Added
8+
- 添加系统配置设置功能([#8](https://gitee.com/liaodeiy/laravel-admin-cms/pulls/8)
9+
10+
### Changed
11+
- 代码整理优化
412

513
## [v8.3.1](https://github.com/liaodeity/laravel-admin-cms/compare/v8.3.0...v8.3.1)
614
### Changed

app/Enums/UploadDriverEnum.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/*
3+
|-----------------------------------------------------------------------------------------------------------
4+
| laravel-admin-cms [ 简单高效的开发插件系统 ]
5+
|-----------------------------------------------------------------------------------------------------------
6+
| Licensed ( MIT )
7+
| ----------------------------------------------------------------------------------------------------------
8+
| Copyright (c) 2020-2021 https://gitee.com/liaodeiy/laravel-admin-cms All rights reserved.
9+
| ----------------------------------------------------------------------------------------------------------
10+
| Author: 廖春贵 < liaodeity@gmail.com >
11+
|-----------------------------------------------------------------------------------------------------------
12+
*/
13+
14+
namespace App\Enums;
15+
16+
17+
class UploadDriverEnum extends BaseEnum
18+
{
19+
const ALIYUN = 'oss';
20+
const QINIU = 'kodo';
21+
protected static $ATTRS = [
22+
self::ALIYUN => '阿里云OSS',
23+
self::QINIU => '七牛云KODO'
24+
];
25+
}

app/Http/Controllers/Admin/AttachmentController.php

Lines changed: 11 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Models\User;
2424
use App\Repositories\AttachmentRepository;
2525
use Illuminate\Http\Request;
26+
use Illuminate\Support\Facades\DB;
2627
use Illuminate\Support\Facades\Storage;
2728
use Illuminate\Support\Facades\View;
2829
use Intervention\Image\Facades\Image;
@@ -48,7 +49,9 @@ public function __construct (AttachmentRepository $repository)
4849
*/
4950
public function index (Request $request)
5051
{
51-
52+
if (!check_admin_auth ($this->module_name . '_' . __FUNCTION__)) {
53+
return auth_error_return ();
54+
}
5255
$category_id = $request->input ('category_id', 0);
5356
if (request ()->wantsJson ()) {
5457
$limit = $request->input ('limit', 15);
@@ -68,7 +71,7 @@ public function index (Request $request)
6871
$path = $item->storage_path;
6972
$exits = Storage::disk ('public')->exists ($path);
7073
if ($exits) {
71-
$src = asset ($item->path);
74+
$src = $item->url ? $item->url : asset ($item->path);
7275
$size = Storage::disk ('public')->size ($path);
7376
$size = format_size ($size);
7477
$mineType = mime_content_type ($item->path);
@@ -99,131 +102,6 @@ public function index (Request $request)
99102
return view ('admin.' . $this->module_name . '.index', compact ('attachment', 'category_id'));
100103
}
101104
}
102-
103-
/**
104-
* Show the form for creating a new resource.
105-
*
106-
* @return \Illuminate\Http\Response
107-
*/
108-
public function create (Request $request)
109-
{
110-
$attachment = $this->repository->makeModel ();
111-
$_method = 'POST';
112-
$attachment->status = StatusEnum::NORMAL;
113-
114-
return view ('admin.' . $this->module_name . '.add', compact ('attachment', '_method'));
115-
}
116-
117-
/**
118-
* Store a newly created resource in storage.
119-
*
120-
* @param \Illuminate\Http\Request $request
121-
* @return \Illuminate\Http\Response
122-
*/
123-
public function store (Request $request)
124-
{
125-
$request->validate ([
126-
'Attachment.title' => 'required',
127-
'Attachment.name' => 'unique:attachments,name',
128-
'Attachment.content' => 'required',
129-
'Attachment.status' => 'required',
130-
], [], [
131-
'Attachment.title' => '标题',
132-
'Attachment.name' => '英文标识',
133-
'Attachment.content' => '内容',
134-
'Attachment.status' => '状态',
135-
]);
136-
if (!check_admin_auth ($this->module_name . '_edit')) {
137-
return auth_error_return ();
138-
}
139-
$input = $request->input ('Attachment');
140-
$input = $this->formatRequestInput (__FUNCTION__, $input);
141-
try {
142-
$input['user_id'] = get_login_user_id ();
143-
$attachment = $this->repository->create ($input);
144-
if ($attachment) {
145-
$log_title = '添加附件记录';
146-
Log::createLog (Log::ADD_TYPE, $log_title, '', $attachment->id, Attachment::class);
147-
148-
return ajax_success_result ('添加成功');
149-
} else {
150-
return ajax_success_result ('添加失败');
151-
}
152-
153-
} catch (BusinessException $e) {
154-
return ajax_error_result ($e->getMessage ());
155-
}
156-
}
157-
158-
private function formatRequestInput (string $__FUNCTION__, $input)
159-
{
160-
return $input;
161-
}
162-
163-
/**
164-
* Display the specified resource.
165-
*
166-
* @param \App\Models\Attachment $attachment
167-
* @return \Illuminate\Http\Response
168-
*/
169-
public function show (Attachment $attachment)
170-
{
171-
//
172-
}
173-
174-
/**
175-
* Show the form for editing the specified resource.
176-
*
177-
* @param \App\Models\Attachment $attachment
178-
* @return \Illuminate\Http\Response
179-
*/
180-
public function edit (Attachment $attachment)
181-
{
182-
$_method = 'PUT';
183-
184-
return view ('admin.' . $this->module_name . '.add', compact ('attachment', '_method'));
185-
}
186-
187-
/**
188-
* Update the specified resource in storage.
189-
*
190-
* @param \Illuminate\Http\Request $request
191-
* @param \App\Models\Attachment $attachment
192-
* @return \Illuminate\Http\Response
193-
*/
194-
public function update (Request $request, Attachment $attachment)
195-
{
196-
$request->validate ([
197-
'Attachment.title' => 'required',
198-
'Attachment.name' => 'unique:attachments,name,' . $attachment->id,
199-
'Attachment.content' => 'required',
200-
'Attachment.status' => 'required',
201-
], [], [
202-
'Attachment.title' => '标题',
203-
'Attachment.name' => '英文标识',
204-
'Attachment.content' => '内容',
205-
'Attachment.status' => '状态',
206-
]);
207-
$input = $request->input ('Attachment');
208-
$input = $this->formatRequestInput (__FUNCTION__, $input);
209-
try {
210-
$input['user_id'] = get_login_user_id ();
211-
$attachment = $this->repository->update ($input, $attachment->id);
212-
if ($attachment) {
213-
$content = $attachment->toArray () ?? '';
214-
$log_title = '修改附件记录';
215-
Log::createLog (Log::EDIT_TYPE, $log_title, $content, $attachment->id, Attachment::class);
216-
217-
return ajax_success_result ('修改成功');
218-
} else {
219-
return ajax_success_result ('修改失败');
220-
}
221-
222-
} catch (BusinessException $e) {
223-
return ajax_error_result ($e->getMessage ());
224-
}
225-
}
226-
227105
/**
228106
* Remove the specified resource from storage.
229107
*
@@ -232,31 +110,30 @@ public function update (Request $request, Attachment $attachment)
232110
*/
233111
public function destroy ($id, Request $request)
234112
{
113+
if (!check_admin_auth ($this->module_name . '_delete')) {
114+
return auth_error_return ();
115+
}
235116
$ids = $request->input ('ids', []);
236117
if (empty($ids)) {
237118
$ids[] = $id;
238119
}
120+
DB::beginTransaction ();
239121
$ids = (array)$ids;
240122
$M = $this->repository->makeModel ();
241123
$lists = $M->whereIn ('id', $ids)->get ();
242124
$num = 0;
243125
foreach ($lists as $item) {
244-
try {
245-
$this->repository->checkAuth ($item);
246-
} catch (BusinessException $e) {
247-
return ajax_error_result ($e->getMessage ());
248-
}
249126
$log_title = '删除附件[' . ($item->category->title ?? '') . '->' . $item->title . ']记录';
250127
$check = $this->repository->allowDelete ($item->id);
251128
if ($check) {
252-
$ret = $this->repository->delete ($item->id);
129+
$ret = Attachment::deleteFile ($item);
253130
if ($ret) {
254131
Log::createLog (Log::DELETE_TYPE, $log_title, $item, $item->id, Attachment::class);
255132
$num++;
256133
}
257134
}
258135
}
259-
136+
DB::commit ();
260137
return ajax_success_result ('成功删除' . $num . '条记录');
261138
}
262139
}

app/Http/Controllers/Admin/UploadController.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function image (Request $request)
4646
return ['status' => 0, 'info' => '.' . $extension . '的后缀不允许上传'];
4747
}
4848

49-
$newImagesName = get_uuid () . "." . $extension;
49+
$newImagesName = md5_file ($images->getRealPath ()). "." . $extension;
5050

5151

5252
$path = $filedir . $newImagesName;
@@ -78,7 +78,7 @@ public function image (Request $request)
7878
$data['size'] = $size;
7979
$data['state'] = 'SUCCESS';
8080
$data['name'] = $newImagesName;
81-
$data['url'] = '/' . $Attachment->path;
81+
$data['url'] = $Attachment->url;
8282
$data['type'] = '.' . $extension;
8383
$data['originalName'] = $Attachment->name;
8484
$data['src'] = $data['url'];
@@ -89,9 +89,9 @@ public function image (Request $request)
8989
case 'wangEditor':
9090
$data['errno'] = 0;
9191
$row = [
92-
'url' => '/' . $Attachment->path,
92+
'url' => $Attachment->url,
9393
'alt' => $Attachment->name,
94-
'href' => '/' . $Attachment->path
94+
'href' => $Attachment->url
9595
];
9696
$data['data'][] = $row;
9797
break;
@@ -119,7 +119,7 @@ public function excel (Request $request, $name = 'file')
119119
return ['status' => 0, 'info' => '.' . $extension . '的后缀不允许上传'];
120120
}
121121

122-
$newImagesName = get_uuid () . "." . $extension;
122+
$newImagesName = md5_file ($files->getRealPath ()) . "." . $extension;
123123

124124
$files->move ($filedir, $newImagesName);
125125
$path = $filedir . $newImagesName;
@@ -137,7 +137,7 @@ public function excel (Request $request, $name = 'file')
137137
'id' => $attachment->id,
138138
'name' => $attachment->name,
139139
'title' => str_replace ('.' . $extension, '', $attachment->name),
140-
'src' => asset ($attachment->path)
140+
'src' => $attachment->url
141141
]
142142
];
143143
Log::createLog (Log::INFO_TYPE, '上传附件记录', '', $attachment->id, Attachment::class);
@@ -164,7 +164,7 @@ public function file (Request $request, $name = 'file')
164164
return ['status' => 0, 'info' => '.' . $extension . '的后缀不允许上传'];
165165
}
166166

167-
$newFileName = get_uuid () . "." . $extension;
167+
$newFileName = md5_file ($files->getRealPath ()) . "." . $extension;
168168

169169
$path = $filedir . $newFileName;
170170
$content = file_get_contents ($files->getRealPath ());
@@ -182,23 +182,12 @@ public function file (Request $request, $name = 'file')
182182
];
183183
$attachment = Attachment::addFile ($insArr);
184184

185-
//$files->move ($filedir, $newImagesName);
186-
//$path = $filedir . $newImagesName;
187-
//$insArr = [
188-
// 'name' => $imagesName,
189-
// 'path' => $path,
190-
// 'file_md5' => md5_file ($path),
191-
// 'file_sha1' => sha1_file ($path),
192-
// 'status' => 1
193-
//];
194-
//$attachment = Attachment::addFile ($insArr);
195-
196185
$result = [
197186
'data' => [
198187
'id' => $attachment->id,
199188
'name' => $attachment->name,
200189
'title' => str_replace ('.' . $extension, '', $attachment->name),
201-
'src' => asset ($attachment->path)
190+
'src' => $attachment->url
202191
]
203192
];
204193
Log::createLog (Log::INFO_TYPE, '上传附件记录', '', $attachment->id, Attachment::class);

0 commit comments

Comments
 (0)