SystemFile.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 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. * @var SystemFileServices
  25. */
  26. protected $services;
  27. /**
  28. * 构造方法
  29. * SystemFile constructor.
  30. * @param App $app
  31. * @param SystemFileServices $services
  32. */
  33. public function __construct(App $app, SystemFileServices $services)
  34. {
  35. parent::__construct($app);
  36. $this->services = $services;
  37. }
  38. /**
  39. * 文件校验记录
  40. * @return mixed
  41. */
  42. public function index()
  43. {
  44. return app('json')->success(['list' => $this->services->getFileList()]);
  45. }
  46. /**
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. *
  52. * @date 2022/09/07
  53. * @author yyw
  54. */
  55. public function login()
  56. {
  57. [$password] = $this->request->postMore([
  58. 'password',
  59. ], true);
  60. $adminInfo = $this->request->adminInfo();
  61. if (!$adminInfo) return app('json')->fail('非法操作');
  62. if ($adminInfo['level'] != 0) return app('json')->fail('非法操作');
  63. if ($password === '') return app('json')->fail('请输入密码');
  64. return app('json')->success($this->services->login($password, 'file_edit'));
  65. }
  66. //打开目录
  67. public function opendir()
  68. {
  69. [$dir, $fileDir, $superior] = $this->request->getMore([
  70. ['dir', ''],
  71. ['filedir', ''],
  72. ['superior', ''],
  73. ], true);
  74. return app('json')->success($this->services->opendir($dir, $fileDir, $superior));
  75. }
  76. //文件备注
  77. public function fileMark()
  78. {
  79. [$path, $fileToken] = $this->request->postMore([
  80. ['path', ''],
  81. ['fileToken', ''],
  82. ], true);
  83. if ($path == '') return app('json')->fail('参数错误');
  84. return app('json')->success($this->services->markForm($path, $fileToken));
  85. }
  86. //文件备注保存
  87. public function fileMarkSave()
  88. {
  89. [$full_path, $mark] = $this->request->postMore([
  90. ['full_path', ''],
  91. ['mark', ''],
  92. ], true);
  93. $full_path = $this->request->param('full_path');
  94. if ($full_path == '') return app('json')->fail('参数错误');
  95. $this->services->fileMarkSave($full_path, $mark);
  96. return app('json')->success('保存成功');
  97. }
  98. //读取文件
  99. public function openfile()
  100. {
  101. $file = $this->request->param('filepath');
  102. if (empty($file)) return app('json')->fail('平台错误:发生异常,请稍后重试');
  103. return app('json')->success($this->services->openfile($file));
  104. }
  105. //保存文件
  106. public function savefile()
  107. {
  108. $comment = $this->request->param('comment');
  109. $filepath = $this->request->param('filepath');
  110. if (empty($filepath)) {
  111. return app('json')->fail('文件路径不存在');
  112. }
  113. $res = $this->services->savefile($filepath, $comment);
  114. if ($res) {
  115. return app('json')->success('保存成功');
  116. } else {
  117. return app('json')->fail('保存失败');
  118. }
  119. }
  120. /**
  121. * 创建文件夹
  122. * @return mixed
  123. *
  124. * @date 2022/09/17
  125. * @author yyw
  126. */
  127. public function createFolder()
  128. {
  129. [$path, $name] = $this->request->postMore([
  130. ['path', ''],
  131. ['name', '']
  132. ], true);
  133. if (empty($path) || empty($name)) {
  134. return app('json')->fail('平台错误:发生异常,请稍后重试');
  135. }
  136. $data = [];
  137. try {
  138. $res = $this->services->createFolder($path, $name);
  139. if ($res) {
  140. $data = [
  141. 'children' => [],
  142. 'contextmenu' => true,
  143. 'isDir' => true,
  144. 'loading' => false,
  145. 'path' => $path,
  146. 'pathname' => $path . DS . $name,
  147. 'title' => $name,
  148. ];
  149. } else {
  150. return app('json')->fail('操作失败');
  151. }
  152. } catch (\Exception $e) {
  153. return app('json')->fail($e->getMessage());
  154. }
  155. return app('json')->success($data);
  156. }
  157. /**
  158. * 创建文件
  159. * @return mixed
  160. *
  161. * @date 2022/09/17
  162. * @author yyw
  163. */
  164. public function createFile()
  165. {
  166. [$path, $name] = $this->request->postMore([
  167. ['path', ''],
  168. ['name', '']
  169. ], true);
  170. if (empty($path) || empty($name)) {
  171. return app('json')->fail('平台错误:发生异常,请稍后重试');
  172. }
  173. $data = [];
  174. try {
  175. $res = $this->services->createFile($path, $name);
  176. if ($res) {
  177. $data = [
  178. 'children' => [],
  179. 'contextmenu' => true,
  180. 'isDir' => false,
  181. 'loading' => false,
  182. 'path' => $path,
  183. 'pathname' => $path . DS . $name,
  184. 'title' => $name,
  185. ];
  186. } else {
  187. return app('json')->fail('操作失败');
  188. }
  189. } catch (\Exception $e) {
  190. return app('json')->fail($e->getMessage());
  191. }
  192. return app('json')->success($data);
  193. }
  194. /**
  195. * 删除文件或文件夹
  196. * @return mixed
  197. *
  198. * @date 2022/09/17
  199. * @author yyw
  200. */
  201. public function delFolder()
  202. {
  203. [$path] = $this->request->postMore([
  204. ['path', '']
  205. ], true);
  206. if (empty($path)) {
  207. return app('json')->fail('平台错误:发生异常,请稍后重试');
  208. }
  209. try {
  210. $this->services->delFolder($path);
  211. } catch (\Exception $e) {
  212. return app('json')->fail($e->getMessage());
  213. }
  214. return app('json')->success('操作成功');
  215. }
  216. /**
  217. * 文件重命名
  218. * @return mixed
  219. *
  220. * @date 2022/09/28
  221. * @author yyw
  222. */
  223. public function rename()
  224. {
  225. [$newname, $oldname] = $this->request->postMore([
  226. ['newname', ''],
  227. ['oldname', '']
  228. ], true);
  229. if (empty($newname) || empty($oldname)) {
  230. return app('json')->fail('平台错误:发生异常,请稍后重试');
  231. }
  232. try {
  233. $this->services->rename($newname, $oldname);
  234. } catch (\Exception $e) {
  235. return app('json')->fail($e->getMessage());
  236. }
  237. return app('json')->success('操作成功');
  238. }
  239. public function copyFolder()
  240. {
  241. [$surDir, $toDir] = $this->request->postMore([
  242. ['surDir', ''],
  243. ['toDir', '']
  244. ], true);
  245. if (empty($surDir) || empty($toDir)) {
  246. return app('json')->fail('平台错误:发生异常,请稍后重试');
  247. }
  248. try {
  249. return app('json')->success($this->services->copyFolder($surDir, $toDir));
  250. } catch (\Exception $e) {
  251. return app('json')->fail($e->getMessage());
  252. }
  253. }
  254. /**
  255. * 写入文件md5
  256. * @return \think\Response
  257. * @author wuhaotian
  258. * @email 442384644@qq.com
  259. * @date 2026/2/25
  260. */
  261. public function writeMd5()
  262. {
  263. try {
  264. $this->services->writeMd5();
  265. } catch (\Exception $e) {
  266. return app('json')->fail($e->getMessage());
  267. }
  268. return app('json')->success('操作成功');
  269. }
  270. }