SystemAttachment.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\supplier\file;
  12. use app\controller\supplier\AuthController;
  13. use app\services\other\CacheServices;
  14. use app\services\system\admin\SystemAdminServices;
  15. use app\services\system\attachment\SystemAttachmentServices;
  16. use think\facade\App;
  17. /**
  18. * 图片管理类
  19. * Class SystemAttachment
  20. * @package app\controller\store\file
  21. */
  22. class SystemAttachment extends AuthController
  23. {
  24. protected $service;
  25. public function __construct(App $app, SystemAttachmentServices $service)
  26. {
  27. parent::__construct($app);
  28. $this->service = $service;
  29. }
  30. /**
  31. * 显示列表
  32. * @return mixed
  33. */
  34. public function index()
  35. {
  36. $where = $this->request->getMore([
  37. ['pid', 0],
  38. ['file_type', 1]
  39. ]);
  40. $where['type'] = 4;
  41. $where['relation_id'] = $this->supplierId;
  42. return app('json')->success($this->service->getImageList($where));
  43. }
  44. /**
  45. * 删除指定资源
  46. *
  47. * @param string $ids
  48. * @return \think\Response
  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('删除成功');
  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] = $this->request->postMore([
  67. ['pid', 0],
  68. ['file', 'file'],
  69. ], true);
  70. $res = $this->service->storeUpload((int)$pid, $file, (int)$this->supplierId, 4);
  71. return app('json')->success('上传成功', ['src' => $res]);
  72. }
  73. /**
  74. * 移动图片
  75. * @return mixed
  76. */
  77. public function moveImageCate()
  78. {
  79. $data = $this->request->postMore([
  80. ['pid', 0],
  81. ['images', '']
  82. ]);
  83. $this->service->move($data);
  84. return app('json')->success('移动成功');
  85. }
  86. /**
  87. * 修改文件名
  88. * @param $id
  89. * @return mixed
  90. */
  91. public function update($id)
  92. {
  93. $realName = $this->request->post('real_name', '');
  94. if (!$realName) {
  95. return app('json')->fail('文件名称不能为空');
  96. }
  97. $this->service->update($id, ['real_name' => $realName]);
  98. return app('json')->success('修改成功');
  99. }
  100. /**
  101. * 获取上传类型
  102. * @return mixed
  103. */
  104. public function uploadType()
  105. {
  106. $data['upload_type'] = (string)sys_config('upload_type', 1);
  107. return app('json')->success($data);
  108. }
  109. /**
  110. * 视频分片上传
  111. * @return mixed
  112. */
  113. public function videoUpload()
  114. {
  115. $data = $this->request->postMore([
  116. ['chunkNumber', 0],//第几分片
  117. ['currentChunkSize', 0],//分片大小
  118. ['chunkSize', 0],//总大小
  119. ['totalChunks', 0],//分片总数
  120. ['file', 'file'],//文件
  121. ['md5', ''],//MD5
  122. ['filename', ''],//文件名称
  123. ['pid', 0],//分类ID
  124. ]);
  125. $fileHandle = $this->request->file($data['file']);
  126. if (!$fileHandle) return $this->fail('上传信息为空');
  127. $res = $this->service->videoUpload($data, $fileHandle, 4, (int)$this->supplierId);
  128. return app('json')->success($res);
  129. }
  130. /**
  131. * 保存云端视频记录
  132. * @return mixed
  133. */
  134. public function saveVideoAttachment()
  135. {
  136. $data = $this->request->postMore([
  137. ['path', ''],//视频地址
  138. ['cover_image', ''],//封面地址
  139. ['pid', 0],//分类ID
  140. ['upload_type', 1],//上传类型
  141. ]);
  142. $res = $this->service->saveOssVideoAttachment($data, 4, (int)$this->supplierId, (int)$data['upload_type']);
  143. return app('json')->success($res);
  144. }
  145. /**获取扫码上传页面链接以及参数
  146. * @return \think\Response
  147. */
  148. public function scanUploadQrcode(CacheServices $services)
  149. {
  150. [$pid] = $this->request->getMore([
  151. ['pid', 0]
  152. ], true);
  153. $uploadToken = md5(time());
  154. $upload_file_size_max = config('upload.filesize');//文件上传大小kb
  155. $services->setDbCache($this->supplierId.'_supplier_scan_upload', $uploadToken, 68400);
  156. $url = sys_config('site_url') . '/app/upload?pid=' . $pid . '&cache='. $this->supplierId .'_supplier_scan_upload&type=4&relation_id='. $this->supplierId . '&upload_file_size_max=' . $upload_file_size_max . '&token=' . $uploadToken;
  157. return app('json')->success(['url' => $url]);
  158. }
  159. /**删除二维码
  160. * @return \think\Response
  161. */
  162. public function removeUploadQrcode(CacheServices $services)
  163. {
  164. $services->delectDbCache($this->supplierId.'_supplier_scan_upload');
  165. return app('json')->success();
  166. }
  167. /**获取扫码上传的图片数据
  168. * @param $scan_token
  169. * @return \think\Response
  170. */
  171. public function scanUploadImage($scan_token)
  172. {
  173. return app('json')->success($this->service->scanUploadImage($scan_token));
  174. }
  175. /**网络图片上传
  176. * @return \think\Response
  177. */
  178. public function onlineUpload()
  179. {
  180. $data = $this->request->postMore([
  181. ['pid', 0],
  182. ['images', []]
  183. ]);
  184. $this->service->onlineUpload($data,4,(int)$this->supplierId);
  185. return app('json')->success('上传完成');
  186. }
  187. /**获取上传信息
  188. * @return \think\Response
  189. * @throws \think\db\exception\DataNotFoundException
  190. * @throws \think\db\exception\DbException
  191. * @throws \think\db\exception\ModelNotFoundException
  192. */
  193. public function getAdminsData()
  194. {
  195. /** @var SystemAdminServices $adminServices */
  196. $adminServices = app()->make(SystemAdminServices::class);
  197. $data['is_way'] = $adminServices->value(['id'=>$this->supplierId], 'is_way');
  198. $data['upload_file_size_max'] = config('upload.filesize');//文件上传大小kb
  199. return app('json')->success($data);
  200. }
  201. /**保存上传信息
  202. * @param int $is_way
  203. * @return \think\Response
  204. */
  205. public function setAdminsData(int $is_way = 0)
  206. {
  207. /** @var SystemAdminServices $adminServices */
  208. $adminServices = app()->make(SystemAdminServices::class);
  209. if(!in_array($is_way,[0,1,2])) return app('json')->fail('参数有误!');
  210. $res = $adminServices->update($this->supplierId, ['is_way' => $is_way]);
  211. if($res) return app('json')->success('ok');
  212. else return app('json')->fail('保存失败');
  213. }
  214. }