model = new AttachmentModel(); } /** * 删除 * @param array $ids * @throws Throwable */ public function del(array $ids = []): void { if (!$this->request->isDelete() || !$ids) { $this->error(__('Parameter error')); } $where = []; $dataLimitAdminIds = $this->getDataLimitAdminIds(); if ($dataLimitAdminIds) { $where[] = [$this->dataLimitField, 'in', $dataLimitAdminIds]; } $pk = $this->model->getPk(); $where[] = [$pk, 'in', $ids]; $count = 0; $data = $this->model->where($where)->select(); try { foreach ($data as $v) { $count += $v->delete(); } } catch (Throwable $e) { $this->error(__('%d records and files have been deleted', [$count]) . $e->getMessage()); } if ($count) { $this->success(__('%d records and files have been deleted', [$count])); } else { $this->error(__('No rows were deleted')); } } }