Grade.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\store\controller\user;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\user\Grade as GradeModel;
  16. /**
  17. * 会员等级
  18. * Class Grade
  19. * @package app\store\controller\user
  20. */
  21. class Grade extends Controller
  22. {
  23. /**
  24. * 列表记录
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. $model = new GradeModel;
  31. $list = $model->getList($this->request->param());
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 全部记录
  36. * @return Json
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function all(): Json
  42. {
  43. $model = new GradeModel;
  44. $list = $model->getAll($this->request->param());
  45. return $this->renderSuccess(compact('list'));
  46. }
  47. /**
  48. * 添加等级
  49. * @return Json
  50. */
  51. public function add(): Json
  52. {
  53. // 新增记录
  54. $model = new GradeModel;
  55. if ($model->add($this->postForm())) {
  56. return $this->renderSuccess('添加成功');
  57. }
  58. return $this->renderError($model->getError() ?: '添加失败');
  59. }
  60. /**
  61. * 编辑会员等级
  62. * @param int $gradeId
  63. * @return Json
  64. */
  65. public function edit(int $gradeId): Json
  66. {
  67. // 会员等级详情
  68. $model = GradeModel::detail($gradeId);
  69. // 更新记录
  70. if ($model->edit($this->postForm())) {
  71. return $this->renderSuccess('更新成功');
  72. }
  73. return $this->renderError($model->getError() ?: '更新失败');
  74. }
  75. /**
  76. * 删除会员等级
  77. * @param int $gradeId
  78. * @return Json
  79. */
  80. public function delete(int $gradeId): Json
  81. {
  82. // 会员等级详情
  83. $model = GradeModel::detail($gradeId);
  84. if (!$model->setDelete()) {
  85. return $this->renderError($model->getError() ?: '删除失败');
  86. }
  87. return $this->renderSuccess('删除成功');
  88. }
  89. }