Skip to content

Commit 29689f4

Browse files
authored
Merge pull request #10 from liaodeity/8.x
8.2.4添加附件管理列表及其他更新
2 parents c4c2ef8 + b43965d commit 29689f4

File tree

18 files changed

+862
-84
lines changed

18 files changed

+862
-84
lines changed

app/Console/Commands/DevBackUp.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,7 @@ public function __construct ()
5050
*/
5151
public function handle ()
5252
{
53-
$tables = [
54-
'users',
55-
'user_admins',
56-
'config_groups',
57-
'configs',
58-
'menus',
59-
'roles',
60-
'permissions',
61-
'role_has_permissions',
62-
'model_has_roles',
63-
'model_has_permissions',
64-
];
53+
$tables = config ('gui.base_table');
6554
$dir = 'database/dev-backup';
6655
$data = [];
6756
foreach ($tables as $table) {

app/Enums/AttachmentStatusEnum.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 AttachmentStatusEnum extends BaseEnum
18+
{
19+
const NORMAL = 1;//正常
20+
const HIDE = 0;//隐藏
21+
const REPEAT = -1;//重复
22+
23+
protected static $ATTRS = [
24+
self::NORMAL => '正常',
25+
self::HIDE => '隐藏',
26+
self::REPEAT => '重复',
27+
];
28+
protected static $COLORS = [
29+
self::NORMAL => ColorEnum::SUCCESS,
30+
self::HIDE => ColorEnum::INFO,
31+
self::REPEAT => ColorEnum::DANGER,
32+
];
33+
}

app/Helpers/function.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
#系统助手函数库,自定义函数请my_function.php#
2020
#########################################
2121

22+
if (!function_exists ('get_upload_url')) {
23+
function get_upload_url ($url, $source)
24+
{
25+
$source_id = $source->id ?? '';
26+
$source_type = is_object ($source) ? get_class ($source) : '';
27+
$url = $url . '?' . '_token=' . csrf_token () . '&id=' . $source_id . '&type=' . urlencode ($source_type);
28+
29+
return $url;
30+
}
31+
}
32+
2233
if (!function_exists ('get_admin_theme')) {
2334
function get_admin_theme ($clear = false)
2435
{

app/Http/Controllers/Admin/ArticleController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class ArticleController extends Controller
3535

3636
public function __construct (ArticleRepository $repository)
3737
{
38-
SexEnum::attrs ();
3938
View::share ('MODULE_NAME', $this->module_name);//模块名称
4039
$this->repository = $repository;
4140
}
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
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\Http\Controllers\Admin;
15+
16+
use App\Enums\AttachmentStatusEnum;
17+
use App\Enums\StatusEnum;
18+
use App\Exceptions\BusinessException;
19+
use App\Http\Controllers\Controller;
20+
use App\Libs\QueryWhere;
21+
use App\Models\Attachment;
22+
use App\Models\Log;
23+
use App\Models\User;
24+
use App\Repositories\AttachmentRepository;
25+
use Illuminate\Http\Request;
26+
use Illuminate\Support\Facades\Storage;
27+
use Illuminate\Support\Facades\View;
28+
use Intervention\Image\Facades\Image;
29+
30+
class AttachmentController extends Controller
31+
{
32+
protected $module_name = 'attachment';
33+
/**
34+
* @var AttachmentRepository
35+
*/
36+
private $repository;
37+
38+
public function __construct (AttachmentRepository $repository)
39+
{
40+
View::share ('MODULE_NAME', $this->module_name);//模块名称
41+
$this->repository = $repository;
42+
}
43+
44+
/**
45+
* Display a listing of the resource.
46+
*
47+
* @return \Illuminate\Http\Response
48+
*/
49+
public function index (Request $request)
50+
{
51+
52+
$category_id = $request->input ('category_id', 0);
53+
if (request ()->wantsJson ()) {
54+
$limit = $request->input ('limit', 15);
55+
QueryWhere::defaultOrderBy ('attachments.id', 'DESC')->setRequest ($request->all ());
56+
$M = $this->repository->makeModel ()->select ('attachments.*');
57+
QueryWhere::date ($M, 'attachments.created_at');
58+
QueryWhere::like ($M, 'attachments.name');
59+
QueryWhere::orderBy ($M);
60+
61+
$M = $M->paginate ($limit);
62+
$count = $M->total ();
63+
$data = $M->items ();
64+
foreach ($data as $key => $item) {
65+
$wh = '-';
66+
$size = '-';
67+
$src = '';
68+
$path = $item->storage_path;
69+
$exits = Storage::disk ('public')->exists ($path);
70+
if ($exits) {
71+
$src = asset ($item->path);
72+
$size = Storage::disk ('public')->size ($path);
73+
$size = format_size ($size);
74+
$mineType = mime_content_type ($item->path);
75+
if ($mineType && strstr ($mineType, 'image')) {
76+
$img = Image::make ($item->path);
77+
$width = $img->getWidth ();
78+
$height = $img->getHeight ();
79+
$wh = $width . '*' . $height;
80+
}
81+
}
82+
83+
$data[ $key ]['_src'] = $src;
84+
$data[ $key ]['_w_h'] = $wh;
85+
$data[ $key ]['_size'] = $size;
86+
$data[ $key ]['user_id'] = User::showName ($item->user_id);
87+
$data[ $key ]['status'] = AttachmentStatusEnum::toHtml ($item->status);
88+
}
89+
$result = [
90+
'count' => $count,
91+
'data' => $data
92+
];
93+
94+
return ajax_success_result ('成功', $result);
95+
96+
} else {
97+
$attachment = $this->repository->makeModel ();
98+
99+
return view ('admin.' . $this->module_name . '.index', compact ('attachment', 'category_id'));
100+
}
101+
}
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+
227+
/**
228+
* Remove the specified resource from storage.
229+
*
230+
* @return \Illuminate\Http\Response
231+
* @throws BusinessException
232+
*/
233+
public function destroy ($id, Request $request)
234+
{
235+
$ids = $request->input ('ids', []);
236+
if (empty($ids)) {
237+
$ids[] = $id;
238+
}
239+
$ids = (array)$ids;
240+
$M = $this->repository->makeModel ();
241+
$lists = $M->whereIn ('id', $ids)->get ();
242+
$num = 0;
243+
foreach ($lists as $item) {
244+
try {
245+
$this->repository->checkAuth ($item);
246+
} catch (BusinessException $e) {
247+
return ajax_error_result ($e->getMessage ());
248+
}
249+
$log_title = '删除附件[' . ($item->category->title ?? '') . '->' . $item->title . ']记录';
250+
$check = $this->repository->allowDelete ($item->id);
251+
if ($check) {
252+
$ret = $this->repository->delete ($item->id);
253+
if ($ret) {
254+
Log::createLog (Log::DELETE_TYPE, $log_title, $item, $item->id, Attachment::class);
255+
$num++;
256+
}
257+
}
258+
}
259+
260+
return ajax_success_result ('成功删除' . $num . '条记录');
261+
}
262+
}

app/Http/Controllers/Admin/PageController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class PageController extends Controller
3434

3535
public function __construct (PageRepository $repository)
3636
{
37-
SexEnum::attrs ();
3837
View::share ('MODULE_NAME', $this->module_name);//模块名称
3938
$this->repository = $repository;
4039
}

0 commit comments

Comments
 (0)