AdminRole.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class AdminRole extends BaseModel
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. private $roleData;
  16. private $sassId = 0;
  17. public function setSassId($sassid) {
  18. $this->sassId = $sassid;
  19. }
  20. /**
  21. * @param $post
  22. */
  23. public function saveRole($post) {
  24. $save['name'] = $post['name'];
  25. $save['status'] = $post['status'];
  26. if($post['id']) {
  27. $info = $this->where("name",$post['name'])->find();
  28. if(!empty($info) && $info['id'] != $post['id'] ) {
  29. return self::setErrorInfo('角色名重复了');
  30. }
  31. $this->where('id',$post['id'])->save($save);
  32. return true;
  33. } else {
  34. $this->insert([
  35. 'name' => $post['name'],
  36. 'status' => $post['status']
  37. ]);
  38. }
  39. return true;
  40. }
  41. /**
  42. * 获取角色数据
  43. * @param $id
  44. * @param string $field
  45. * @return mixed
  46. */
  47. public function getRoleId($id,$field = '*') {
  48. $this->getRoleData();
  49. foreach ($this->roleData as $v) {
  50. if($v['id'] == $id) {
  51. return $field == '*' ? $v : $v[$field];
  52. }
  53. }
  54. }
  55. public function getRoleData(){
  56. if(empty($this->roleData))
  57. $this->roleData = $this->where('status',1)->select();
  58. return $this->roleData;
  59. }
  60. }