LotteryEnum.php 13 KB

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