SystemRole.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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;
  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 searchTypeAttr($query, $value)
  48. {
  49. if (is_array($value)) {
  50. if ($value) $query->whereIn('type', $value);
  51. } else {
  52. if ($value !== '') $query->where('type', $value);
  53. }
  54. }
  55. /**
  56. * 关联门店ID、供应商ID搜索器
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchRelationIdAttr($query, $value)
  61. {
  62. if (is_array($value)) {
  63. if ($value) $query->whereIn('relation_id', $value);
  64. } else {
  65. if ($value !== '') $query->where('relation_id', $value);
  66. }
  67. }
  68. /**
  69. * 供应商
  70. * @param Model $query
  71. * @param $value
  72. */
  73. public function searchSupplierIdAttr($query, $value)
  74. {
  75. if (is_array($value)) {
  76. if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
  77. } else {
  78. if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
  79. }
  80. }
  81. /**
  82. * 门店
  83. * @param Model $query
  84. * @param $value
  85. */
  86. public function searchStoreIdAttr($query, $value)
  87. {
  88. if (is_array($value)) {
  89. if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
  90. } else {
  91. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  92. }
  93. }
  94. /**
  95. * 权限规格状态搜索器
  96. * @param Model $query
  97. * @param $value
  98. */
  99. public function searchStatusAttr($query, $value)
  100. {
  101. if ($value != '') {
  102. $query->where('status', $value);
  103. }
  104. }
  105. /**
  106. * 权限等级搜索器
  107. * @param Model $query
  108. * @param $value
  109. */
  110. public function searchLevelAttr($query, $value)
  111. {
  112. $query->where('level', $value);
  113. }
  114. /**
  115. * id搜索器
  116. * @param Model $query
  117. * @param $value
  118. */
  119. public function searchIdAttr($query, $value)
  120. {
  121. if (is_array($value)) {
  122. $query->whereIn('id', $value);
  123. } else {
  124. $query->where('id', $value);
  125. }
  126. }
  127. /**
  128. * 身份管理搜索
  129. * @param Model $query
  130. * @param $value
  131. */
  132. public function searchRoleNameAttr($query, $value)
  133. {
  134. if ($value) {
  135. $query->whereLike('role_name', '%' . $value . '%');
  136. }
  137. }
  138. }