LotteryEnum.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. namespace app\common\Enum;
  3. /**
  4. * 抽奖活动枚举类
  5. */
  6. class LotteryEnum
  7. {
  8. // 活动类型
  9. const ACTIVITY_TYPE_CONSUME = 1; // 消费抽奖
  10. // 奖品类型
  11. const PRIZE_TYPE_NO_PRIZE = 1; // 未中奖
  12. const PRIZE_TYPE_GOODS = 2; // 实物奖品
  13. const PRIZE_TYPE_INTEGRAL = 3; // 积分
  14. const PRIZE_TYPE_BALANCE = 4; // 余额
  15. const PRIZE_TYPE_COUPON = 5; // 优惠券
  16. const PRIZE_TYPE_REDBAG = 6; // 红包
  17. const PRIZE_TYPE_CODE = 7; // 兑换码
  18. const PRIZE_TYPE_SHOP_GOODS = 8; // 商城奖品
  19. // 活动状态
  20. const ACTIVITY_STATUS_DRAFT = 0; // 草稿
  21. const ACTIVITY_STATUS_ACTIVE = 1; // 进行中
  22. const ACTIVITY_STATUS_ENDED = 2; // 已结束
  23. const ACTIVITY_STATUS_PAUSED = 3; // 已暂停
  24. // 开奖方式
  25. const LOTTERY_TYPE_IMMEDIATE = 1; // 即抽即中
  26. const LOTTERY_TYPE_TIME = 2; // 按时间开奖
  27. const LOTTERY_TYPE_PEOPLE = 3; // 按人数开奖
  28. // 适用人群
  29. const USER_LIMIT_TYPE_ALL = 1; // 所有用户
  30. const USER_LIMIT_TYPE_LEVEL = 2; // 会员等级
  31. const USER_LIMIT_TYPE_TAG = 3; // 会员标签
  32. // 引导样式
  33. const GUIDE_STYLE_DEFAULT = 1; // 默认样式
  34. const GUIDE_STYLE_CUSTOM = 2; // 自定义样式
  35. // 条件类型(任务类型)
  36. const CONDITION_TYPE_BUY_GOODS = 1; // 购买指定商品
  37. const CONDITION_TYPE_ORDER_AMOUNT = 2; // 单笔订单消费满额
  38. const CONDITION_TYPE_RECHARGE_AMOUNT = 3; // 单次充值满额
  39. const CONDITION_TYPE_TOTAL_AMOUNT = 4; // 活动期间累计消费满额
  40. // 活动渠道
  41. const CHANNEL_WECHAT_MP = 'wechat_mp'; // 微信公众号
  42. const CHANNEL_WECHAT_MINI = 'wechat_mini'; // 微信小程序
  43. const CHANNEL_H5 = 'h5'; // 手机浏览器H5
  44. const CHANNEL_APP = 'app'; // APP
  45. // 兑奖期限类型
  46. const REDEEM_EXPIRE_TYPE_FOREVER = 1; // 永久有效
  47. const REDEEM_EXPIRE_TYPE_DAYS = 2; // 固定天数
  48. /**
  49. * 获取奖品类型映射
  50. * @return array
  51. */
  52. public static function getPrizeTypeMap()
  53. {
  54. return [
  55. self::PRIZE_TYPE_NO_PRIZE => '未中奖',
  56. self::PRIZE_TYPE_GOODS => '实物奖品',
  57. self::PRIZE_TYPE_INTEGRAL => '积分',
  58. self::PRIZE_TYPE_BALANCE => '余额',
  59. self::PRIZE_TYPE_COUPON => '优惠券',
  60. self::PRIZE_TYPE_REDBAG => '红包',
  61. self::PRIZE_TYPE_CODE => '兑换码',
  62. self::PRIZE_TYPE_SHOP_GOODS => '商城奖品',
  63. ];
  64. }
  65. /**
  66. * 获取活动类型映射
  67. * @return array
  68. */
  69. public static function getActivityTypeMap()
  70. {
  71. return [
  72. self::ACTIVITY_TYPE_CONSUME => '消费抽奖',
  73. ];
  74. }
  75. /**
  76. * 获取奖品类型文本
  77. * @param string $type
  78. * @return string
  79. */
  80. public static function getPrizeTypeText($type)
  81. {
  82. return self::getPrizeTypeMap()[$type] ?? '未知';
  83. }
  84. /**
  85. * 获取奖品类型列表(用于前端选择)
  86. * @return array
  87. */
  88. public static function getPrizeTypeList()
  89. {
  90. $map = self::getPrizeTypeMap();
  91. //unset($map[self::PRIZE_TYPE_NO_PRIZE]); // 移除未中奖选项
  92. return array_map(function($value, $key) {
  93. return ['value' => $key, 'text' => $value];
  94. }, $map, array_keys($map));
  95. }
  96. /**
  97. * 获取活动状态映射
  98. * @return array
  99. */
  100. public static function getActivityStatusMap()
  101. {
  102. return [
  103. self::ACTIVITY_STATUS_DRAFT => '草稿',
  104. self::ACTIVITY_STATUS_ACTIVE => '进行中',
  105. self::ACTIVITY_STATUS_ENDED => '已结束',
  106. self::ACTIVITY_STATUS_PAUSED => '已暂停',
  107. ];
  108. }
  109. /**
  110. * 获取活动状态文本
  111. * @param int $status
  112. * @return string
  113. */
  114. public static function getActivityStatusText($status)
  115. {
  116. return self::getActivityStatusMap()[$status] ?? '未知';
  117. }
  118. /**
  119. * 获取开奖方式映射
  120. * @return array
  121. */
  122. public static function getLotteryTypeMap()
  123. {
  124. return [
  125. self::LOTTERY_TYPE_IMMEDIATE => '即抽即中',
  126. self::LOTTERY_TYPE_TIME => '按时间开奖',
  127. self::LOTTERY_TYPE_PEOPLE => '按人数开奖',
  128. ];
  129. }
  130. /**
  131. * 获取开奖方式文本
  132. * @param int $type
  133. * @return string
  134. */
  135. public static function getLotteryTypeText($type)
  136. {
  137. return self::getLotteryTypeMap()[$type] ?? '未知';
  138. }
  139. /**
  140. * 获取适用人群映射
  141. * @return array
  142. */
  143. public static function getUserLimitTypeMap()
  144. {
  145. return [
  146. self::USER_LIMIT_TYPE_ALL => '全部会员',
  147. self::USER_LIMIT_TYPE_LEVEL => '会员等级',
  148. self::USER_LIMIT_TYPE_TAG => '会员标签',
  149. ];
  150. }
  151. /**
  152. * 获取适用人群文本
  153. * @param int $type
  154. * @return string
  155. */
  156. public static function getUserLimitTypeText($type)
  157. {
  158. return self::getUserLimitTypeMap()[$type] ?? '未知';
  159. }
  160. /**
  161. * 获取引导样式映射
  162. * @return array
  163. */
  164. public static function getGuideStyleMap()
  165. {
  166. return [
  167. self::GUIDE_STYLE_DEFAULT => '默认样式',
  168. self::GUIDE_STYLE_CUSTOM => '自定义样式',
  169. ];
  170. }
  171. /**
  172. * 获取引导样式文本
  173. * @param int $style
  174. * @return string
  175. */
  176. public static function getGuideStyleText($style)
  177. {
  178. return self::getGuideStyleMap()[$style] ?? '未知';
  179. }
  180. /**
  181. * 获取条件类型映射
  182. * @return array
  183. */
  184. public static function getConditionTypeMap()
  185. {
  186. return [
  187. self::CONDITION_TYPE_BUY_GOODS => '购买指定商品',
  188. self::CONDITION_TYPE_ORDER_AMOUNT => '单笔订单消费满额',
  189. self::CONDITION_TYPE_RECHARGE_AMOUNT => '单次充值满额',
  190. self::CONDITION_TYPE_TOTAL_AMOUNT => '活动期间累计消费满额',
  191. ];
  192. }
  193. /**
  194. * 获取条件类型文本
  195. * @param int $type
  196. * @return string
  197. */
  198. public static function getConditionTypeText($type)
  199. {
  200. return self::getConditionTypeMap()[$type] ?? '未知';
  201. }
  202. /**
  203. * 获取任务类型映射(兼容旧方法名)
  204. * @return array
  205. * @deprecated 请使用 getConditionTypeMap()
  206. */
  207. public static function getTaskTypeMap()
  208. {
  209. return self::getConditionTypeMap();
  210. }
  211. /**
  212. * 获取任务类型文本(兼容旧方法名)
  213. * @param int $type
  214. * @return string
  215. * @deprecated 请使用 getConditionTypeText()
  216. */
  217. public static function getTaskTypeText($type)
  218. {
  219. return self::getConditionTypeText($type);
  220. }
  221. /**
  222. * 获取活动渠道映射
  223. * @return array
  224. */
  225. public static function getChannelMap()
  226. {
  227. return [
  228. self::CHANNEL_WECHAT_MP => '微信公众号',
  229. self::CHANNEL_WECHAT_MINI => '微信小程序',
  230. self::CHANNEL_H5 => '手机浏览器H5',
  231. self::CHANNEL_APP => 'APP',
  232. ];
  233. }
  234. /**
  235. * 获取活动渠道文本
  236. * @param string $channel
  237. * @return string
  238. */
  239. public static function getChannelText($channel)
  240. {
  241. return self::getChannelMap()[$channel] ?? '未知';
  242. }
  243. /**
  244. * 获取兑奖期限类型映射
  245. * @return array
  246. */
  247. public static function getRedeemExpireTypeMap()
  248. {
  249. return [
  250. self::REDEEM_EXPIRE_TYPE_FOREVER => '永久有效',
  251. self::REDEEM_EXPIRE_TYPE_DAYS => '固定时长',
  252. ];
  253. }
  254. /**
  255. * 获取兑奖期限类型文本
  256. * @param int $type
  257. * @return string
  258. */
  259. public static function getRedeemExpireTypeText($type)
  260. {
  261. return self::getRedeemExpireTypeMap()[$type] ?? '未知';
  262. }
  263. /**
  264. * 获取奖品默认图片映射
  265. * @return array
  266. */
  267. public static function getPrizeDefaultImageMap()
  268. {
  269. // 默认图
  270. $config = config('site');
  271. return [
  272. self::PRIZE_TYPE_NO_PRIZE => $config['prize_losing_lottery'] ?? '',
  273. self::PRIZE_TYPE_GOODS => $config['prize_goods'] ?? '',
  274. self::PRIZE_TYPE_INTEGRAL => $config['prize_credit'] ?? '',
  275. self::PRIZE_TYPE_BALANCE => $config['prize_balance'] ?? '',
  276. self::PRIZE_TYPE_COUPON => $config['prize_coupon'] ?? '',
  277. self::PRIZE_TYPE_REDBAG => $config['prize_redbag'] ?? '',
  278. self::PRIZE_TYPE_CODE => $config['prize_code'] ?? '',
  279. self::PRIZE_TYPE_SHOP_GOODS => $config['prize_shop_goods'] ?? '',
  280. ];
  281. }
  282. /**
  283. * 获取奖品默认图片
  284. * @param string $type
  285. * @return string
  286. */
  287. public static function getPrizeDefaultImage($type)
  288. {
  289. return self::getPrizeDefaultImageMap()[$type] ?? '/assets/img/lottery/default.png';
  290. }
  291. /**
  292. * 检查是否为有效的奖品类型
  293. * @param string $type
  294. * @return bool
  295. */
  296. public static function isValidPrizeType($type)
  297. {
  298. return array_key_exists($type, self::getPrizeTypeMap());
  299. }
  300. /**
  301. * 检查是否为有效的活动状态
  302. * @param int $status
  303. * @return bool
  304. */
  305. public static function isValidActivityStatus($status)
  306. {
  307. return array_key_exists($status, self::getActivityStatusMap());
  308. }
  309. /**
  310. * 检查是否为有效的开奖方式
  311. * @param int $type
  312. * @return bool
  313. */
  314. public static function isValidLotteryType($type)
  315. {
  316. return array_key_exists($type, self::getLotteryTypeMap());
  317. }
  318. /**
  319. * 检查是否为有效的条件类型
  320. * @param int $type
  321. * @return bool
  322. */
  323. public static function isValidConditionType($type)
  324. {
  325. return array_key_exists($type, self::getConditionTypeMap());
  326. }
  327. }