AuthController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace pt\controllers;
  3. use bizHd\auth\services\AuthService;
  4. use common\components\util;
  5. use Yii;
  6. class AuthController extends BaseController
  7. {
  8. //获取权限树 ssh 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. //添加权限 ssh 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::complete();
  28. }
  29. //修改 ssh 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::complete();
  46. }
  47. //删除权限 ssh 2020.1.7
  48. public function actionDelete()
  49. {
  50. $id = Yii::$app->request->get('id');
  51. util::complete('删除成功');
  52. }
  53. }