AuthController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. //获取权限树 shish 2019.11.24
  9. public function actionTree()
  10. {
  11. $get = Yii::$app->request->get();
  12. $endId = isset($get['endId']) ? $get['endId'] : 1;
  13. $tree = AuthService::getTree($endId);
  14. util::success($tree);
  15. }
  16. //添加权限 shish 2019.11.24
  17. public function actionAdd()
  18. {
  19. $post = Yii::$app->request->post();
  20. $endId = isset($post['endId']) ? $post['endId'] : 1;
  21. $authName = isset($post['authName']) ? $post['authName'] : '';
  22. $list = AuthService::getNameList($endId);
  23. if (in_array($authName, $list)) {
  24. util::fail('名称已经存在');
  25. }
  26. AuthService::add($_POST);
  27. util::ok();
  28. }
  29. //修改 shish 2019.11.24
  30. public function actionUpdate()
  31. {
  32. $post = Yii::$app->request->post();
  33. $id = isset($post['id']) ? $post['id'] : 0;
  34. $auth = AuthService::getById($id);
  35. if (empty($auth)) {
  36. util::fail('没有找到权限');
  37. }
  38. $endId = $auth['endId'];
  39. $nameList = AuthService::getNameList($endId);
  40. $authName = isset($post['authName']) ? $post['authName'] : '';
  41. if ($authName != $auth['authName'] && in_array($authName, $nameList)) {
  42. util::fail('名称已经存在');
  43. }
  44. AuthService::updateById($id, $_POST);
  45. util::ok();
  46. }
  47. }