Role.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-24
  7. *
  8. *
  9. */
  10. namespace app\common\model\system\auth;
  11. use app\common\model\BaseModel;
  12. class Role extends BaseModel
  13. {
  14. /**
  15. * @return string
  16. * @author xaboy
  17. * @day 2020-03-30
  18. */
  19. public static function tablePk(): string
  20. {
  21. return 'role_id';
  22. }
  23. /**
  24. * @return string
  25. * @author xaboy
  26. * @day 2020-03-30
  27. */
  28. public static function tableName(): string
  29. {
  30. return 'system_role';
  31. }
  32. public function ruleNames($isArray = false)
  33. {
  34. $menusName = Menu::getDB()->whereIn('menu_id', $this->rules)->column('menu_name');
  35. return $isArray ? $menusName : implode(',', $menusName);
  36. }
  37. /**
  38. * @param $value
  39. * @return array
  40. * @author xaboy
  41. * @day 2020-03-30
  42. */
  43. public function getRulesAttr($value)
  44. {
  45. return array_map('intval', explode(',', $value));
  46. }
  47. /**
  48. * @param $value
  49. * @return string
  50. * @author xaboy
  51. * @day 2020-03-30
  52. */
  53. public function setRulesAttr($value)
  54. {
  55. return implode(',', $value);
  56. }
  57. }