Grade.php 2.0 KB

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