StatusEnum.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\common\Enum;
  3. /**
  4. * 全局状态枚举
  5. */
  6. class StatusEnum
  7. {
  8. const ENABLED = 1; // 开启
  9. const DISABLED = 0; // 关闭
  10. const YES = 1; // 是
  11. const NO = 0; // 否
  12. public static function getYesNoMap()
  13. {
  14. return [
  15. self::YES => '是',
  16. self::NO => '否',
  17. ];
  18. }
  19. /**
  20. * 获取状态描述
  21. * @param int $status
  22. * @return string
  23. */
  24. public static function getStatusText($status)
  25. {
  26. $map = [
  27. self::ENABLED => '开启',
  28. self::DISABLED => '关闭',
  29. ];
  30. return $map[$status] ?? '未知';
  31. }
  32. /**
  33. * 获取状态映射
  34. * @return array
  35. */
  36. public static function getMap()
  37. {
  38. return [
  39. self::ENABLED => '开启',
  40. self::DISABLED => '关闭',
  41. ];
  42. }
  43. const NORMAL = 'normal'; // 正常
  44. const HIDDEN = 'hidden'; // 隐藏
  45. /**
  46. * 获取状态描述
  47. * @param int $status
  48. * @return string
  49. */
  50. public static function getStrStatusText($status)
  51. {
  52. $map = [
  53. self::NORMAL => '正常',
  54. self::HIDDEN => '隐藏',
  55. ];
  56. return $map[$status] ?? '未知';
  57. }
  58. /**
  59. * 获取状态映射
  60. * @return array
  61. */
  62. public static function getStrMap()
  63. {
  64. return [
  65. self::NORMAL => '正常',
  66. self::HIDDEN => '隐藏',
  67. ];
  68. }
  69. }