SystemRole.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\system\admin;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 管理员权限规则
  17. * Class SystemRole
  18. * @package app\model\system\admin
  19. */
  20. class SystemRole extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'system_role';
  33. /**
  34. * 规则修改器
  35. * @param Model $value
  36. * @return string
  37. */
  38. public static function setRulesAttr($value)
  39. {
  40. return is_array($value) ? implode(',', $value) : $value;
  41. }
  42. /**
  43. * 权限规格状态搜索器
  44. * @param Model $query
  45. * @param $value
  46. */
  47. public function searchStatusAttr($query, $value)
  48. {
  49. if ($value !== '') {
  50. $query->where('status', $value);
  51. }
  52. }
  53. /**
  54. * 权限等级搜索器
  55. * @param Model $query
  56. * @param $value
  57. */
  58. public function searchLevelAttr($query, $value)
  59. {
  60. $query->where('level', $value);
  61. }
  62. /**
  63. * id搜索器
  64. * @param Model $query
  65. * @param $value
  66. */
  67. public function searchIdAttr($query, $value)
  68. {
  69. if (is_array($value)) {
  70. $query->whereIn('id', $value);
  71. } else {
  72. $query->where('id', $value);
  73. }
  74. }
  75. /**
  76. * 身份管理搜索
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchRoleNameAttr($query, $value)
  81. {
  82. if ($value) {
  83. $query->whereLike('role_name', '%' . $value . '%');
  84. }
  85. }
  86. }