CommentEnum.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace app\common\Enum;
  3. class CommentEnum
  4. {
  5. /**
  6. * 评价状态
  7. */
  8. const EVALUATE_STATUS_PENDING = 1; // 审核中
  9. const EVALUATE_STATUS_APPROVED = 2; // 审核通过
  10. const EVALUATE_STATUS_REJECTED = 3; // 审核失败
  11. /**
  12. * 是否有图片
  13. */
  14. const HAS_PICTURE_NO = 0; // 无图片
  15. const HAS_PICTURE_YES = 1; // 有图片
  16. /**
  17. * 星级评价类型
  18. */
  19. const RATING_TYPE_BAD = 1; // 差评 (1-2星)
  20. const RATING_TYPE_MEDIUM = 2; // 中评 (3星)
  21. const RATING_TYPE_GOOD = 3; // 好评 (4-5星)
  22. /**
  23. * 获取评价状态文本
  24. * @param int $status
  25. * @return string
  26. */
  27. public static function getEvaluateStatusText($status)
  28. {
  29. $statusMap = [
  30. self::EVALUATE_STATUS_PENDING => '审核中',
  31. self::EVALUATE_STATUS_APPROVED => '审核通过',
  32. self::EVALUATE_STATUS_REJECTED => '审核失败'
  33. ];
  34. return isset($statusMap[$status]) ? $statusMap[$status] : '未知状态';
  35. }
  36. /**
  37. * 获取有图片状态文本
  38. * @param int $hasPicture
  39. * @return string
  40. */
  41. public static function getHasPictureText($hasPicture)
  42. {
  43. $statusMap = [
  44. self::HAS_PICTURE_NO => '无图片',
  45. self::HAS_PICTURE_YES => '有图片'
  46. ];
  47. return isset($statusMap[$hasPicture]) ? $statusMap[$hasPicture] : '未知状态';
  48. }
  49. /**
  50. * 获取星级评价类型文本
  51. * @param int $ratingType
  52. * @return string
  53. */
  54. public static function getRatingTypeText($ratingType)
  55. {
  56. $typeMap = [
  57. self::RATING_TYPE_BAD => '差评',
  58. self::RATING_TYPE_MEDIUM => '中评',
  59. self::RATING_TYPE_GOOD => '好评'
  60. ];
  61. return isset($typeMap[$ratingType]) ? $typeMap[$ratingType] : '未知类型';
  62. }
  63. /**
  64. * 根据星级获取评价类型
  65. * @param int $star
  66. * @return int
  67. */
  68. public static function getRatingTypeByStar($star)
  69. {
  70. if ($star >= 4) {
  71. return self::RATING_TYPE_GOOD;
  72. } elseif ($star == 3) {
  73. return self::RATING_TYPE_MEDIUM;
  74. } else {
  75. return self::RATING_TYPE_BAD;
  76. }
  77. }
  78. /**
  79. * 获取所有评价状态
  80. * @return array
  81. */
  82. public static function getEvaluateStatusList()
  83. {
  84. return [
  85. self::EVALUATE_STATUS_PENDING => '审核中',
  86. self::EVALUATE_STATUS_APPROVED => '审核通过',
  87. self::EVALUATE_STATUS_REJECTED => '审核失败'
  88. ];
  89. }
  90. /**
  91. * 获取所有有图片状态
  92. * @return array
  93. */
  94. public static function getHasPictureList()
  95. {
  96. return [
  97. self::HAS_PICTURE_NO => '无图片',
  98. self::HAS_PICTURE_YES => '有图片'
  99. ];
  100. }
  101. /**
  102. * 获取所有星级评价类型
  103. * @return array
  104. */
  105. public static function getRatingTypeList()
  106. {
  107. return [
  108. self::RATING_TYPE_GOOD => '好评',
  109. self::RATING_TYPE_MEDIUM => '中评',
  110. self::RATING_TYPE_BAD => '差评'
  111. ];
  112. }
  113. /**
  114. * 验证评价状态
  115. * @param int $status
  116. * @return bool
  117. */
  118. public static function isValidEvaluateStatus($status)
  119. {
  120. return in_array($status, [
  121. self::EVALUATE_STATUS_PENDING,
  122. self::EVALUATE_STATUS_APPROVED,
  123. self::EVALUATE_STATUS_REJECTED
  124. ]);
  125. }
  126. /**
  127. * 验证有图片状态
  128. * @param int $hasPicture
  129. * @return bool
  130. */
  131. public static function isValidHasPicture($hasPicture)
  132. {
  133. return in_array($hasPicture, [
  134. self::HAS_PICTURE_NO,
  135. self::HAS_PICTURE_YES
  136. ]);
  137. }
  138. /**
  139. * 验证星级评价类型
  140. * @param int $ratingType
  141. * @return bool
  142. */
  143. public static function isValidRatingType($ratingType)
  144. {
  145. return in_array($ratingType, [
  146. self::RATING_TYPE_BAD,
  147. self::RATING_TYPE_MEDIUM,
  148. self::RATING_TYPE_GOOD
  149. ]);
  150. }
  151. }