SystemFile.php 7.5 KB

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