Grade.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\user;
  10. use app\store\controller\Controller;
  11. use app\store\model\user\Grade as GradeModel;
  12. /**
  13. * 会员等级
  14. * Class Grade
  15. * @package app\store\controller\user
  16. */
  17. class Grade extends Controller
  18. {
  19. /**
  20. * 会员等级列表
  21. * @return mixed
  22. * @throws \think\exception\DbException
  23. */
  24. public function index()
  25. {
  26. $model = new GradeModel;
  27. $list = $model->getList();
  28. return $this->fetch('index', compact('list'));
  29. }
  30. /**
  31. * 添加等级
  32. * @return array|bool|mixed
  33. * @throws \Exception
  34. */
  35. public function add()
  36. {
  37. $model = new GradeModel;
  38. if (!$this->request->isAjax()) {
  39. return $this->fetch('add');
  40. }
  41. // 新增记录
  42. if ($model->add($this->postData('grade'))) {
  43. return $this->renderSuccess('添加成功', url('user.grade/index'));
  44. }
  45. return $this->renderError($model->getError() ?: '添加失败');
  46. }
  47. /**
  48. * 编辑会员等级
  49. * @param $grade_id
  50. * @return array|bool|mixed
  51. * @throws \think\exception\DbException
  52. */
  53. public function edit($grade_id)
  54. {
  55. // 会员等级详情
  56. $model = GradeModel::detail($grade_id);
  57. if (!$this->request->isAjax()) {
  58. return $this->fetch('edit', compact('model'));
  59. }
  60. // 新增记录
  61. if ($model->edit($this->postData('grade'))) {
  62. return $this->renderSuccess('更新成功', url('user.grade/index'));
  63. }
  64. return $this->renderError($model->getError() ?: '更新失败');
  65. }
  66. /**
  67. * 删除会员等级
  68. * @param $grade_id
  69. * @return array
  70. * @throws \think\exception\DbException
  71. */
  72. public function delete($grade_id)
  73. {
  74. // 会员等级详情
  75. $model = GradeModel::detail($grade_id);
  76. if (!$model->setDelete()) {
  77. return $this->renderError($model->getError() ?: '删除失败');
  78. }
  79. return $this->renderSuccess('删除成功');
  80. }
  81. }