SystemAuth.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/02
  5. */
  6. namespace app\models\system;
  7. use crmeb\services\UtilService as Util;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. use think\facade\Route as Url;
  11. /**
  12. * 菜单 model
  13. * Class SystemMenus
  14. * @package app\models\system
  15. */
  16. class SystemAuth extends BaseModel
  17. {
  18. /**
  19. * 数据表主键
  20. * @var string
  21. */
  22. protected $pk = 'id';
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'system_auth';
  28. use ModelTrait;
  29. public static $isShowStatus = [1 => '显示', 0 => '不显示'];
  30. public static $accessStatus = [1 => '管理员可用', 0 => '管理员不可用'];
  31. public static function legalWhere($where = [])
  32. {
  33. $where['is_show'] = 1;
  34. }
  35. public function setParamsAttr($value)
  36. {
  37. $value = $value ? explode('/', $value) : [];
  38. $params = array_chunk($value, 2);
  39. $data = [];
  40. foreach ($params as $param) {
  41. if (isset($param[0]) && isset($param[1])) $data[$param[0]] = $param[1];
  42. }
  43. return json_encode($data);
  44. }
  45. protected function setControllerAttr($value)
  46. {
  47. return lcfirst($value);
  48. }
  49. /**
  50. * @param $id
  51. * @return bool
  52. */
  53. public static function delMenu($id)
  54. {
  55. if (self::where('pid', $id)->where(['is_del' => 0])->count())
  56. return self::setErrorInfo('请先删除改菜单下的子菜单!');
  57. return self::where('id', $id)->update(['is_del' => 1]);
  58. }
  59. /**
  60. * @param $params
  61. * @return array
  62. */
  63. public static function getAuthList($params)
  64. {
  65. $model = new self;
  66. if ($params['is_show'] !== '') $model = $model->where('is_show', $params['is_show']);
  67. if ($params['pid'] !== '' && !$params['keyword']) $model = $model->where('pid', $params['pid']);
  68. if ($params['keyword'] !== '') $model = $model->where('menu_name|id|pid', 'LIKE', "%$params[keyword]%");
  69. $model = $model->where('is_del', 0);
  70. $list = $model->order('sort DESC,id ASC')->select();
  71. return get_tree_children($list->toArray());
  72. }
  73. /**
  74. * @param $params
  75. * @return string
  76. */
  77. public static function paramStr($params)
  78. {
  79. if (!is_array($params)) $params = json_decode($params, true) ?: [];
  80. $p = [];
  81. foreach ($params as $key => $param) {
  82. $p[] = $key;
  83. $p[] = $param;
  84. }
  85. return implode('/', $p);
  86. }
  87. }