SystemAttachment.php 5.3 KB

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