Skip to content

Commit 62b0ee5

Browse files
committedMar 19, 2020
🐛 Fixing a bug.
1 parent ca06b2f commit 62b0ee5

File tree

2 files changed

+14
-36
lines changed

2 files changed

+14
-36
lines changed
 

‎application/index/controller/User.php

+7-18
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,14 @@ public function deleteImages($deleteId = null)
4949
try {
5050
$id = $deleteId ? $deleteId : $this->request->post('id');
5151
$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;
6957
}
70-
$image->delete();
58+
$value->delete();
59+
unset($value);
7160
}
7261
// 是否开启软删除(开启了只删除记录,不删除文件)
7362
if (!$this->getConfig('soft_delete')) {

‎application/index/controller/admin/Images.php

+7-18
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,14 @@ public function delete()
7777
try {
7878
$id = $this->request->post('id');
7979
$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;
9785
}
98-
$image->delete();
86+
$value->delete();
87+
unset($value);
9988
}
10089
// 是否开启软删除(开启了只删除记录,不删除文件)
10190
if (!$this->getConfig('soft_delete')) {

0 commit comments

Comments
 (0)
Please sign in to comment.