SystemFile.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. if ($password === '') return app('json')->fail(400256);
  60. return app('json')->success($this->services->login($password, 'file_edit'));
  61. }
  62. //打开目录
  63. public function opendir()
  64. {
  65. return app('json')->success($this->services->opendir());
  66. }
  67. //文件备注
  68. public function fileMark()
  69. {
  70. [$path, $fileToken] = $this->request->postMore([
  71. ['path', ''],
  72. ['fileToken', ''],
  73. ], true);
  74. if ($path == '') return app('json')->fail(100100);
  75. return app('json')->success($this->services->markForm($path, $fileToken));
  76. }
  77. //文件备注保存
  78. public function fileMarkSave()
  79. {
  80. [$full_path, $mark] = $this->request->postMore([
  81. ['full_path', ''],
  82. ['mark', ''],
  83. ], true);
  84. if ($full_path == '') return app('json')->fail(100100);
  85. $this->services->fileMarkSave($full_path, $mark);
  86. return app('json')->success(100000);
  87. }
  88. //读取文件
  89. public function openfile()
  90. {
  91. $file = $this->request->param('filepath');
  92. if (empty($file)) return app('json')->fail(410087);
  93. return app('json')->success($this->services->openfile($file));
  94. }
  95. //保存文件
  96. public function savefile()
  97. {
  98. $comment = $this->request->param('comment');
  99. $filepath = $this->request->param('filepath');
  100. if (empty($filepath)) {
  101. return app('json')->fail(410087);
  102. }
  103. $res = $this->services->savefile($filepath, $comment);
  104. if ($res) {
  105. return app('json')->success(100000);
  106. } else {
  107. return app('json')->fail(100006);
  108. }
  109. }
  110. /**
  111. * 创建文件夹
  112. * @return mixed
  113. *
  114. * @date 2022/09/17
  115. * @author yyw
  116. */
  117. public function createFolder()
  118. {
  119. [$path, $name] = $this->request->postMore([
  120. ['path', ''],
  121. ['name', '']
  122. ], true);
  123. if (empty($path) || empty($name)) {
  124. return app('json')->fail(410087);
  125. }
  126. $data = [];
  127. try {
  128. $res = $this->services->createFolder($path, $name);
  129. if ($res) {
  130. $data = [
  131. 'children' => [],
  132. 'contextmenu' => true,
  133. 'isDir' => true,
  134. 'loading' => false,
  135. 'path' => $path,
  136. 'pathname' => $path . DS . $name,
  137. 'title' => $name,
  138. ];
  139. } else {
  140. return app('json')->fail(100005);
  141. }
  142. } catch (\Exception $e) {
  143. return app('json')->fail($e->getMessage());
  144. }
  145. return app('json')->success($data);
  146. }
  147. /**
  148. * 创建文件
  149. * @return mixed
  150. *
  151. * @date 2022/09/17
  152. * @author yyw
  153. */
  154. public function createFile()
  155. {
  156. [$path, $name] = $this->request->postMore([
  157. ['path', ''],
  158. ['name', '']
  159. ], true);
  160. if (empty($path) || empty($name)) {
  161. return app('json')->fail(410087);
  162. }
  163. $data = [];
  164. try {
  165. $res = $this->services->createFile($path, $name);
  166. if ($res) {
  167. $data = [
  168. 'children' => [],
  169. 'contextmenu' => true,
  170. 'isDir' => false,
  171. 'loading' => false,
  172. 'path' => $path,
  173. 'pathname' => $path . DS . $name,
  174. 'title' => $name,
  175. ];
  176. } else {
  177. return app('json')->fail(100005);
  178. }
  179. } catch (\Exception $e) {
  180. return app('json')->fail($e->getMessage());
  181. }
  182. return app('json')->success($data);
  183. }
  184. /**
  185. * 删除文件或文件夹
  186. * @return mixed
  187. *
  188. * @date 2022/09/17
  189. * @author yyw
  190. */
  191. public function delFolder()
  192. {
  193. [$path] = $this->request->postMore([
  194. ['path', '']
  195. ], true);
  196. if (empty($path)) {
  197. return app('json')->fail(410087);
  198. }
  199. try {
  200. $this->services->delFolder($path);
  201. } catch (\Exception $e) {
  202. return app('json')->fail($e->getMessage());
  203. }
  204. return app('json')->success(100010);
  205. }
  206. /**
  207. * 文件重命名
  208. * @return mixed
  209. *
  210. * @date 2022/09/28
  211. * @author yyw
  212. */
  213. public function rename()
  214. {
  215. [$newname, $oldname] = $this->request->postMore([
  216. ['newname', ''],
  217. ['oldname', '']
  218. ], true);
  219. if (empty($newname) || empty($oldname)) {
  220. return app('json')->fail(410087);
  221. }
  222. try {
  223. $this->services->rename($newname, $oldname);
  224. } catch (\Exception $e) {
  225. return app('json')->fail($e->getMessage());
  226. }
  227. return app('json')->success(100010);
  228. }
  229. public function copyFolder()
  230. {
  231. [$surDir, $toDir] = $this->request->postMore([
  232. ['surDir', ''],
  233. ['toDir', '']
  234. ], true);
  235. if (empty($surDir) || empty($toDir)) {
  236. return app('json')->fail(410087);
  237. }
  238. try {
  239. return app('json')->success($this->services->copyFolder($surDir, $toDir));
  240. } catch (\Exception $e) {
  241. return app('json')->fail($e->getMessage());
  242. }
  243. }
  244. }