SystemFile.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\system;
  12. use think\facade\App;
  13. use app\adminapi\controller\AuthController;
  14. use app\services\system\log\SystemFileServices;
  15. /**
  16. * 文件校验控制器
  17. * Class SystemFile
  18. * @package app\admin\controller\system
  19. *
  20. */
  21. class SystemFile extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * SystemFile constructor.
  26. * @param App $app
  27. * @param SystemFileServices $services
  28. */
  29. public function __construct(App $app, SystemFileServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 文件校验记录
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. return app('json')->success(['list' => $this->services->getFileList()]);
  41. }
  42. //打开目录
  43. public function opendir()
  44. {
  45. return app('json')->success($this->services->opendir());
  46. }
  47. //读取文件
  48. public function openfile()
  49. {
  50. $file = $this->request->param('filepath');
  51. if (empty($file)) return app('json')->fail('出现错误');
  52. return app('json')->success($this->services->openfile($file));
  53. }
  54. //保存文件
  55. public function savefile()
  56. {
  57. return app('json')->fail('请勿在生产环境使用,该接口存在危险性!!!');//如果开发环境,可以注释本行
  58. $comment = $this->request->param('comment');
  59. $filepath = $this->request->param('filepath');
  60. if(empty($comment) || empty($filepath)){
  61. return app('json')->fail('出现错误');
  62. }
  63. $res = $this->services->savefile($filepath,$comment);
  64. if ($res) {
  65. return app('json')->success('保存成功!');
  66. } else {
  67. return app('json')->fail('保存失败');
  68. }
  69. }
  70. }