Access.php 2.6 KB

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