123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace app\common\Enum;
- class CommentEnum
- {
- /**
- * 评价状态
- */
- const EVALUATE_STATUS_PENDING = 1; // 审核中
- const EVALUATE_STATUS_APPROVED = 2; // 审核通过
- const EVALUATE_STATUS_REJECTED = 3; // 审核失败
- /**
- * 是否有图片
- */
- const HAS_PICTURE_NO = 0; // 无图片
- const HAS_PICTURE_YES = 1; // 有图片
- /**
- * 星级评价类型
- */
- const RATING_TYPE_BAD = 1; // 差评 (1-2星)
- const RATING_TYPE_MEDIUM = 2; // 中评 (3星)
- const RATING_TYPE_GOOD = 3; // 好评 (4-5星)
- /**
- * 获取评价状态文本
- * @param int $status
- * @return string
- */
- public static function getEvaluateStatusText($status)
- {
- $statusMap = [
- self::EVALUATE_STATUS_PENDING => '审核中',
- self::EVALUATE_STATUS_APPROVED => '审核通过',
- self::EVALUATE_STATUS_REJECTED => '审核失败'
- ];
- return isset($statusMap[$status]) ? $statusMap[$status] : '未知状态';
- }
-
- /**
- * 获取有图片状态文本
- * @param int $hasPicture
- * @return string
- */
- public static function getHasPictureText($hasPicture)
- {
- $statusMap = [
- self::HAS_PICTURE_NO => '无图片',
- self::HAS_PICTURE_YES => '有图片'
- ];
- return isset($statusMap[$hasPicture]) ? $statusMap[$hasPicture] : '未知状态';
- }
- /**
- * 获取星级评价类型文本
- * @param int $ratingType
- * @return string
- */
- public static function getRatingTypeText($ratingType)
- {
- $typeMap = [
- self::RATING_TYPE_BAD => '差评',
- self::RATING_TYPE_MEDIUM => '中评',
- self::RATING_TYPE_GOOD => '好评'
- ];
- return isset($typeMap[$ratingType]) ? $typeMap[$ratingType] : '未知类型';
- }
- /**
- * 根据星级获取评价类型
- * @param int $star
- * @return int
- */
- public static function getRatingTypeByStar($star)
- {
- if ($star >= 4) {
- return self::RATING_TYPE_GOOD;
- } elseif ($star == 3) {
- return self::RATING_TYPE_MEDIUM;
- } else {
- return self::RATING_TYPE_BAD;
- }
- }
- /**
- * 获取所有评价状态
- * @return array
- */
- public static function getEvaluateStatusList()
- {
- return [
- self::EVALUATE_STATUS_PENDING => '审核中',
- self::EVALUATE_STATUS_APPROVED => '审核通过',
- self::EVALUATE_STATUS_REJECTED => '审核失败'
- ];
- }
- /**
- * 获取所有有图片状态
- * @return array
- */
- public static function getHasPictureList()
- {
- return [
- self::HAS_PICTURE_NO => '无图片',
- self::HAS_PICTURE_YES => '有图片'
- ];
- }
- /**
- * 获取所有星级评价类型
- * @return array
- */
- public static function getRatingTypeList()
- {
- return [
- self::RATING_TYPE_GOOD => '好评',
- self::RATING_TYPE_MEDIUM => '中评',
- self::RATING_TYPE_BAD => '差评'
- ];
- }
- /**
- * 验证评价状态
- * @param int $status
- * @return bool
- */
- public static function isValidEvaluateStatus($status)
- {
- return in_array($status, [
- self::EVALUATE_STATUS_PENDING,
- self::EVALUATE_STATUS_APPROVED,
- self::EVALUATE_STATUS_REJECTED
- ]);
- }
- /**
- * 验证有图片状态
- * @param int $hasPicture
- * @return bool
- */
- public static function isValidHasPicture($hasPicture)
- {
- return in_array($hasPicture, [
- self::HAS_PICTURE_NO,
- self::HAS_PICTURE_YES
- ]);
- }
- /**
- * 验证星级评价类型
- * @param int $ratingType
- * @return bool
- */
- public static function isValidRatingType($ratingType)
- {
- return in_array($ratingType, [
- self::RATING_TYPE_BAD,
- self::RATING_TYPE_MEDIUM,
- self::RATING_TYPE_GOOD
- ]);
- }
- }
|