SystemFile.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. * @return mixed
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. *
  48. * @date 2022/09/07
  49. * @author yyw
  50. */
  51. public function login()
  52. {
  53. [$password] = $this->request->postMore([
  54. 'password',
  55. ], true);
  56. $adminInfo = $this->request->adminInfo();
  57. if (!$adminInfo) return app('json')->fail(100101);
  58. if ($adminInfo['level'] != 0) return app('json')->fail(100101);
  59. return app('json')->success($this->services->login($adminInfo['account'], $password, 'admin_edit'));
  60. }
  61. //打开目录
  62. public function opendir()
  63. {
  64. return app('json')->success($this->services->opendir());
  65. }
  66. //读取文件
  67. public function openfile()
  68. {
  69. $file = $this->request->param('filepath');
  70. if (empty($file)) return app('json')->fail(410087);
  71. return app('json')->success($this->services->openfile($file));
  72. }
  73. //保存文件
  74. public function savefile()
  75. {
  76. $comment = $this->request->param('comment');
  77. $filepath = $this->request->param('filepath');
  78. if (empty($comment) || empty($filepath)) {
  79. return app('json')->fail(410087);
  80. }
  81. $res = $this->services->savefile($filepath, $comment);
  82. if ($res) {
  83. return app('json')->success(100000);
  84. } else {
  85. return app('json')->fail(100006);
  86. }
  87. }
  88. /**
  89. * 创建文件夹
  90. * @return mixed
  91. *
  92. * @date 2022/09/17
  93. * @author yyw
  94. */
  95. public function createFolder()
  96. {
  97. [$path] = $this->request->postMore([
  98. ['path', '']
  99. ], true);
  100. try {
  101. $this->services->createFolder($path);
  102. } catch (\Exception $e) {
  103. return app('json')->fail($e->getMessage());
  104. }
  105. return app('json')->success(100010);
  106. }
  107. /**
  108. * 创建文件
  109. * @return mixed
  110. *
  111. * @date 2022/09/17
  112. * @author yyw
  113. */
  114. public function createFile()
  115. {
  116. [$path] = $this->request->postMore([
  117. ['path', '']
  118. ], true);
  119. try {
  120. $this->services->createFile($path);
  121. } catch (\Exception $e) {
  122. return app('json')->fail($e->getMessage());
  123. }
  124. return app('json')->success(100010);
  125. }
  126. /**
  127. * 删除文件或文件夹
  128. * @return mixed
  129. *
  130. * @date 2022/09/17
  131. * @author yyw
  132. */
  133. public function delFolder()
  134. {
  135. [$path] = $this->request->postMore([
  136. ['path', '']
  137. ], true);
  138. try {
  139. $this->services->delFolder($path);
  140. } catch (\Exception $e) {
  141. return app('json')->fail($e->getMessage());
  142. }
  143. return app('json')->success(100010);
  144. }
  145. public function copyFolder()
  146. {
  147. [$surDir, $toDir] = $this->request->postMore([
  148. ['surDir', ''],
  149. ['toDir', '']
  150. ], true);
  151. try {
  152. return app('json')->success($this->services->copyFolder($surDir, $toDir));
  153. } catch (\Exception $e) {
  154. return app('json')->fail($e->getMessage());
  155. }
  156. }
  157. }