LotteryEnum.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. namespace app\common\Enum;
  3. /**
  4. * 抽奖活动枚举类
  5. */
  6. class LotteryEnum
  7. {
  8. // ============ 抽奖基础状态 ============
  9. const STATUS_NOT_STARTED = 1; // 未开始
  10. const STATUS_ONGOING = 2; // 进行中
  11. const STATUS_ENDED = 3; // 已结束
  12. const STATUS_CANCELLED = 4; // 已取消
  13. const STATUS_SUSPENDED = 5; // 已暂停
  14. const STATUS_CLOSED = 6; // 已关闭
  15. const STATUS_DELETED = 7; // 已删除
  16. const STATUS_EXPIRED = 8; // 已过期
  17. // ============ 抽奖类型 ============
  18. const LOTTERY_TYPE_CONSUMPTION_LOTTERY = 1; // 消费抽奖
  19. // ============ 开奖方式 ============
  20. const LOTTERY_TYPE_INSTANT = 1; // 即抽即中
  21. const LOTTERY_TYPE_TIME = 2; // 按时间开奖
  22. const LOTTERY_TYPE_PEOPLE = 3; // 按人数开奖
  23. // ============ 用户群体类型 ============
  24. const USER_LIMIT_ALL = 1; // 全部会员
  25. const USER_LIMIT_LEVEL = 2; // 会员等级
  26. const USER_LIMIT_TAG = 3; // 会员标签
  27. // ============ 引导样式 ============
  28. const GUIDE_STYLE_DEFAULT = 1; // 默认样式
  29. const GUIDE_STYLE_CUSTOM = 2; // 自定义
  30. // ============ 奖品类型 ============
  31. const PRIZE_TYPE_NO_PRIZE = 1; // 未中奖
  32. const PRIZE_TYPE_GOODS = 2; // 实物奖品
  33. const PRIZE_TYPE_POINTS = 3; // 积分
  34. const PRIZE_TYPE_BALANCE = 4; // 余额
  35. const PRIZE_TYPE_COUPON = 5; // 优惠券
  36. const PRIZE_TYPE_REDPACK = 6; // 红包
  37. const PRIZE_TYPE_CODE = 7; // 兑换码
  38. const PRIZE_TYPE_SHOP_GOODS = 8; // 商城奖品
  39. // ============ 奖品发放方式 ============
  40. const DELIVER_TYPE_AUTO = 1; // 自动发放
  41. const DELIVER_TYPE_MANUAL = 2; // 手动发放
  42. // ============ 奖品发放状态 ============
  43. const DELIVER_STATUS_PENDING = 0; // 待发放
  44. const DELIVER_STATUS_SUCCESS = 1; // 已发放
  45. const DELIVER_STATUS_FAILED = 2; // 发放失败
  46. const DELIVER_STATUS_CANCELLED = 3; // 已取消
  47. // ============ 参与条件类型 ============
  48. const CONDITION_TYPE_BUY_GOODS = 1; // 购买指定商品
  49. const CONDITION_TYPE_ORDER_AMOUNT = 2; // 单笔订单消费满额
  50. const CONDITION_TYPE_RECHARGE_AMOUNT = 3; // 单次充值满额
  51. const CONDITION_TYPE_TOTAL_AMOUNT = 4; // 活动期间累计消费满额
  52. // ============ 商品规则 ============
  53. const GOODS_RULE_INCLUDE = 1; // 指定商品参与
  54. const GOODS_RULE_EXCLUDE = 2; // 指定商品不可参与
  55. // ============ 触发类型 ============
  56. const TRIGGER_TYPE_BUY_GOODS = 1; // 购买商品
  57. const TRIGGER_TYPE_ORDER_CONSUME = 2; // 订单消费
  58. const TRIGGER_TYPE_RECHARGE = 3; // 充值
  59. const TRIGGER_TYPE_TOTAL_CONSUME = 4; // 累计消费
  60. // ============ 机会获取类型(与条件类型保持一致,额外增加管理员赠送) ============
  61. const CHANCE_GET_TYPE_BUY_GOODS = 1; // 购买指定商品(对应CONDITION_TYPE_BUY_GOODS)
  62. const CHANCE_GET_TYPE_ORDER_AMOUNT = 2; // 单笔订单消费满额(对应CONDITION_TYPE_ORDER_AMOUNT)
  63. const CHANCE_GET_TYPE_RECHARGE = 3; // 单次充值满额(对应CONDITION_TYPE_RECHARGE_AMOUNT)
  64. const CHANCE_GET_TYPE_TOTAL_AMOUNT = 4; // 活动期间累计消费满额(对应CONDITION_TYPE_TOTAL_AMOUNT)
  65. const CHANCE_GET_TYPE_ADMIN_GRANT = 5; // 管理员赠送
  66. // ============ 兑奖期限类型 ============
  67. const REDEEM_EXPIRE_FOREVER = 1; // 永久有效
  68. const REDEEM_EXPIRE_FIXED = 2; // 固定时长
  69. /**
  70. * 获取活动状态映射(页面显示用)
  71. */
  72. public static function getActivityStatusMap()
  73. {
  74. return [
  75. self::STATUS_NOT_STARTED => '未开始',
  76. self::STATUS_ONGOING => '进行中',
  77. self::STATUS_ENDED => '已结束',
  78. self::STATUS_CANCELLED => '已取消',
  79. self::STATUS_SUSPENDED => '已暂停',
  80. ];
  81. }
  82. /**
  83. * 获取全部活动状态映射(包含逻辑状态)
  84. */
  85. public static function getAllActivityStatusMap()
  86. {
  87. return [
  88. self::STATUS_NOT_STARTED => '未开始',
  89. self::STATUS_ONGOING => '进行中',
  90. self::STATUS_ENDED => '已结束',
  91. self::STATUS_CANCELLED => '已取消',
  92. self::STATUS_SUSPENDED => '已暂停',
  93. self::STATUS_CLOSED => '已关闭',
  94. self::STATUS_DELETED => '已删除',
  95. self::STATUS_EXPIRED => '已过期',
  96. ];
  97. }
  98. /**
  99. * 获取活动类型映射
  100. */
  101. public static function getActivityTypeMap()
  102. {
  103. return [
  104. self::LOTTERY_TYPE_CONSUMPTION_LOTTERY => '消费抽奖',
  105. ];
  106. }
  107. /**
  108. * 获取开奖方式映射
  109. */
  110. public static function getLotteryTypeMap()
  111. {
  112. return [
  113. self::LOTTERY_TYPE_INSTANT => '即抽即中',
  114. self::LOTTERY_TYPE_TIME => '按时间开奖',
  115. self::LOTTERY_TYPE_PEOPLE => '按人数开奖',
  116. ];
  117. }
  118. /**
  119. * 获取用户群体类型映射
  120. */
  121. public static function getUserLimitTypeMap()
  122. {
  123. return [
  124. self::USER_LIMIT_ALL => '全部会员',
  125. self::USER_LIMIT_LEVEL => '会员等级',
  126. self::USER_LIMIT_TAG => '会员标签',
  127. ];
  128. }
  129. /**
  130. * 获取引导样式映射
  131. */
  132. public static function getGuideStyleMap()
  133. {
  134. return [
  135. self::GUIDE_STYLE_DEFAULT => '默认样式',
  136. self::GUIDE_STYLE_CUSTOM => '自定义',
  137. ];
  138. }
  139. /**
  140. * 获取奖品类型映射
  141. */
  142. public static function getPrizeTypeMap()
  143. {
  144. return [
  145. self::PRIZE_TYPE_NO_PRIZE => '未中奖',
  146. self::PRIZE_TYPE_GOODS => '实物奖品',
  147. self::PRIZE_TYPE_POINTS => '积分',
  148. self::PRIZE_TYPE_BALANCE => '余额',
  149. self::PRIZE_TYPE_COUPON => '优惠券',
  150. self::PRIZE_TYPE_REDPACK => '红包',
  151. self::PRIZE_TYPE_CODE => '兑换码',
  152. self::PRIZE_TYPE_SHOP_GOODS => '商城奖品',
  153. ];
  154. }
  155. /**
  156. * 获取奖品默认图片映射
  157. */
  158. public static function getPrizeDefaultImageMap()
  159. {
  160. // 从配置文件获取图片路径
  161. $config = config('site');
  162. return [
  163. self::PRIZE_TYPE_NO_PRIZE => $config['prize_losing_lottery'] ?? '/assets/img/avatar.png',
  164. self::PRIZE_TYPE_GOODS => $config['prize_goods'] ?? '/assets/img/package.png',
  165. self::PRIZE_TYPE_POINTS => $config['prize_credit'] ?? '/assets/img/circle.png',
  166. self::PRIZE_TYPE_BALANCE => $config['prize_balance'] ?? '/assets/img/circle.png',
  167. self::PRIZE_TYPE_COUPON => $config['prize_coupon'] ?? '/assets/img/circle.png',
  168. self::PRIZE_TYPE_REDPACK => $config['prize_redbag'] ?? '/assets/img/circle.png',
  169. self::PRIZE_TYPE_CODE => $config['prize_code'] ?? '/assets/img/circle.png',
  170. self::PRIZE_TYPE_SHOP_GOODS => $config['prize_shop_goods'] ?? '/assets/img/package.png',
  171. ];
  172. }
  173. /**
  174. * 获取奖品发放方式映射
  175. */
  176. public static function getDeliverTypeMap()
  177. {
  178. return [
  179. self::DELIVER_TYPE_AUTO => '自动发放',
  180. self::DELIVER_TYPE_MANUAL => '手动发放',
  181. ];
  182. }
  183. /**
  184. * 获取奖品发放状态映射
  185. */
  186. public static function getDeliverStatusMap()
  187. {
  188. return [
  189. self::DELIVER_STATUS_PENDING => '待发放',
  190. self::DELIVER_STATUS_SUCCESS => '已发放',
  191. self::DELIVER_STATUS_FAILED => '发放失败',
  192. self::DELIVER_STATUS_CANCELLED => '已取消',
  193. ];
  194. }
  195. /**
  196. * 获取参与条件类型映射
  197. */
  198. public static function getConditionTypeMap()
  199. {
  200. return [
  201. self::CONDITION_TYPE_BUY_GOODS => '购买指定商品',
  202. self::CONDITION_TYPE_ORDER_AMOUNT => '单笔订单消费满N元',
  203. self::CONDITION_TYPE_RECHARGE_AMOUNT => '单次充值金额满N元',
  204. self::CONDITION_TYPE_TOTAL_AMOUNT => '活动期间累计消费N元',
  205. ];
  206. }
  207. /**
  208. * 获取商品规则映射
  209. */
  210. public static function getGoodsRuleMap()
  211. {
  212. return [
  213. self::GOODS_RULE_INCLUDE => '指定商品参与',
  214. self::GOODS_RULE_EXCLUDE => '指定商品不可参与',
  215. ];
  216. }
  217. /**
  218. * 获取触发类型映射 后台
  219. */
  220. public static function getTriggerTypeMap()
  221. {
  222. return [
  223. self::TRIGGER_TYPE_BUY_GOODS => '购买商品',
  224. self::TRIGGER_TYPE_ORDER_CONSUME => '订单消费',
  225. self::TRIGGER_TYPE_RECHARGE => '充值',
  226. self::TRIGGER_TYPE_TOTAL_CONSUME => '累计消费',
  227. ];
  228. }
  229. /**
  230. * 获取机会获取类型映射h
  231. */
  232. public static function getChanceGetTypeMap()
  233. {
  234. return [
  235. self::CHANCE_GET_TYPE_BUY_GOODS => '购买指定商品',
  236. self::CHANCE_GET_TYPE_ORDER_AMOUNT => '单笔订单消费满额',
  237. self::CHANCE_GET_TYPE_RECHARGE => '单次充值满额',
  238. self::CHANCE_GET_TYPE_TOTAL_AMOUNT => '活动期间累计消费满额',
  239. self::CHANCE_GET_TYPE_ADMIN_GRANT => '管理员赠送',
  240. ];
  241. }
  242. /**
  243. * 获取兑奖期限类型映射
  244. */
  245. public static function getRedeemExpireTypeMap()
  246. {
  247. return [
  248. self::REDEEM_EXPIRE_FOREVER => '永久有效',
  249. self::REDEEM_EXPIRE_FIXED => '固定时长',
  250. ];
  251. }
  252. /**
  253. * 获取活动状态文本
  254. */
  255. public static function getActivityStatusText($status)
  256. {
  257. $map = self::getAllActivityStatusMap();
  258. return $map[$status] ?? '未知';
  259. }
  260. /**
  261. * 获取奖品类型文本
  262. */
  263. public static function getPrizeTypeText($type)
  264. {
  265. $map = self::getPrizeTypeMap();
  266. return $map[$type] ?? '未知';
  267. }
  268. /**
  269. * 获取开奖方式文本
  270. */
  271. public static function getLotteryTypeText($type)
  272. {
  273. $map = self::getLotteryTypeMap();
  274. return $map[$type] ?? '未知';
  275. }
  276. /**
  277. * 获取条件类型文本
  278. */
  279. public static function getConditionTypeText($type)
  280. {
  281. $map = self::getConditionTypeMap();
  282. return $map[$type] ?? '未知';
  283. }
  284. /**
  285. * 获取机会获取类型文本
  286. */
  287. public static function getChanceGetTypeText($type)
  288. {
  289. $map = self::getChanceGetTypeMap();
  290. return $map[$type] ?? '未知';
  291. }
  292. /**
  293. * 验证活动状态是否有效(包含所有状态)
  294. */
  295. public static function isValidActivityStatus($status)
  296. {
  297. return array_key_exists($status, self::getAllActivityStatusMap());
  298. }
  299. /**
  300. * 判断是否为可在页面显示的状态
  301. */
  302. public static function isDisplayableStatus($status)
  303. {
  304. return array_key_exists($status, self::getActivityStatusMap());
  305. }
  306. /**
  307. * 判断是否为逻辑状态(不在页面显示)
  308. */
  309. public static function isLogicalStatus($status)
  310. {
  311. return in_array($status, [
  312. self::STATUS_CLOSED,
  313. self::STATUS_DELETED,
  314. self::STATUS_EXPIRED
  315. ]);
  316. }
  317. /**
  318. * 验证奖品类型是否有效
  319. */
  320. public static function isValidPrizeType($type)
  321. {
  322. return array_key_exists($type, self::getPrizeTypeMap());
  323. }
  324. /**
  325. * 验证开奖方式是否有效
  326. */
  327. public static function isValidLotteryType($type)
  328. {
  329. return array_key_exists($type, self::getLotteryTypeMap());
  330. }
  331. /**
  332. * 验证条件类型是否有效
  333. */
  334. public static function isValidConditionType($type)
  335. {
  336. return array_key_exists($type, self::getConditionTypeMap());
  337. }
  338. /**
  339. * 验证机会获取类型是否有效
  340. */
  341. public static function isValidChanceGetType($type)
  342. {
  343. return array_key_exists($type, self::getChanceGetTypeMap());
  344. }
  345. }