where('group_id', '=', (int)$groupId); // 文件类型 !empty($fileType) && $this->where('file_type', '=', trim($fileType)); // 是否在回收站 $isRecycle > -1 && $this->where('is_recycle', '=', (int)$isRecycle); // 查询列表数据 return $this->with(['upload_group']) ->where(['is_user' => 0, 'is_delete' => 0]) ->order(['file_id' => 'desc']) ->paginate(32, false, [ 'query' => Request::instance()->request() ]); } /** * 移入|移出回收站 * @param bool $isRecycle * @return false|int */ public function setRecycle($isRecycle = true) { return $this->save(['is_recycle' => (int)$isRecycle]); } /** * 删除文件 * @return false|int * @throws \think\Exception */ public function setDelete() { // 存储配置信息 $config = SettingModel::getItem('storage'); // 实例化存储驱动 $StorageDriver = new StorageDriver($config, $this['storage']); // 删除文件 if (!$StorageDriver->delete($this['file_name'])) { $this->error = '文件删除失败:' . $StorageDriver->getError(); return false; } return $this->save(['is_delete' => 1]); } /** * 批量软删除 * @param $fileIds * @return $this */ public function softDelete($fileIds) { return $this->where('file_id', 'in', $fileIds)->update(['is_recycle' => 1]); } /** * 批量移动文件分组 * @param $group_id * @param $fileIds * @return $this */ public function moveGroup($group_id, $fileIds) { return $this->where('file_id', 'in', $fileIds)->update(compact('group_id')); } }