SystemAttachment.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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] = $this->request->postMore([
  62. ['pid', 0],
  63. ['file', 'file'],
  64. ], true);
  65. $res = $this->service->upload((int)$pid, $file, $upload_type, $type);
  66. return app('json')->success('上传成功', ['src' => $res]);
  67. }
  68. /**
  69. * 移动图片
  70. * @return mixed
  71. */
  72. public function moveImageCate()
  73. {
  74. $data = $this->request->postMore([
  75. ['pid', 0],
  76. ['images', '']
  77. ]);
  78. $this->service->move($data);
  79. return app('json')->success('移动成功');
  80. }
  81. /**
  82. * 修改文件名
  83. * @param $id
  84. * @return mixed
  85. */
  86. public function update($id)
  87. {
  88. $realName = $this->request->post('real_name', '');
  89. if (!$realName) {
  90. return app('json')->fail('文件名称不能为空');
  91. }
  92. $this->service->update($id, ['real_name' => $realName]);
  93. return app('json')->success('修改成功');
  94. }
  95. }