Role.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\store;
  13. use app\store\controller\Controller;
  14. use app\store\model\store\Role as RoleModel;
  15. /**
  16. * 商家用户角色控制器
  17. * Class StoreUser
  18. * @package app\store\controller
  19. */
  20. class Role extends Controller
  21. {
  22. /**
  23. * 角色列表
  24. * @return array
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function list()
  30. {
  31. $model = new RoleModel;
  32. $list = $model->getList();
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 添加角色
  37. * @return array
  38. */
  39. public function add()
  40. {
  41. // 新增记录
  42. $model = new RoleModel;
  43. if ($model->add($this->postForm())) {
  44. return $this->renderSuccess('添加成功');
  45. }
  46. return $this->renderError($model->getError() ?: '添加失败');
  47. }
  48. /**
  49. * 更新角色
  50. * @param $roleId
  51. * @return array|bool|string
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function edit(int $roleId)
  57. {
  58. // 角色详情
  59. $model = RoleModel::detail($roleId);
  60. // 更新记录
  61. if ($model->edit($this->postForm())) {
  62. return $this->renderSuccess('更新成功');
  63. }
  64. return $this->renderError($model->getError() ?: '更新失败');
  65. }
  66. /**
  67. * 删除角色
  68. * @param $roleId
  69. * @return array|bool
  70. * @throws \Exception
  71. */
  72. public function delete(int $roleId)
  73. {
  74. // 角色详情
  75. $model = RoleModel::detail($roleId);
  76. if (!$model->remove()) {
  77. return $this->renderError($model->getError() ?: '删除失败');
  78. }
  79. return $this->renderSuccess('删除成功');
  80. }
  81. }