update:优化代码
This commit is contained in:
parent
d9faa42905
commit
3a0c537ce0
@ -9,19 +9,36 @@ use think\facade\Filesystem;
|
|||||||
|
|
||||||
class Attachments extends CatchController
|
class Attachments extends CatchController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 列表
|
||||||
|
*
|
||||||
|
* @time 2020年07月25日
|
||||||
|
* @param AttachmentsModel $model
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
public function index(AttachmentsModel $model)
|
public function index(AttachmentsModel $model)
|
||||||
{
|
{
|
||||||
return CatchResponse::paginate($model->getList());
|
return CatchResponse::paginate($model->getList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @time 2020年07月25日
|
||||||
|
* @param $id
|
||||||
|
* @param AttachmentsModel $model
|
||||||
|
* @throws \League\Flysystem\FileNotFoundException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
public function delete($id, AttachmentsModel $model)
|
public function delete($id, AttachmentsModel $model)
|
||||||
{
|
{
|
||||||
$ids = Utils::stringToArrayBy($id);
|
$attachments = $model->whereIn('id', Utils::stringToArrayBy($id))->select();
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
if ($model->deleteBy($id)) {
|
||||||
$attachment = $model->findBy($id);
|
foreach ($attachments as $attachment) {
|
||||||
if ($attachment && $model->deleteBy($id)) {
|
|
||||||
Filesystem::delete($attachment->path);
|
Filesystem::delete($attachment->path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,13 @@ class OperateLog extends CatchController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除
|
* 批量删除
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param mixed $id
|
||||||
* @throws \Exception
|
* @param Log $log
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function delete($id, Log $log)
|
public function delete($id, Log $log)
|
||||||
{
|
{
|
||||||
$ids = explode(',', $id);
|
return CatchResponse::success($log->deleteBy($id));
|
||||||
|
|
||||||
if (empty($ids)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CatchResponse::success($log->whereIn('id', $ids)->delete());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user