File.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\supplier\controller\file;
  3. use app\supplier\controller\Controller;
  4. use app\shop\model\file\UploadFile as UploadFileModel;
  5. use app\common\model\file\UploadGroup as UploadGroupModel;
  6. class File extends Controller
  7. {
  8. /**
  9. * 文件库列表
  10. */
  11. public function lists($pageSize, $type = 'image', $group_id = -1)
  12. {
  13. // 文件列表
  14. $file_list = (new UploadFileModel)->getlist(intval($group_id), $type, $pageSize, -1, $this->getSupplierId());
  15. return $this->renderSuccess('success', compact('file_list'));
  16. }
  17. /**
  18. * 类别列表
  19. */
  20. public function category($type = 'image')
  21. {
  22. // 分组列表
  23. $group_list = (new UploadGroupModel)->getList($type, $this->getSupplierId());
  24. return $this->renderSuccess('success', compact('group_list'));
  25. }
  26. /**
  27. * 新增分组
  28. */
  29. public function addGroup($group_name, $group_type = 'image')
  30. {
  31. $model = new UploadGroupModel;
  32. $shop_supplier_id = $this->getSupplierId();
  33. if ($model->add(compact('group_name', 'group_type', 'shop_supplier_id'))) {
  34. $group_id = $model->getLastInsID();
  35. return $this->renderSuccess('添加成功', compact('group_id', 'group_name'));
  36. }
  37. return $this->renderError($model->getError() ?: '添加失败');
  38. }
  39. /**
  40. * 编辑分组
  41. */
  42. public function editGroup($group_id, $group_name)
  43. {
  44. $model = UploadGroupModel::detail($group_id, $this->getSupplierId());
  45. if ($model->edit(compact('group_name'))) {
  46. return $this->renderSuccess('修改成功');
  47. }
  48. return $this->renderError($model->getError() ?: '修改失败');
  49. }
  50. /**
  51. * 删除分组
  52. */
  53. public function deleteGroup($group_id)
  54. {
  55. $model = UploadGroupModel::detail($group_id, $this->getSupplierId());
  56. if ($model->remove()) {
  57. return $this->renderSuccess('删除成功');
  58. }
  59. return $this->renderError($model->getError() ?: '删除失败');
  60. }
  61. /**
  62. * 批量删除文件
  63. */
  64. public function deleteFiles($fileIds)
  65. {
  66. $model = new UploadFileModel;
  67. if ($model->softDelete($fileIds)) {
  68. return $this->renderSuccess('删除成功');
  69. }
  70. return $this->renderError($model->getError() ?: '删除失败');
  71. }
  72. /**
  73. * 批量移动文件分组
  74. */
  75. public function moveFiles($group_id, $fileIds)
  76. {
  77. $model = new UploadFileModel;
  78. if ($model->moveGroup($group_id, $fileIds) !== false) {
  79. return $this->renderSuccess('移动成功');
  80. }
  81. return $this->renderError($model->getError() ?: '移动失败');
  82. }
  83. }