SystemMenus.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 菜单规则模型
  17. * Class SystemMenus
  18. * @package app\model\system
  19. */
  20. class SystemMenus 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_menus';
  33. /**
  34. * 参数修改器
  35. * @param $value
  36. * @return false|string
  37. */
  38. public function setParamsAttr($value)
  39. {
  40. $value = $value ? explode('/', $value) : [];
  41. $params = array_chunk($value, 2);
  42. $data = [];
  43. foreach ($params as $param) {
  44. if (isset($param[0]) && isset($param[1])) $data[$param[0]] = $param[1];
  45. }
  46. return json_encode($data);
  47. }
  48. /**
  49. * 参数获取器
  50. * @param $_value
  51. * @return mixed
  52. */
  53. public function getParamsAttr($_value)
  54. {
  55. return json_decode($_value, true);
  56. }
  57. /**
  58. * pid获取器
  59. * @param $value
  60. * @return mixed|string
  61. */
  62. public function getPidStrAttr($value)
  63. {
  64. return !$value ? '顶级' : $this->where('pid', $value)->value('menu_name');
  65. }
  66. /**
  67. * 默认条件查询器
  68. * @param Model $query
  69. * @param $value
  70. */
  71. public function searchDefaultAttr($query)
  72. {
  73. $query->where(['is_show' => 1, 'access' => 1]);
  74. }
  75. /**
  76. * 是否显示搜索器
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchIsShowAttr($query, $value)
  81. {
  82. if ($value != '') {
  83. $query->where('is_show', $value);
  84. }
  85. }
  86. /**
  87. * 是否删除搜索器
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchIsDelAttr($query, $value)
  92. {
  93. $query->where('is_del', $value);
  94. }
  95. /**
  96. * Pid搜索器
  97. * @param Model $query
  98. * @param $value
  99. */
  100. public function searchPidAttr($query, $value)
  101. {
  102. $query->where('pid', $value ?? 0);
  103. }
  104. /**
  105. * 规格搜索器
  106. * @param Model $query
  107. * @param $value
  108. */
  109. public function searchRuleAttr($query, $value)
  110. {
  111. $query->whereIn('id', $value)->where('is_del', 0)->whereOr('pid', 0);
  112. }
  113. /**
  114. * 搜索菜单
  115. * @param Model $query
  116. * @param $value
  117. */
  118. public function searchKeywordAttr($query, $value)
  119. {
  120. if ($value != '') {
  121. $query->whereLike('menu_name|id|pid', "%$value%");
  122. }
  123. }
  124. /**
  125. * 方法搜索器
  126. * @param Model $query
  127. * @param $value
  128. */
  129. public function searchActionAttr($query, $value)
  130. {
  131. $query->where('action', $value);
  132. }
  133. /**
  134. * 控制器搜索器
  135. * @param Model $query
  136. * @param $value
  137. */
  138. public function searchControllerAttr($query, $value)
  139. {
  140. $query->where('controller', lcfirst($value));
  141. }
  142. /**
  143. * 访问地址搜索器
  144. * @param Model $query
  145. * @param $value
  146. */
  147. public function searchUrlAttr($query, $value)
  148. {
  149. $query->where('api_url', $value);
  150. }
  151. /**
  152. * 参数搜索器
  153. * @param Model $query
  154. * @param $value
  155. */
  156. public function searchParamsAttr($query, $value)
  157. {
  158. $query->where(function ($query) use ($value) {
  159. $query->where('params', $value)->whereOr('params', "'[]'");
  160. });
  161. }
  162. /**
  163. * 权限标识搜索器
  164. * @param Model $query
  165. * @param $value
  166. */
  167. public function searchUniqueAttr($query, $value)
  168. {
  169. $query->where('is_del', 0);
  170. if ($value) {
  171. $query->whereIn('id', $value);
  172. }
  173. }
  174. /**
  175. * 菜单规格搜索
  176. * @param Model $query
  177. * @param $value
  178. */
  179. public function searchRouteAttr($query, $value)
  180. {
  181. $query->where('auth_type', 1)->where('is_del', 0);
  182. if ($value) {
  183. $query->whereIn('id', $value);
  184. }
  185. }
  186. /**
  187. * Id搜索器
  188. * @param Model $query
  189. * @param $value
  190. */
  191. public function searchIdAttr($query, $value)
  192. {
  193. $query->whereIn('id', $value);
  194. }
  195. /**
  196. * is_show_path
  197. * @param Model $query
  198. * @param $value
  199. */
  200. public function searchIsShowPathAttr($query, $value)
  201. {
  202. $query->where('is_show_path', $value);
  203. }
  204. /**
  205. * auth_type
  206. * @param Model $query
  207. * @param $value
  208. */
  209. public function searchAuthTypeAttr($query, $value)
  210. {
  211. if ($value !== '') {
  212. if ($value == 3) {
  213. $query->whereIn('auth_type', [1, 3]);
  214. } else {
  215. $query->where('auth_type', $value);
  216. }
  217. }
  218. }
  219. }