tapi/app/controller/admin/system/FileController.php
2025-08-27 20:38:16 +08:00

60 lines
1.7 KiB
PHP

<?php
namespace app\controller\admin\system;
use app\BaseController;
use app\entity\SysFileRecord;
use app\service\CurdService;
use think\db\exception\DbException;
use think\exception\FileException;
use think\exception\ValidateException;
use think\facade\Filesystem;
use think\response\Json;
class FileController extends BaseController
{
/**
* 分页查询账号登录记录
* @return Json
* @throws DbException
*/
public function page(): Json
{
$model = SysFileRecord::with(['createUser'])->withSearch(['name', 'path', 'createNickname'], [
'name' => $this->request->param('name/s', ''),
'path' => $this->request->param('path/s', ''),
'createNickname' => $this->request->param('createNickname/s', ''),
'createTime' => [
$this->request->get('createTimeStart/s', ''),
$this->request->get('createTimeEnd/s', '')
],
]);
$paginate = CurdService::getPaginate($this->request, $model);
return $this->writeSuccess('ok', $paginate);
}
public function batchRemove()
{
return $this->writeError('禁止删除');
$data = $this->request->delete();
SysFileRecord::destroy($data);
return $this->writeSuccess('删除成功');
}
public function upload()
{
$file = $this->request->file('file');
if (empty($file)) {
return $this->writeError('文件不存在');
}
try {
$result = filesystem()->upload($file, 0, $this->auth->userId);
} catch (ValidateException|FileException $e) {
return $this->writeError($e->getMessage());
}
return $this->writeSuccess('ok', $result);
}
}