AuthController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace saas\controllers;
  3. use biz\auth\services\AuthService;
  4. use common\components\util;
  5. use Yii;
  6. class AuthController extends BaseController
  7. {
  8. public $enableCsrfValidation = false;
  9. //获取权限树 shish 2019.11.24
  10. public function actionTree()
  11. {
  12. $get = Yii::$app->request->get();
  13. $endId = isset($get['endId']) ? $get['endId'] : 1;
  14. $tree = AuthService::getTree($endId);
  15. util::success($tree);
  16. }
  17. //添加权限 shish 2019.11.24
  18. public function actionAdd()
  19. {
  20. $post = Yii::$app->request->post();
  21. $endId = isset($post['endId']) ? $post['endId'] : 1;
  22. $authName = isset($post['authName']) ? $post['authName'] : '';
  23. $list = AuthService::getNameList($endId);
  24. if (in_array($authName, $list)) {
  25. util::fail('名称已经存在');
  26. }
  27. AuthService::add($_POST);
  28. util::ok();
  29. }
  30. //修改 shish 2019.11.24
  31. public function actionModify()
  32. {
  33. $post = Yii::$app->request->post();
  34. $id = isset($post['id']) ? $post['id'] : 0;
  35. $auth = AuthService::getById($id);
  36. if (empty($auth)) {
  37. util::fail('没有找到权限');
  38. }
  39. $endId = $auth['endId'];
  40. $nameList = AuthService::getNameList($endId);
  41. $authName = isset($post['authName']) ? $post['authName'] : '';
  42. if ($authName != $auth['authName'] && in_array($authName, $nameList)) {
  43. util::fail('名称已经存在');
  44. }
  45. AuthService::updateById($id, $_POST);
  46. util::ok();
  47. }
  48. }