Grade.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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 app\store\controller\Controller;
  14. use app\store\model\user\Grade as GradeModel;
  15. /**
  16. * 会员等级
  17. * Class Grade
  18. * @package app\store\controller\user
  19. */
  20. class Grade extends Controller
  21. {
  22. /**
  23. * 列表记录
  24. * @return array
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function list()
  28. {
  29. $model = new GradeModel;
  30. $list = $model->getList($this->request->param());
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 全部记录
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function all()
  41. {
  42. $model = new GradeModel;
  43. $list = $model->getAll($this->request->param());
  44. return $this->renderSuccess(compact('list'));
  45. }
  46. /**
  47. * 添加等级
  48. * @return array|bool|mixed
  49. * @throws \Exception
  50. */
  51. public function add()
  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 array|bool|mixed
  64. */
  65. public function edit(int $gradeId)
  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 array
  79. */
  80. public function delete(int $gradeId)
  81. {
  82. // 会员等级详情
  83. $model = GradeModel::detail($gradeId);
  84. if (!$model->setDelete()) {
  85. return $this->renderError($model->getError() ?: '删除失败');
  86. }
  87. return $this->renderSuccess('删除成功');
  88. }
  89. }