SystemAttachment.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. ['real_name', '']
  44. ]);
  45. return app('json')->success($this->service->getImageList($where));
  46. }
  47. /**
  48. * 删除指定资源
  49. * @return mixed
  50. */
  51. public function delete()
  52. {
  53. [$ids] = $this->request->postMore([
  54. ['ids', '']
  55. ], true);
  56. $this->service->del($ids);
  57. return app('json')->success(100002);
  58. }
  59. /**
  60. * 图片上传
  61. * @param int $upload_type
  62. * @param int $type
  63. * @return mixed
  64. */
  65. public function upload($upload_type = 0, $type = 0)
  66. {
  67. [$pid, $file, $menuName] = $this->request->postMore([
  68. ['pid', 0],
  69. ['file', 'file'],
  70. ['menu_name', '']
  71. ], true);
  72. $res = $this->service->upload((int)$pid, $file, $upload_type, $type, $menuName);
  73. return app('json')->success(100032, ['src' => $res]);
  74. }
  75. /**
  76. * 移动图片
  77. * @return mixed
  78. */
  79. public function moveImageCate()
  80. {
  81. $data = $this->request->postMore([
  82. ['pid', 0],
  83. ['images', '']
  84. ]);
  85. $this->service->move($data);
  86. return app('json')->success(100034);
  87. }
  88. /**
  89. * 修改文件名
  90. * @param $id
  91. * @return mixed
  92. */
  93. public function update($id)
  94. {
  95. $realName = $this->request->post('real_name', '');
  96. if (!$realName) {
  97. return app('json')->fail(400104);
  98. }
  99. $this->service->update($id, ['real_name' => $realName]);
  100. return app('json')->success(100001);
  101. }
  102. /**
  103. * 获取上传类型
  104. * @return mixed
  105. */
  106. public function uploadType()
  107. {
  108. $data['upload_type'] = (string)sys_config('upload_type', 1);
  109. return app('json')->success($data);
  110. }
  111. /**
  112. * 视频分片上传
  113. * @return mixed
  114. */
  115. public function videoUpload()
  116. {
  117. $data = $this->request->postMore([
  118. ['chunkNumber', 0],//第几分片
  119. ['currentChunkSize', 0],//分片大小
  120. ['chunkSize', 0],//总大小
  121. ['totalChunks', 0],//分片总数
  122. ['file', 'file'],//文件
  123. ['md5', ''],//MD5
  124. ['filename', ''],//文件名称
  125. ]);
  126. $res = $this->service->videoUpload($data, $_FILES['file']);
  127. return app('json')->success($res);
  128. }
  129. /**
  130. * 获取扫码上传页面链接以及参数
  131. * @return \think\Response
  132. * @author 吴汐
  133. * @email 442384644@qq.com
  134. * @date 2023/06/13
  135. */
  136. public function scanUploadQrcode()
  137. {
  138. [$pid] = $this->request->getMore([
  139. ['pid', 0]
  140. ], true);
  141. $uploadToken = md5(time());
  142. $this->service->cacheDriver()->set('scan_upload', $uploadToken, 600);
  143. $url = sys_config('site_url') . '/app/upload?token=' . $uploadToken . '&pid=' . $pid;
  144. return app('json')->success(['url' => $url]);
  145. }
  146. /**
  147. * 删除二维码
  148. * @return \think\Response
  149. * @author 等风来
  150. * @email 136327134@qq.com
  151. * @date 2023/6/26
  152. */
  153. public function removeUploadQrcode()
  154. {
  155. $this->service->cacheDriver()->delete('scan_upload');
  156. return app('json')->success();
  157. }
  158. /**
  159. * 获取扫码上传的图片数据
  160. * @param $scan_token
  161. * @return \think\Response
  162. * @author 吴汐
  163. * @email 442384644@qq.com
  164. * @date 2023/06/13
  165. */
  166. public function scanUploadImage($scan_token)
  167. {
  168. return app('json')->success($this->service->scanUploadImage($scan_token));
  169. }
  170. /**
  171. * 网络图片上传
  172. * @return \think\Response
  173. * @throws \Exception
  174. * @author 吴汐
  175. * @email 442384644@qq.com
  176. * @date 2023/06/13
  177. */
  178. public function onlineUpload()
  179. {
  180. $data = $this->request->postMore([
  181. ['pid', 0],
  182. ['images', []]
  183. ]);
  184. $this->service->onlineUpload($data);
  185. return app('json')->success(100032);
  186. }
  187. }