SystemFile.php 7.4 KB

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