RoleRule.php 742 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. use think\Db;
  5. use think\Validate;
  6. use think\Request;
  7. /**
  8. * 角色-权限管理
  9. * @author Superbee
  10. *
  11. */
  12. class RoleRule extends Model{
  13. /**
  14. * 添加和更新的方法
  15. */
  16. public function addAndSave(){
  17. $data = request()->post();
  18. $aid = $data['id'];
  19. $this->db()->where(['aid'=>$data['id']])->delete();
  20. foreach ($data['rid'] as $v){
  21. $data = ['id'=>'', 'aid'=>$aid, 'rid'=>$v];
  22. $this->isUpdate(false)->save($data);
  23. }
  24. }
  25. /**
  26. * 根据id找到规则
  27. * @param unknown $aid
  28. */
  29. public function getRidByAid($aid){
  30. $array = [];
  31. $res = $this->db()->where(['aid'=>$aid])->select();
  32. foreach ($res as $v){
  33. $array[] = $v['rid'];
  34. }
  35. return $array;
  36. }
  37. }