AdminActionEvent.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Module\Admin\Events;
  3. use Illuminate\Foundation\Events\Dispatchable;
  4. use Illuminate\Queue\SerializesModels;
  5. /**
  6. * 管理员操作事件
  7. */
  8. class AdminActionEvent
  9. {
  10. use Dispatchable, SerializesModels;
  11. /**
  12. * @var array
  13. */
  14. public array $actionData;
  15. /**
  16. * 创建新的事件实例
  17. *
  18. * @param array $actionData
  19. */
  20. public function __construct(array $actionData)
  21. {
  22. $this->actionData = $actionData;
  23. }
  24. /**
  25. * 获取操作数据
  26. *
  27. * @return array
  28. */
  29. public function getActionData(): array
  30. {
  31. return $this->actionData;
  32. }
  33. /**
  34. * 获取管理员ID
  35. *
  36. * @return int|null
  37. */
  38. public function getAdminId(): ?int
  39. {
  40. return $this->actionData['admin_id'] ?? null;
  41. }
  42. /**
  43. * 获取管理员名称
  44. *
  45. * @return string
  46. */
  47. public function getAdminName(): string
  48. {
  49. return $this->actionData['admin_name'] ?? 'Unknown';
  50. }
  51. /**
  52. * 获取操作类型
  53. *
  54. * @return string
  55. */
  56. public function getActionType(): string
  57. {
  58. return $this->actionData['action_type'] ?? '';
  59. }
  60. /**
  61. * 获取操作描述
  62. *
  63. * @return string
  64. */
  65. public function getDescription(): string
  66. {
  67. return $this->actionData['description'] ?? '';
  68. }
  69. /**
  70. * 获取操作数据
  71. *
  72. * @return array
  73. */
  74. public function getData(): array
  75. {
  76. return $this->actionData['data'] ?? [];
  77. }
  78. /**
  79. * 获取IP地址
  80. *
  81. * @return string
  82. */
  83. public function getIpAddress(): string
  84. {
  85. return $this->actionData['ip_address'] ?? '';
  86. }
  87. /**
  88. * 获取用户代理
  89. *
  90. * @return string
  91. */
  92. public function getUserAgent(): string
  93. {
  94. return $this->actionData['user_agent'] ?? '';
  95. }
  96. /**
  97. * 获取时间戳
  98. *
  99. * @return \Carbon\Carbon|null
  100. */
  101. public function getTimestamp(): ?\Carbon\Carbon
  102. {
  103. return $this->actionData['timestamp'] ?? null;
  104. }
  105. }