12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\bug\model;
- class UserRole extends Base
- {
- //设置字段信息
- protected $schema = [
- 'id' =>'int',//
- 'uid' =>'bigint',//用户id
- 'roleid' =>'int',//角色id
- 'status' =>'int',//使用状态
- 'is_del' =>'int',//是否删除
- 'addtime' =>'datetime',//
- 'updatetime' =>'datetime',//
- ];
-
- protected $updateTime='updatetime';
- protected $createTime='addtime';
-
- public function RoleIdByUid($uid,$staus=1){
- return $this->where(["uid"=>$uid,"status"=>$staus,"is_del"=>0])->value("roleid","0");
- }
-
- public function role(){
- return $this->belongsTo(Role::class,"roleid")->where(["status"=>1])->bind(["role_name"]);
- }
-
- public function RoleInfoByUid($uid=[]){
- $list= $this->with(["role"])->where(['uid'=>$uid,'is_del'=>0])->select();
- if($list->isEmpty()) return[];
- $result=[];
- foreach ($list as $item){
- $result[$item->uid] = $item;
- }
- return $result;
- }
- }
|