Store.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\admin\controller;
  13. use think\response\Json;
  14. use app\admin\model\Store as StoreModel;
  15. /**
  16. * 商城管理
  17. * Class Store
  18. * @package app\admin\controller
  19. */
  20. class Store extends Controller
  21. {
  22. /**
  23. * 强制验证当前访问的控制器方法method
  24. * @var array
  25. */
  26. protected array $methodRules = [
  27. 'index' => 'GET',
  28. 'recycle' => 'GET',
  29. 'add' => 'POST',
  30. 'move' => 'POST',
  31. 'delete' => 'POST',
  32. ];
  33. /**
  34. * 商城列表
  35. * @return Json
  36. * @throws \think\db\exception\DbException
  37. */
  38. public function index(): Json
  39. {
  40. // 商城列表
  41. $model = new StoreModel;
  42. $list = $model->getList();
  43. return $this->renderSuccess(compact('list'));
  44. }
  45. /**
  46. * 新增商城
  47. * @return Json
  48. */
  49. public function add(): Json
  50. {
  51. return $this->renderError('很抱歉,免费版暂不支持多开商城');
  52. }
  53. /**
  54. * 回收站列表
  55. * @return Json
  56. * @throws \think\db\exception\DbException
  57. */
  58. public function recycle(): Json
  59. {
  60. // 商城列表
  61. $model = new StoreModel;
  62. $list = $model->getList(true);
  63. return $this->renderSuccess(compact('list'));
  64. }
  65. /**
  66. * 移入回收站
  67. * @param int $storeId
  68. * @return Json
  69. */
  70. public function recovery(int $storeId): Json
  71. {
  72. // 商城详情
  73. $model = StoreModel::detail($storeId);
  74. if (!$model->recycle()) {
  75. return $this->renderError($model->getError() ?: '操作失败');
  76. }
  77. return $this->renderSuccess('操作成功');
  78. }
  79. /**
  80. * 移出回收站
  81. * @param int $storeId
  82. * @return Json
  83. */
  84. public function move(int $storeId): Json
  85. {
  86. // 商城详情
  87. $model = StoreModel::detail($storeId);
  88. if (!$model->recycle(false)) {
  89. return $this->renderError($model->getError() ?: '操作失败');
  90. }
  91. return $this->renderSuccess('操作成功');
  92. }
  93. }