Access.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\admin\controller\store;
  10. use app\admin\controller\Controller;
  11. use app\admin\model\store\Access as AccesscModel;
  12. /**
  13. * 商家用户权限控制器
  14. * Class StoreUser
  15. * @package app\store\controller
  16. */
  17. class Access extends Controller
  18. {
  19. /**
  20. * 权限列表
  21. * @return mixed
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. */
  27. public function index()
  28. {
  29. $model = new AccesscModel;
  30. $list = $model->getList();
  31. return $this->fetch('index', compact('list'));
  32. }
  33. /**
  34. * 添加权限
  35. * @return array|mixed
  36. * @throws \think\Exception
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @throws \think\exception\DbException
  40. */
  41. public function add()
  42. {
  43. $model = new AccesscModel;
  44. if (!$this->request->isAjax()) {
  45. // 权限列表
  46. $accessList = $model->getList();
  47. return $this->fetch('add', compact('accessList'));
  48. }
  49. // 新增记录
  50. if ($model->add($this->postData('access'))) {
  51. return $this->renderSuccess('添加成功', url('store.access/index'));
  52. }
  53. return $this->renderError($model->getError() ?: '添加失败');
  54. }
  55. /**
  56. * 更新权限
  57. * @param $access_id
  58. * @return array|mixed
  59. * @throws \think\Exception
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. */
  64. public function edit($access_id)
  65. {
  66. // 权限详情
  67. $model = AccesscModel::detail($access_id);
  68. if (!$this->request->isAjax()) {
  69. // 权限列表
  70. $accessList = $model->getList();
  71. return $this->fetch('edit', compact('model', 'accessList'));
  72. }
  73. // 更新记录
  74. if ($model->edit($this->postData('access'))) {
  75. return $this->renderSuccess('更新成功', url('store.access/index'));
  76. }
  77. return $this->renderError($model->getError() ?: '更新失败');
  78. }
  79. /**
  80. * 删除权限
  81. * @param $access_id
  82. * @return array
  83. * @throws \think\exception\DbException
  84. */
  85. public function delete($access_id)
  86. {
  87. // 权限详情
  88. $model = AccesscModel::detail($access_id);
  89. if (!$model->remove()) {
  90. return $this->renderError($model->getError() ?: '删除失败');
  91. }
  92. return $this->renderSuccess('删除成功');
  93. }
  94. }