SystemAuth.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\model;
  16. use think\admin\Model;
  17. /**
  18. * 用户权限模型
  19. * Class SystemAuth
  20. * @package app\admin\model
  21. */
  22. class SystemAuth extends Model
  23. {
  24. /**
  25. * 日志名称
  26. * @var string
  27. */
  28. protected $oplogName = '系统权限';
  29. /**
  30. * 日志类型
  31. * @var string
  32. */
  33. protected $oplogType = '系统权限管理';
  34. /**
  35. * 获取权限数据
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function items(): array
  42. {
  43. return $this->where(['status' => 1])->order('sort desc,id desc')->select()->toArray();
  44. }
  45. /**
  46. * 删除权限事件
  47. * @param string $ids
  48. */
  49. public function onAdminDelete(string $ids)
  50. {
  51. if (count($aids = str2arr($ids ?? '')) > 0) {
  52. SystemNode::mk()->whereIn('auth', $aids)->delete();
  53. }
  54. sysoplog($this->oplogType, "删除{$this->oplogName}[{$ids}]及授权配置");
  55. }
  56. /**
  57. * 格式化创建时间
  58. * @param string $value
  59. * @return string
  60. */
  61. public function getCreateAtAttr(string $value): string
  62. {
  63. return format_datetime($value);
  64. }
  65. }