ActivityEnum.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. namespace app\common\Enum;
  3. /**
  4. * 抽奖活动相关枚举类
  5. */
  6. class ActivityEnum
  7. {
  8. // ============ 活动基础状态 ============
  9. const ACTIVITY_STATUS_NOT_STARTED = 1; // 未开始
  10. const ACTIVITY_STATUS_ONGOING = 2; // 进行中
  11. const ACTIVITY_STATUS_ENDED = 3; // 已结束
  12. const ACTIVITY_STATUS_CANCELLED = 4; // 已取消
  13. const ACTIVITY_STATUS_SUSPENDED = 5; // 已暂停
  14. const ACTIVITY_STATUS_CLOSED = 6; // 已关闭
  15. const ACTIVITY_STATUS_DELETED = 7; // 已删除
  16. const ACTIVITY_STATUS_EXPIRED = 8; // 已过期
  17. // ============ 活动类型 ============
  18. const ACTIVITY_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 REDEEM_EXPIRE_FOREVER = 1; // 永久有效
  62. const REDEEM_EXPIRE_FIXED = 2; // 固定时长
  63. /**
  64. * 获取活动状态映射(页面显示用)
  65. */
  66. public static function getActivityStatusMap()
  67. {
  68. return [
  69. self::ACTIVITY_STATUS_NOT_STARTED => '未开始',
  70. self::ACTIVITY_STATUS_ONGOING => '进行中',
  71. self::ACTIVITY_STATUS_ENDED => '已结束',
  72. self::ACTIVITY_STATUS_CANCELLED => '已取消',
  73. self::ACTIVITY_STATUS_SUSPENDED => '已暂停',
  74. ];
  75. }
  76. /**
  77. * 获取全部活动状态映射(包含逻辑状态)
  78. */
  79. public static function getAllActivityStatusMap()
  80. {
  81. return [
  82. self::ACTIVITY_STATUS_NOT_STARTED => '未开始',
  83. self::ACTIVITY_STATUS_ONGOING => '进行中',
  84. self::ACTIVITY_STATUS_ENDED => '已结束',
  85. self::ACTIVITY_STATUS_CANCELLED => '已取消',
  86. self::ACTIVITY_STATUS_SUSPENDED => '已暂停',
  87. self::ACTIVITY_STATUS_CLOSED => '已关闭',
  88. self::ACTIVITY_STATUS_DELETED => '已删除',
  89. self::ACTIVITY_STATUS_EXPIRED => '已过期',
  90. ];
  91. }
  92. /**
  93. * 获取活动类型映射
  94. */
  95. public static function getActivityTypeMap()
  96. {
  97. return [
  98. self::ACTIVITY_TYPE_CONSUMPTION_LOTTERY => '消费抽奖',
  99. ];
  100. }
  101. /**
  102. * 获取开奖方式映射
  103. */
  104. public static function getLotteryTypeMap()
  105. {
  106. return [
  107. self::LOTTERY_TYPE_INSTANT => '即抽即中',
  108. self::LOTTERY_TYPE_TIME => '按时间开奖',
  109. self::LOTTERY_TYPE_PEOPLE => '按人数开奖',
  110. ];
  111. }
  112. /**
  113. * 获取用户群体类型映射
  114. */
  115. public static function getUserLimitTypeMap()
  116. {
  117. return [
  118. self::USER_LIMIT_ALL => '全部会员',
  119. self::USER_LIMIT_LEVEL => '会员等级',
  120. self::USER_LIMIT_TAG => '会员标签',
  121. ];
  122. }
  123. /**
  124. * 获取引导样式映射
  125. */
  126. public static function getGuideStyleMap()
  127. {
  128. return [
  129. self::GUIDE_STYLE_DEFAULT => '默认样式',
  130. self::GUIDE_STYLE_CUSTOM => '自定义',
  131. ];
  132. }
  133. /**
  134. * 获取奖品类型映射
  135. */
  136. public static function getPrizeTypeMap()
  137. {
  138. return [
  139. self::PRIZE_TYPE_NO_PRIZE => '未中奖',
  140. self::PRIZE_TYPE_GOODS => '实物奖品',
  141. self::PRIZE_TYPE_POINTS => '积分',
  142. self::PRIZE_TYPE_BALANCE => '余额',
  143. self::PRIZE_TYPE_COUPON => '优惠券',
  144. self::PRIZE_TYPE_REDPACK => '红包',
  145. self::PRIZE_TYPE_CODE => '兑换码',
  146. self::PRIZE_TYPE_SHOP_GOODS => '商城奖品',
  147. ];
  148. }
  149. /**
  150. * 获取奖品默认图片映射
  151. */
  152. public static function getPrizeDefaultImageMap()
  153. {
  154. // 从配置文件获取图片路径
  155. $config = config('site');
  156. return [
  157. self::PRIZE_TYPE_NO_PRIZE => $config['prize_losing_lottery'] ?? '/assets/img/avatar.png',
  158. self::PRIZE_TYPE_GOODS => $config['prize_goods'] ?? '/assets/img/package.png',
  159. self::PRIZE_TYPE_POINTS => $config['prize_credit'] ?? '/assets/img/circle.png',
  160. self::PRIZE_TYPE_BALANCE => $config['prize_balance'] ?? '/assets/img/circle.png',
  161. self::PRIZE_TYPE_COUPON => $config['prize_coupon'] ?? '/assets/img/circle.png',
  162. self::PRIZE_TYPE_REDPACK => $config['prize_redbag'] ?? '/assets/img/circle.png',
  163. self::PRIZE_TYPE_CODE => $config['prize_code'] ?? '/assets/img/circle.png',
  164. self::PRIZE_TYPE_SHOP_GOODS => $config['prize_shop_goods'] ?? '/assets/img/package.png',
  165. ];
  166. }
  167. /**
  168. * 获取奖品发放方式映射
  169. */
  170. public static function getDeliverTypeMap()
  171. {
  172. return [
  173. self::DELIVER_TYPE_AUTO => '自动发放',
  174. self::DELIVER_TYPE_MANUAL => '手动发放',
  175. ];
  176. }
  177. /**
  178. * 获取奖品发放状态映射
  179. */
  180. public static function getDeliverStatusMap()
  181. {
  182. return [
  183. self::DELIVER_STATUS_PENDING => '待发放',
  184. self::DELIVER_STATUS_SUCCESS => '已发放',
  185. self::DELIVER_STATUS_FAILED => '发放失败',
  186. self::DELIVER_STATUS_CANCELLED => '已取消',
  187. ];
  188. }
  189. /**
  190. * 获取参与条件类型映射
  191. */
  192. public static function getConditionTypeMap()
  193. {
  194. return [
  195. self::CONDITION_TYPE_BUY_GOODS => '购买指定商品',
  196. self::CONDITION_TYPE_ORDER_AMOUNT => '单笔订单消费满N元',
  197. self::CONDITION_TYPE_RECHARGE_AMOUNT => '单次充值金额满N元',
  198. self::CONDITION_TYPE_TOTAL_AMOUNT => '活动期间累计消费N元',
  199. ];
  200. }
  201. /**
  202. * 获取商品规则映射
  203. */
  204. public static function getGoodsRuleMap()
  205. {
  206. return [
  207. self::GOODS_RULE_INCLUDE => '指定商品参与',
  208. self::GOODS_RULE_EXCLUDE => '指定商品不可参与',
  209. ];
  210. }
  211. /**
  212. * 获取触发类型映射
  213. */
  214. public static function getTriggerTypeMap()
  215. {
  216. return [
  217. self::TRIGGER_TYPE_BUY_GOODS => '购买商品',
  218. self::TRIGGER_TYPE_ORDER_CONSUME => '订单消费',
  219. self::TRIGGER_TYPE_RECHARGE => '充值',
  220. self::TRIGGER_TYPE_TOTAL_CONSUME => '累计消费',
  221. ];
  222. }
  223. /**
  224. * 获取兑奖期限类型映射
  225. */
  226. public static function getRedeemExpireTypeMap()
  227. {
  228. return [
  229. self::REDEEM_EXPIRE_FOREVER => '永久有效',
  230. self::REDEEM_EXPIRE_FIXED => '固定时长',
  231. ];
  232. }
  233. /**
  234. * 获取活动状态文本
  235. */
  236. public static function getActivityStatusText($status)
  237. {
  238. $map = self::getAllActivityStatusMap();
  239. return $map[$status] ?? '未知';
  240. }
  241. /**
  242. * 获取奖品类型文本
  243. */
  244. public static function getPrizeTypeText($type)
  245. {
  246. $map = self::getPrizeTypeMap();
  247. return $map[$type] ?? '未知';
  248. }
  249. /**
  250. * 获取开奖方式文本
  251. */
  252. public static function getLotteryTypeText($type)
  253. {
  254. $map = self::getLotteryTypeMap();
  255. return $map[$type] ?? '未知';
  256. }
  257. /**
  258. * 获取条件类型文本
  259. */
  260. public static function getConditionTypeText($type)
  261. {
  262. $map = self::getConditionTypeMap();
  263. return $map[$type] ?? '未知';
  264. }
  265. /**
  266. * 验证活动状态是否有效(包含所有状态)
  267. */
  268. public static function isValidActivityStatus($status)
  269. {
  270. return array_key_exists($status, self::getAllActivityStatusMap());
  271. }
  272. /**
  273. * 判断是否为可在页面显示的状态
  274. */
  275. public static function isDisplayableStatus($status)
  276. {
  277. return array_key_exists($status, self::getActivityStatusMap());
  278. }
  279. /**
  280. * 判断是否为逻辑状态(不在页面显示)
  281. */
  282. public static function isLogicalStatus($status)
  283. {
  284. return in_array($status, [
  285. self::ACTIVITY_STATUS_CLOSED,
  286. self::ACTIVITY_STATUS_DELETED,
  287. self::ACTIVITY_STATUS_EXPIRED
  288. ]);
  289. }
  290. /**
  291. * 验证奖品类型是否有效
  292. */
  293. public static function isValidPrizeType($type)
  294. {
  295. return array_key_exists($type, self::getPrizeTypeMap());
  296. }
  297. /**
  298. * 验证开奖方式是否有效
  299. */
  300. public static function isValidLotteryType($type)
  301. {
  302. return array_key_exists($type, self::getLotteryTypeMap());
  303. }
  304. /**
  305. * 验证条件类型是否有效
  306. */
  307. public static function isValidConditionType($type)
  308. {
  309. return array_key_exists($type, self::getConditionTypeMap());
  310. }
  311. }