<?php
namespace app\store\model;
use think\Request;
use app\common\model\UploadFile as UploadFileModel;
use app\store\model\Setting as SettingModel;
use app\common\library\storage\Driver as StorageDriver;
class UploadFile extends UploadFileModel
{
public function getList($groupId = -1, $fileType = '', $isRecycle = -1)
{
$groupId != -1 && $this->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()
]);
}
public function setRecycle($isRecycle = true)
{
return $this->save(['is_recycle' => (int)$isRecycle]);
}
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]);
}
public function softDelete($fileIds)
{
return $this->where('file_id', 'in', $fileIds)->update(['is_recycle' => 1]);
}
public function moveGroup($group_id, $fileIds)
{
return $this->where('file_id', 'in', $fileIds)->update(compact('group_id'));
}
}