UserRole.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\bug\model;
  3. class UserRole extends Base
  4. {
  5. //设置字段信息
  6. protected $schema = [
  7. 'id' =>'int',//
  8. 'uid' =>'bigint',//用户id
  9. 'roleid' =>'int',//角色id
  10. 'status' =>'int',//使用状态
  11. 'is_del' =>'int',//是否删除
  12. 'addtime' =>'datetime',//
  13. 'updatetime' =>'datetime',//
  14. ];
  15. protected $updateTime='updatetime';
  16. protected $createTime='addtime';
  17. public function RoleIdByUid($uid,$staus=1){
  18. return $this->where(["uid"=>$uid,"status"=>$staus,"is_del"=>0])->value("roleid","0");
  19. }
  20. public function role(){
  21. return $this->belongsTo(Role::class,"roleid")->where(["status"=>1])->bind(["role_name"]);
  22. }
  23. public function RoleInfoByUid($uid=[]){
  24. $list= $this->with(["role"])->where(['uid'=>$uid,'is_del'=>0])->select();
  25. if($list->isEmpty()) return[];
  26. $result=[];
  27. foreach ($list as $item){
  28. $result[$item->uid] = $item;
  29. }
  30. return $result;
  31. }
  32. }