SystemAttachment.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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\file;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\system\attachment\SystemAttachmentServices;
  14. use think\facade\App;
  15. /**
  16. * 附件管理类
  17. * Class SystemAttachment
  18. * @package app\adminapi\controller\v1\file
  19. */
  20. class SystemAttachment extends AuthController
  21. {
  22. /**
  23. * @var SystemAttachmentServices
  24. */
  25. protected $service;
  26. /**
  27. * @param App $app
  28. * @param SystemAttachmentServices $service
  29. */
  30. public function __construct(App $app, SystemAttachmentServices $service)
  31. {
  32. parent::__construct($app);
  33. $this->service = $service;
  34. }
  35. /**
  36. * 显示列表
  37. * @return mixed
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['pid', 0]
  43. ]);
  44. return app('json')->success($this->service->getImageList($where));
  45. }
  46. /**
  47. * 删除指定资源
  48. * @return mixed
  49. */
  50. public function delete()
  51. {
  52. [$ids] = $this->request->postMore([
  53. ['ids', '']
  54. ], true);
  55. $this->service->del($ids);
  56. return app('json')->success(100002);
  57. }
  58. /**
  59. * 图片上传
  60. * @param int $upload_type
  61. * @param int $type
  62. * @return mixed
  63. */
  64. public function upload($upload_type = 0, $type = 0)
  65. {
  66. [$pid, $file, $menuName] = $this->request->postMore([
  67. ['pid', 0],
  68. ['file', 'file'],
  69. ['menu_name', '']
  70. ], true);
  71. $res = $this->service->upload((int)$pid, $file, $upload_type, $type, $menuName);
  72. return app('json')->success(100032, ['src' => $res]);
  73. }
  74. /**
  75. * 移动图片
  76. * @return mixed
  77. */
  78. public function moveImageCate()
  79. {
  80. $data = $this->request->postMore([
  81. ['pid', 0],
  82. ['images', '']
  83. ]);
  84. $this->service->move($data);
  85. return app('json')->success(100034);
  86. }
  87. /**
  88. * 修改文件名
  89. * @param $id
  90. * @return mixed
  91. */
  92. public function update($id)
  93. {
  94. $realName = $this->request->post('real_name', '');
  95. if (!$realName) {
  96. return app('json')->fail(400104);
  97. }
  98. $this->service->update($id, ['real_name' => $realName]);
  99. return app('json')->success(100001);
  100. }
  101. /**
  102. * 获取上传类型
  103. * @return mixed
  104. */
  105. public function uploadType()
  106. {
  107. $data['upload_type'] = (string)sys_config('upload_type', 1);
  108. return app('json')->success($data);
  109. }
  110. /**
  111. * 视频分片上传
  112. * @return mixed
  113. */
  114. public function videoUpload()
  115. {
  116. $data = $this->request->postMore([
  117. ['chunkNumber', 0],//第几分片
  118. ['currentChunkSize', 0],//分片大小
  119. ['chunkSize', 0],//总大小
  120. ['totalChunks', 0],//分片总数
  121. ['file', 'file'],//文件
  122. ['md5', ''],//MD5
  123. ['filename', ''],//文件名称
  124. ]);
  125. $res = $this->service->videoUpload($data, $_FILES['file']);
  126. return app('json')->success($res);
  127. }
  128. }