File tree 2 files changed +14
-36
lines changed
application/index/controller
2 files changed +14
-36
lines changed Original file line number Diff line number Diff line change @@ -49,25 +49,14 @@ public function deleteImages($deleteId = null)
49
49
try {
50
50
$ id = $ deleteId ? $ deleteId : $ this ->request ->post ('id ' );
51
51
$ deletes = []; // 需要删除的文件
52
- if (is_array ($ id )) {
53
- $ images = $ this ->user ->images ()->where ('id ' , $ id )->select ();
54
- foreach ($ images as &$ value ) {
55
- // 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
56
- if (!$ this ->exists ($ value )) {
57
- $ deletes [$ value ->strategy ][] = $ value ->pathname ;
58
- }
59
- $ value ->delete ();
60
- unset($ value );
61
- }
62
- } else {
63
- $ image = $ this ->user ->images ()->where ('id ' , $ id )->find ();
64
- if (!$ image ) {
65
- throw new Exception ('没有找到该图片数据 ' );
66
- }
67
- if (!$ this ->exists ($ image )) {
68
- $ deletes [$ image ->strategy ][] = $ image ->pathname ;
52
+ $ images = $ this ->user ->images ()->where ('id ' , 'in ' , $ id )->select ();
53
+ foreach ($ images as &$ value ) {
54
+ // 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
55
+ if (!$ this ->exists ($ value )) {
56
+ $ deletes [$ value ->strategy ][] = $ value ->pathname ;
69
57
}
70
- $ image ->delete ();
58
+ $ value ->delete ();
59
+ unset($ value );
71
60
}
72
61
// 是否开启软删除(开启了只删除记录,不删除文件)
73
62
if (!$ this ->getConfig ('soft_delete ' )) {
Original file line number Diff line number Diff line change @@ -77,25 +77,14 @@ public function delete()
77
77
try {
78
78
$ id = $ this ->request ->post ('id ' );
79
79
$ deletes = []; // 需要删除的文件
80
- if (is_array ($ id )) {
81
- $ images = ImagesModel::all ($ id );
82
- foreach ($ images as &$ value ) {
83
- // 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
84
- if (!$ this ->exists ($ value )) {
85
- $ deletes [$ value ->strategy ][] = $ value ->pathname ;
86
- }
87
- $ value ->delete ();
88
- unset($ value );
89
- }
90
- } else {
91
- $ image = ImagesModel::get ($ id );
92
- if (!$ image ) {
93
- throw new Exception ('没有找到该图片数据 ' );
94
- }
95
- if (!$ this ->exists ($ image )) {
96
- $ deletes [$ image ->strategy ][] = $ image ->pathname ;
80
+ $ images = ImagesModel::where ('id ' , 'in ' , $ id )->select ();
81
+ foreach ($ images as &$ value ) {
82
+ // 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
83
+ if (!$ this ->exists ($ value )) {
84
+ $ deletes [$ value ->strategy ][] = $ value ->pathname ;
97
85
}
98
- $ image ->delete ();
86
+ $ value ->delete ();
87
+ unset($ value );
99
88
}
100
89
// 是否开启软删除(开启了只删除记录,不删除文件)
101
90
if (!$ this ->getConfig ('soft_delete ' )) {
You can’t perform that action at this time.
0 commit comments