123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\model\system;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Model;
- /**
- * 菜单规则模型
- * Class SystemMenus
- * @package app\model\system
- */
- class SystemMenus extends BaseModel
- {
- use ModelTrait;
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'system_menus';
- /**
- * 参数修改器
- * @param $value
- * @return false|string
- */
- public function setParamsAttr($value)
- {
- $value = $value ? explode('/', $value) : [];
- $params = array_chunk($value, 2);
- $data = [];
- foreach ($params as $param) {
- if (isset($param[0]) && isset($param[1])) $data[$param[0]] = $param[1];
- }
- return json_encode($data);
- }
- /**
- * 参数获取器
- * @param $_value
- * @return mixed
- */
- public function getParamsAttr($_value)
- {
- return is_string($_value) ? json_decode($_value, true) : $_value;
- }
- /**
- * pid获取器
- * @param $value
- * @return mixed|string
- */
- public function getPidAttr($value)
- {
- return !$value ? '顶级' : $this->where('pid', $value)->value('menu_name');
- }
- /**
- * 默认条件查询器
- * @param Model $query
- * @param $value
- */
- public function searchDefaultAttr($query)
- {
- $query->where(['is_show' => 1, 'access' => 1]);
- }
- /**
- * 是否显示搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIsShowAttr($query, $value)
- {
- if ($value != '') {
- $query->where('is_show', $value);
- }
- }
- /**
- * 是否删除搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIsDelAttr($query, $value)
- {
- $query->where('is_del', $value);
- }
- /**
- * Pid搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPidAttr($query, $value)
- {
- $query->where('pid', $value ?? 0);
- }
- /**
- * type搜索器
- * @param Model $query
- * @param $value
- */
- public function searchTypeAttr($query, $value)
- {
- if ($value) $query->where('type', $value);
- }
- /**
- * 规格搜索器
- * @param Model $query
- * @param $value
- */
- public function searchRuleAttr($query, $value)
- {
- $query->whereIn('id', $value)->where('is_del', 0)->whereOr('pid', 0);
- }
- /**
- * 搜索菜单
- * @param Model $query
- * @param $value
- */
- public function searchKeywordAttr($query, $value)
- {
- if ($value != '') {
- $query->whereLike('menu_name|menu_path|unique_auth|api_url|id|pid', "%$value%");
- }
- }
- /**
- * 方法搜索器
- * @param Model $query
- * @param $value
- */
- public function searchActionAttr($query, $value)
- {
- $query->where('action', $value);
- }
- /**
- * 控制器搜索器
- * @param Model $query
- * @param $value
- */
- public function searchControllerAttr($query, $value)
- {
- $query->where('controller', lcfirst($value));
- }
- /**
- * 访问地址搜索器
- * @param Model $query
- * @param $value
- */
- public function searchUrlAttr($query, $value)
- {
- $query->where('api_url', $value);
- }
- /**
- * 参数搜索器
- * @param Model $query
- * @param $value
- */
- public function searchParamsAttr($query, $value)
- {
- $query->where(function ($query) use ($value) {
- $query->where('params', $value)->whereOr('params', "'[]'");
- });
- }
- /**
- * 权限标识搜索器
- * @param Model $query
- * @param $value
- */
- public function searchUniqueAttr($query, $value)
- {
- $query->where('is_del', 0);
- if ($value) {
- $query->whereIn('id', $value);
- }
- }
- /**
- * 菜单规格搜索
- * @param Model $query
- * @param $value
- */
- public function searchRouteAttr($query, $value)
- {
- $query->where('auth_type', 1)->where('is_show', 1)->where('is_del', 0);
- if ($value) {
- $query->whereIn('id', $value);
- }
- }
- /**
- * Id搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIdAttr($query, $value)
- {
- $query->whereIn('id', $value);
- }
- /**
- * is_show_path
- * @param Model $query
- * @param $value
- */
- public function searchIsShowPathAttr($query, $value)
- {
- $query->where('is_show_path', $value);
- }
- /**
- * auth_type
- * @param Model $query
- * @param $value
- */
- public function searchAuthTypeAttr($query, $value)
- {
- $query->where('auth_type', $value);
- }
- }
|