ZeroUserRequestEntity.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\entity\admin\request\user;
  3. use app\entity\request\RequestCommonEntity;
  4. /**
  5. * 添加0号线用户请求参数
  6. */
  7. class ZeroUserRequestEntity extends RequestCommonEntity
  8. {
  9. // id
  10. public $id;
  11. // 万能验证码
  12. public $customCode;
  13. // 状态
  14. public $status;
  15. // 团队昵称
  16. public $teamName;
  17. // 团队长uid
  18. public $teamUid;
  19. // 是否移除团队
  20. public $isRemove;
  21. // 获取id
  22. public function getId()
  23. {
  24. return $this->id;
  25. }
  26. // 设置id
  27. public function setId($id)
  28. {
  29. $this->id = $id;
  30. return $this;
  31. }
  32. // 获取万能验证码
  33. public function getCustomCode()
  34. {
  35. return $this->customCode;
  36. }
  37. // 设置万能验证码
  38. public function setCustomCode($customCode)
  39. {
  40. $this->customCode = $customCode ?? null;
  41. return $this;
  42. }
  43. // 获取团队昵称
  44. public function getStatus()
  45. {
  46. return $this->status;
  47. }
  48. public function setStatus($status)
  49. {
  50. $this->status = $status;
  51. return $this;
  52. }
  53. // 获取团队昵称
  54. public function getTeamName()
  55. {
  56. return $this->teamName ?? '';
  57. }
  58. public function setTeamName($teamName): ZeroUserRequestEntity
  59. {
  60. $this->teamName = $teamName;
  61. return $this;
  62. }
  63. // 获取团队长uid
  64. public function getTeamUid()
  65. {
  66. return $this->teamUid;
  67. }
  68. public function setTeamUid($teamUid): ZeroUserRequestEntity
  69. {
  70. $this->teamUid = $teamUid;
  71. return $this;
  72. }
  73. // 获取是否移除
  74. public function getIsRemove()
  75. {
  76. return $this->isRemove;
  77. }
  78. public function setIsRemove($isRemove): ZeroUserRequestEntity
  79. {
  80. $this->isRemove = $isRemove;
  81. return $this;
  82. }
  83. /**
  84. * 将请求参数转换为数组格式
  85. * 用于数据库操作或API传输
  86. * 动态获取当前类的所有公共属性,使用下划线分割的键名
  87. *
  88. * @return array
  89. */
  90. public function getArray(): array
  91. {
  92. $result = [];
  93. $reflection = new \ReflectionClass($this);
  94. $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
  95. foreach ($properties as $property) {
  96. $propertyName = $property->getName();
  97. // 跳过继承的属性
  98. if ($property->getDeclaringClass()->getName() !== self::class) {
  99. continue;
  100. }
  101. // 将驼峰命名转换为下划线命名
  102. $key = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $propertyName));
  103. // 获取对应的getter方法名
  104. $getterMethod = 'get' . ucfirst($propertyName);
  105. if (method_exists($this, $getterMethod)) {
  106. $result[$key] = $this->$getterMethod();
  107. } else {
  108. // 如果没有对应的getter方法,直接获取属性值
  109. $result[$key] = $this->$propertyName;
  110. }
  111. }
  112. return $result;
  113. }
  114. }