SystemAttachment.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\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. protected $service;
  23. public function __construct(App $app, SystemAttachmentServices $service)
  24. {
  25. parent::__construct($app);
  26. $this->service = $service;
  27. }
  28. /**
  29. * 显示列表
  30. * @return mixed
  31. */
  32. public function index()
  33. {
  34. $where = $this->request->getMore([
  35. ['pid', 0]
  36. ]);
  37. return app('json')->success($this->service->getImageList($where));
  38. }
  39. /**
  40. * 删除指定资源
  41. *
  42. * @param string $ids
  43. * @return \think\Response
  44. */
  45. public function delete()
  46. {
  47. [$ids] = $this->request->postMore([
  48. ['ids', '']
  49. ], true);
  50. $this->service->del($ids);
  51. return app('json')->success('删除成功');
  52. }
  53. /**
  54. * 图片上传
  55. * @param int $upload_type
  56. * @param int $type
  57. * @return mixed
  58. */
  59. public function upload($upload_type = 0, $type = 0)
  60. {
  61. [$pid, $file, $menuName] = $this->request->postMore([
  62. ['pid', 0],
  63. ['file', 'file'],
  64. ['menu_name', '']
  65. ], true);
  66. $res = $this->service->upload((int)$pid, $file, $upload_type, $type, $menuName);
  67. return app('json')->success('上传成功', ['src' => $res]);
  68. }
  69. /**
  70. * 移动图片
  71. * @return mixed
  72. */
  73. public function moveImageCate()
  74. {
  75. $data = $this->request->postMore([
  76. ['pid', 0],
  77. ['images', '']
  78. ]);
  79. $this->service->move($data);
  80. return app('json')->success('移动成功');
  81. }
  82. /**
  83. * 修改文件名
  84. * @param $id
  85. * @return mixed
  86. */
  87. public function update($id)
  88. {
  89. $realName = $this->request->post('real_name', '');
  90. if (!$realName) {
  91. return app('json')->fail('文件名称不能为空');
  92. }
  93. $this->service->update($id, ['real_name' => $realName]);
  94. return app('json')->success('修改成功');
  95. }
  96. /**
  97. * 获取上传类型
  98. * @return mixed
  99. */
  100. public function uploadType()
  101. {
  102. $data['upload_type'] = sys_config('upload_type', 1);
  103. return app('json')->success($data);
  104. }
  105. }