Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨昕
media-resource
Commits
e7f95991
Commit
e7f95991
authored
Aug 04, 2020
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加回收站功能
parent
eaf283f4
Pipeline
#10376
passed with stages
in 45 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
2 deletions
+69
-2
MediaModel.php
app/Model/MediaModel.php
+14
-2
RecycleModel.php
app/Model/RecycleModel.php
+55
-0
No files found.
app/Model/MediaModel.php
View file @
e7f95991
...
@@ -378,15 +378,27 @@ class MediaModel extends Eloquent
...
@@ -378,15 +378,27 @@ class MediaModel extends Eloquent
throw
new
\Exception
(
'媒资不存在!'
);
throw
new
\Exception
(
'媒资不存在!'
);
}
}
if
(
$request
->
token_user
name
!=
'offcn'
){
if
(
getAdmin
()
->
name
!=
'offcn'
){
throw
new
\Exception
(
"您无权限操作"
);
}
}
$session
=
\DB
::
connection
(
'mongodb'
)
->
getMongoClient
()
->
startSession
();
$session
->
startTransaction
();
$recycleId
=
RecycleModel
::
addRecycle
(
$id
);
if
(
!
$recycleId
){
$session
->
abortTransaction
();
throw
new
\Exception
(
'回收站保存失败'
);
}
$flag
=
MediaModel
::
destroy
(
$id
);
$flag
=
MediaModel
::
destroy
(
$id
);
if
(
!
$flag
){
if
(
!
$flag
){
LogModel
::
addlog
([
"删除媒资失败"
=>
$id
]);
$session
->
abortTransaction
();
throw
new
\Exception
(
'删除失败'
);
throw
new
\Exception
(
'删除失败'
);
}
}
$session
->
commitTransaction
();
}
catch
(
\Exception
$exception
){
}
catch
(
\Exception
$exception
){
...
...
app/Model/RecycleModel.php
0 → 100644
View file @
e7f95991
<?php
namespace
App\Model
;
use
App\Exceptions\DatabaseException
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
RecycleModel
extends
Eloquent
{
/**
* mongodb collection 名字
*/
protected
$collection
=
'recycle'
;
protected
$connection
=
'mongodb'
;
//使用mongodb
protected
$primaryKey
=
'_id'
;
public
static
function
addRecycle
(
$obj_id
,
$obj_type
=
"media"
){
$recycle
=
RecycleModel
::
where
([
"obj_type"
=>
$obj_type
,
"obj_id"
=>
$obj_id
,
])
->
first
();
if
(
!
empty
(
$recycle
)){
throw
new
\Exception
(
"回收站已存在"
);
}
$obj_model
=
'App\\Model\\'
.
ucfirst
(
$obj_type
)
.
'Model'
;
$model
=
new
$obj_model
();
$obj
=
$model
->
find
(
$obj_id
)
->
toArray
();
if
(
empty
(
$obj
)){
throw
new
\Exception
(
'数据不存在'
);
}
$data
=
[
'obj_id'
=>
$obj_id
,
'obj_type'
=>
$obj_type
,
'content'
=>
json_encode
(
$obj
),
'create_time'
=>
date
(
'Y-m-d H:i:s'
,
time
())
];
$id
=
RecycleModel
::
insertGetId
(
$data
);
if
(
!
$id
){
throw
new
\Exception
(
'添加回收站失败'
);
}
return
$id
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment