SystemAdmin.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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\admin;
  12. use app\model\supplier\SystemSupplier;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\JwtAuthModelTrait;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. /**
  18. * 管理员模型
  19. * Class SystemAdmin
  20. * @package app\model\system\admin
  21. */
  22. class SystemAdmin extends BaseModel
  23. {
  24. use ModelTrait;
  25. use JwtAuthModelTrait;
  26. /**
  27. * 数据表主键
  28. * @var string
  29. */
  30. protected $pk = 'id';
  31. /**
  32. * 模型名称
  33. * @var string
  34. */
  35. protected $name = 'system_admin';
  36. protected $insert = ['add_time'];
  37. /**
  38. * 权限数据
  39. * @param $value
  40. * @return false|string[]
  41. */
  42. public static function getRolesAttr($value)
  43. {
  44. return explode(',', $value);
  45. }
  46. /**
  47. * 供应商
  48. * @return \think\model\relation\HasOne
  49. */
  50. public function supplier()
  51. {
  52. return $this->hasOne(SystemSupplier::class, 'id', 'relation_id')->field(['id', 'supplier_name', 'admin_id', 'avatar', 'is_show'])->bind([
  53. 'supplier_id' => 'id',
  54. 'supplier_name',
  55. 'avatar',
  56. 'is_show'
  57. ]);
  58. }
  59. /**
  60. * 管理员级别搜索器
  61. * @param Model $query
  62. * @param $value
  63. * @param $data
  64. */
  65. public function searchLevelAttr($query, $value)
  66. {
  67. if (is_array($value)) {
  68. $query->where('level', $value[0], $value[1]);
  69. } else {
  70. $query->where('level', $value);
  71. }
  72. }
  73. /**
  74. * 管理员账号和姓名搜索器
  75. * @param Model $query
  76. * @param $value
  77. */
  78. public function searchAccountLikeAttr($query, $value)
  79. {
  80. if ($value) {
  81. $query->whereLike('account|real_name', '%' . $value . '%');
  82. }
  83. }
  84. /**
  85. * 管理员账号搜索器
  86. * @param Model $query
  87. * @param $value
  88. */
  89. public function searchAccountAttr($query, $value)
  90. {
  91. if ($value) {
  92. $query->where('account', $value);
  93. }
  94. }
  95. /**
  96. * 管理员电话搜索器
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchPhoneAttr($query, $value)
  101. {
  102. if ($value != '') {
  103. $query->where('phone', $value);
  104. }
  105. }
  106. /**
  107. * 管理员权限搜索器
  108. * @param Model $query
  109. * @param $roles
  110. */
  111. public function searchRolesAttr($query, $roles)
  112. {
  113. if ($roles) {
  114. $query->where("CONCAT(',',roles,',') LIKE '%,$roles,%'");
  115. }
  116. }
  117. /**
  118. * 是否删除搜索器
  119. * @param Model $query
  120. * @param $value
  121. */
  122. public function searchIsDelAttr($query)
  123. {
  124. $query->where('is_del', 0);
  125. }
  126. /**
  127. * 状态搜索器
  128. * @param Model $query
  129. * @param $value
  130. */
  131. public function searchStatusAttr($query, $value)
  132. {
  133. if ($value != '' && $value != null) {
  134. $query->where('status', $value);
  135. }
  136. }
  137. /**
  138. * 关联ID搜索器
  139. * @param Model $query
  140. * @param $value
  141. */
  142. public function searchRelationIdAttr($query, $value)
  143. {
  144. if ($value != '' && $value != null) {
  145. $query->where('relation_id', $value);
  146. }
  147. }
  148. /**
  149. * 状态搜索器
  150. * @param Model $query
  151. * @param $value
  152. */
  153. public function searchAdminTypeAttr($query, $value)
  154. {
  155. if ($value != '' && $value != null) {
  156. $query->where('admin_type', $value);
  157. }
  158. }
  159. }