UserRole.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class UserRole extends Model
  9. {
  10. protected $updateTime='updatetime';
  11. protected $createTime='addtime';
  12. public static function GetRoleIdByCompnyNoAndUid($companyNo,$uid){
  13. return self::where([
  14. 'uid' => $uid,
  15. 'companyNo' => $companyNo,
  16. 'status' => 1,
  17. 'is_del' => 0])
  18. ->value('roleid','');
  19. }
  20. public function RoleInfo(){
  21. return $this->belongsTo(RoleAction::class,"roleid","role_id")->bind(['action_conllect']);
  22. }
  23. public static function getAllAction($uid=0,$companyNo='',$level=0){
  24. switch ($level){
  25. case 1:
  26. $action = Action::where(['is_del' => 0, 'status' => 1]) ->column('id');
  27. break;
  28. case 2:
  29. $role = self::where([
  30. 'uid' => $uid,
  31. 'companyNo' => $companyNo,
  32. 'is_del' => 0])->with('RoleInfo')
  33. ->findOrEmpty();
  34. $action = $role->action_conllect??[];
  35. break;
  36. case 3:
  37. $role = self::where([
  38. 'uid' => $uid,
  39. 'is_del' => 0])->with('RoleInfo')
  40. ->findOrEmpty();
  41. $action = $role->action_conllect??[];
  42. break;
  43. default:
  44. $action = [];
  45. }
  46. return $action;
  47. }
  48. }