SystemAdmin.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\JwtAuthModelTrait;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 管理员模型
  18. * Class SystemAdmin
  19. * @package app\model\system\admin
  20. */
  21. class SystemAdmin extends BaseModel
  22. {
  23. use ModelTrait;
  24. use JwtAuthModelTrait;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'system_admin';
  35. protected $insert = ['add_time'];
  36. /**
  37. * 权限数据
  38. * @param $value
  39. * @return false|string[]
  40. */
  41. public static function getRolesAttr($value)
  42. {
  43. return explode(',', $value);
  44. }
  45. /**
  46. * 管理员级别搜索器
  47. * @param Model $query
  48. * @param $value
  49. * @param $data
  50. */
  51. public function searchLevelAttr($query, $value)
  52. {
  53. if (is_array($value)) {
  54. $query->where('level', $value[0], $value[1]);
  55. } else {
  56. $query->where('level', $value);
  57. }
  58. }
  59. /**
  60. * 管理员账号和姓名搜索器
  61. * @param Model $query
  62. * @param $value
  63. */
  64. public function searchAccountLikeAttr($query, $value)
  65. {
  66. if ($value) {
  67. $query->whereLike('account|real_name', '%' . $value . '%');
  68. }
  69. }
  70. /**
  71. * 管理员账号搜索器
  72. * @param Model $query
  73. * @param $value
  74. */
  75. public function searchAccountAttr($query, $value)
  76. {
  77. if ($value) {
  78. $query->where('account', $value);
  79. }
  80. }
  81. /**
  82. * 管理员权限搜索器
  83. * @param Model $query
  84. * @param $roles
  85. */
  86. public function searchRolesAttr($query, $roles)
  87. {
  88. if ($roles) {
  89. $query->where("CONCAT(',',roles,',') LIKE '%,$roles,%'");
  90. }
  91. }
  92. /**
  93. * 是否删除搜索器
  94. * @param Model $query
  95. * @param $value
  96. */
  97. public function searchIsDelAttr($query)
  98. {
  99. $query->where('is_del', 0);
  100. }
  101. /**
  102. * 状态搜索器
  103. * @param Model $query
  104. * @param $value
  105. */
  106. public function searchStatusAttr($query, $value)
  107. {
  108. if ($value != '' && $value != null) {
  109. $query->where('status', $value);
  110. }
  111. }
  112. }