123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <?php
- namespace app\common\Enum;
- /**
- * 抽奖活动枚举类
- */
- class LotteryEnum
- {
- // 活动类型
- const ACTIVITY_TYPE_CONSUME = 1; // 消费抽奖
- // 奖品类型
- const PRIZE_TYPE_NO_PRIZE = 1; // 未中奖
- const PRIZE_TYPE_GOODS = 2; // 实物奖品
- const PRIZE_TYPE_INTEGRAL = 3; // 积分
- const PRIZE_TYPE_BALANCE = 4; // 余额
- const PRIZE_TYPE_COUPON = 5; // 优惠券
- const PRIZE_TYPE_REDBAG = 6; // 红包
- const PRIZE_TYPE_CODE = 7; // 兑换码
- const PRIZE_TYPE_SHOP_GOODS = 8; // 商城奖品
- // 活动状态
- const ACTIVITY_STATUS_DRAFT = 0; // 草稿
- const ACTIVITY_STATUS_ACTIVE = 1; // 进行中
- const ACTIVITY_STATUS_ENDED = 2; // 已结束
- const ACTIVITY_STATUS_PAUSED = 3; // 已暂停
- // 开奖方式
- const LOTTERY_TYPE_IMMEDIATE = 1; // 即抽即中
- const LOTTERY_TYPE_TIME = 2; // 按时间开奖
- const LOTTERY_TYPE_PEOPLE = 3; // 按人数开奖
- // 适用人群
- const USER_LIMIT_TYPE_ALL = 1; // 所有用户
- const USER_LIMIT_TYPE_LEVEL = 2; // 会员等级
- const USER_LIMIT_TYPE_TAG = 3; // 会员标签
- // 引导样式
- const GUIDE_STYLE_DEFAULT = 1; // 默认样式
- const GUIDE_STYLE_CUSTOM = 2; // 自定义样式
- // 条件类型(任务类型)
- const CONDITION_TYPE_BUY_GOODS = 1; // 购买指定商品
- const CONDITION_TYPE_ORDER_AMOUNT = 2; // 单笔订单消费满额
- const CONDITION_TYPE_RECHARGE_AMOUNT = 3; // 单次充值满额
- const CONDITION_TYPE_TOTAL_AMOUNT = 4; // 活动期间累计消费满额
- // 活动渠道
- const CHANNEL_WECHAT_MP = 'wechat_mp'; // 微信公众号
- const CHANNEL_WECHAT_MINI = 'wechat_mini'; // 微信小程序
- const CHANNEL_H5 = 'h5'; // 手机浏览器H5
- const CHANNEL_APP = 'app'; // APP
- // 兑奖期限类型
- const REDEEM_EXPIRE_TYPE_FOREVER = 1; // 永久有效
- const REDEEM_EXPIRE_TYPE_DAYS = 2; // 固定天数
- /**
- * 获取奖品类型映射
- * @return array
- */
- public static function getPrizeTypeMap()
- {
- return [
- self::PRIZE_TYPE_NO_PRIZE => '未中奖',
- self::PRIZE_TYPE_GOODS => '实物奖品',
- self::PRIZE_TYPE_INTEGRAL => '积分',
- self::PRIZE_TYPE_BALANCE => '余额',
- self::PRIZE_TYPE_COUPON => '优惠券',
- self::PRIZE_TYPE_REDBAG => '红包',
- self::PRIZE_TYPE_CODE => '兑换码',
- self::PRIZE_TYPE_SHOP_GOODS => '商城奖品',
- ];
- }
- /**
- * 获取活动类型映射
- * @return array
- */
- public static function getActivityTypeMap()
- {
- return [
- self::ACTIVITY_TYPE_CONSUME => '消费抽奖',
- ];
- }
- /**
- * 获取奖品类型文本
- * @param string $type
- * @return string
- */
- public static function getPrizeTypeText($type)
- {
- return self::getPrizeTypeMap()[$type] ?? '未知';
- }
- /**
- * 获取奖品类型列表(用于前端选择)
- * @return array
- */
- public static function getPrizeTypeList()
- {
- $map = self::getPrizeTypeMap();
- //unset($map[self::PRIZE_TYPE_NO_PRIZE]); // 移除未中奖选项
- return array_map(function($value, $key) {
- return ['value' => $key, 'text' => $value];
- }, $map, array_keys($map));
- }
- /**
- * 获取活动状态映射
- * @return array
- */
- public static function getActivityStatusMap()
- {
- return [
- self::ACTIVITY_STATUS_DRAFT => '草稿',
- self::ACTIVITY_STATUS_ACTIVE => '进行中',
- self::ACTIVITY_STATUS_ENDED => '已结束',
- self::ACTIVITY_STATUS_PAUSED => '已暂停',
- ];
- }
- /**
- * 获取活动状态文本
- * @param int $status
- * @return string
- */
- public static function getActivityStatusText($status)
- {
- return self::getActivityStatusMap()[$status] ?? '未知';
- }
- /**
- * 获取开奖方式映射
- * @return array
- */
- public static function getLotteryTypeMap()
- {
- return [
- self::LOTTERY_TYPE_IMMEDIATE => '即抽即中',
- self::LOTTERY_TYPE_TIME => '按时间开奖',
- self::LOTTERY_TYPE_PEOPLE => '按人数开奖',
- ];
- }
- /**
- * 获取开奖方式文本
- * @param int $type
- * @return string
- */
- public static function getLotteryTypeText($type)
- {
- return self::getLotteryTypeMap()[$type] ?? '未知';
- }
- /**
- * 获取适用人群映射
- * @return array
- */
- public static function getUserLimitTypeMap()
- {
- return [
- self::USER_LIMIT_TYPE_ALL => '全部会员',
- self::USER_LIMIT_TYPE_LEVEL => '会员等级',
- self::USER_LIMIT_TYPE_TAG => '会员标签',
- ];
- }
- /**
- * 获取适用人群文本
- * @param int $type
- * @return string
- */
- public static function getUserLimitTypeText($type)
- {
- return self::getUserLimitTypeMap()[$type] ?? '未知';
- }
- /**
- * 获取引导样式映射
- * @return array
- */
- public static function getGuideStyleMap()
- {
- return [
- self::GUIDE_STYLE_DEFAULT => '默认样式',
- self::GUIDE_STYLE_CUSTOM => '自定义样式',
- ];
- }
- /**
- * 获取引导样式文本
- * @param int $style
- * @return string
- */
- public static function getGuideStyleText($style)
- {
- return self::getGuideStyleMap()[$style] ?? '未知';
- }
- /**
- * 获取条件类型映射
- * @return array
- */
- public static function getConditionTypeMap()
- {
- return [
- self::CONDITION_TYPE_BUY_GOODS => '购买指定商品',
- self::CONDITION_TYPE_ORDER_AMOUNT => '单笔订单消费满额',
- self::CONDITION_TYPE_RECHARGE_AMOUNT => '单次充值满额',
- self::CONDITION_TYPE_TOTAL_AMOUNT => '活动期间累计消费满额',
- ];
- }
- /**
- * 获取条件类型文本
- * @param int $type
- * @return string
- */
- public static function getConditionTypeText($type)
- {
- return self::getConditionTypeMap()[$type] ?? '未知';
- }
- /**
- * 获取任务类型映射(兼容旧方法名)
- * @return array
- * @deprecated 请使用 getConditionTypeMap()
- */
- public static function getTaskTypeMap()
- {
- return self::getConditionTypeMap();
- }
- /**
- * 获取任务类型文本(兼容旧方法名)
- * @param int $type
- * @return string
- * @deprecated 请使用 getConditionTypeText()
- */
- public static function getTaskTypeText($type)
- {
- return self::getConditionTypeText($type);
- }
- /**
- * 获取活动渠道映射
- * @return array
- */
- public static function getChannelMap()
- {
- return [
- self::CHANNEL_WECHAT_MP => '微信公众号',
- self::CHANNEL_WECHAT_MINI => '微信小程序',
- self::CHANNEL_H5 => '手机浏览器H5',
- self::CHANNEL_APP => 'APP',
- ];
- }
- /**
- * 获取活动渠道文本
- * @param string $channel
- * @return string
- */
- public static function getChannelText($channel)
- {
- return self::getChannelMap()[$channel] ?? '未知';
- }
- /**
- * 获取兑奖期限类型映射
- * @return array
- */
- public static function getRedeemExpireTypeMap()
- {
- return [
- self::REDEEM_EXPIRE_TYPE_FOREVER => '永久有效',
- self::REDEEM_EXPIRE_TYPE_DAYS => '固定时长',
- ];
- }
- /**
- * 获取兑奖期限类型文本
- * @param int $type
- * @return string
- */
- public static function getRedeemExpireTypeText($type)
- {
- return self::getRedeemExpireTypeMap()[$type] ?? '未知';
- }
- /**
- * 获取奖品默认图片映射
- * @return array
- */
- public static function getPrizeDefaultImageMap()
- {
- // 默认图
- $config = config('site');
- return [
- self::PRIZE_TYPE_NO_PRIZE => $config['prize_losing_lottery'] ?? '',
- self::PRIZE_TYPE_GOODS => $config['prize_goods'] ?? '',
- self::PRIZE_TYPE_INTEGRAL => $config['prize_credit'] ?? '',
- self::PRIZE_TYPE_BALANCE => $config['prize_balance'] ?? '',
- self::PRIZE_TYPE_COUPON => $config['prize_coupon'] ?? '',
- self::PRIZE_TYPE_REDBAG => $config['prize_redbag'] ?? '',
- self::PRIZE_TYPE_CODE => $config['prize_code'] ?? '',
- self::PRIZE_TYPE_SHOP_GOODS => $config['prize_shop_goods'] ?? '',
- ];
- }
- /**
- * 获取奖品默认图片
- * @param string $type
- * @return string
- */
- public static function getPrizeDefaultImage($type)
- {
- return self::getPrizeDefaultImageMap()[$type] ?? '/assets/img/lottery/default.png';
- }
- /**
- * 检查是否为有效的奖品类型
- * @param string $type
- * @return bool
- */
- public static function isValidPrizeType($type)
- {
- return array_key_exists($type, self::getPrizeTypeMap());
- }
- /**
- * 检查是否为有效的活动状态
- * @param int $status
- * @return bool
- */
- public static function isValidActivityStatus($status)
- {
- return array_key_exists($status, self::getActivityStatusMap());
- }
- /**
- * 检查是否为有效的开奖方式
- * @param int $type
- * @return bool
- */
- public static function isValidLotteryType($type)
- {
- return array_key_exists($type, self::getLotteryTypeMap());
- }
- /**
- * 检查是否为有效的条件类型
- * @param int $type
- * @return bool
- */
- public static function isValidConditionType($type)
- {
- return array_key_exists($type, self::getConditionTypeMap());
- }
- }
|