UserRole.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\cxinv\model;
  3. class UserRole extends Base
  4. {
  5. //设置字段信息
  6. protected $schema = [
  7. 'id' =>'bigint',//
  8. 'uid' =>'int',//
  9. 'nickname' =>'varchar',//账户名称
  10. 'roleid' =>'int',//角色id
  11. 'companyNo' =>'varchar',//关联企业编号
  12. 'company_type' =>'tinyint',//业务公司类型1业务公司 2供应商 0 无关联
  13. 'status' =>'tinyint',//状态 0禁用 1可用
  14. 'is_main' =>'tinyint',//是否默认角色
  15. 'is_del' =>'tinyint',//是否删除
  16. 'addtime' =>'datetime',//新建时间
  17. 'updatetime' =>'datetime',//更新时间
  18. ];
  19. protected $updateTime='updatetime';
  20. protected $createTime='addtime';
  21. public static function GetRoleIdByCompnyNoAndUid($companyNo,$uid){
  22. return self::where([
  23. 'uid' => $uid,
  24. 'companyNo' => $companyNo,
  25. 'is_del' => 0])
  26. ->value('role_id','');
  27. }
  28. public function RoleInfo(){
  29. return $this->belongsTo(RoleAction::class,'roleid','role_id')->bind(['action_conllect']);
  30. }
  31. public static function getAllAction($uid=0,$companyNo='',$level=0){
  32. switch ($level){
  33. case 1:
  34. $action = Action::where(['is_del' => 0, 'status' => 1]) ->column('id');
  35. break;
  36. case 2:
  37. $role = self::where([
  38. 'uid' => $uid,
  39. 'companyNo' => $companyNo,
  40. 'is_del' => 0])->with('RoleInfo')
  41. ->findOrEmpty();
  42. $action = $role->action_conllect??[];
  43. break;
  44. case 3:
  45. $role = self::where([
  46. 'uid' => $uid,
  47. 'is_del' => 0])->with('RoleInfo')
  48. ->findOrEmpty();
  49. $action = $role->action_conllect??[];
  50. break;
  51. default:
  52. $action = [];
  53. }
  54. return $action;
  55. }
  56. }