SystemAttachment.php 5.9 KB

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