Coupon.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package cn.seecoder.courselearning.po.coupon;
  2. import cn.seecoder.courselearning.enums.CouponScope;
  3. import cn.seecoder.courselearning.enums.CouponType;
  4. import cn.seecoder.courselearning.vo.coupon.CouponVO;
  5. import lombok.AccessLevel;
  6. import lombok.Data;
  7. import lombok.Getter;
  8. import lombok.NoArgsConstructor;
  9. import java.time.LocalDateTime;
  10. @Data
  11. @NoArgsConstructor
  12. public class Coupon {
  13. /**
  14. * 优惠券id
  15. */
  16. private Integer id;
  17. /**
  18. * 优惠券类型
  19. */
  20. private CouponType type;
  21. /**
  22. * 优惠券使用范围
  23. */
  24. private CouponScope scope;
  25. /**
  26. * 优惠券名称
  27. */
  28. private String name;
  29. /**
  30. * 优惠券描述
  31. */
  32. private String description;
  33. /**
  34. * 优惠券元数据,对不同的优惠券类型,优惠券发放策略,优惠券使用范围不同,格式为JSON字符串
  35. * 如优惠券类型为满减,这里的元数据可以是{"threshold": 100, "cutDown": 20}表示满100减20的优惠券
  36. * 如优惠券类型为折扣,这里的元数据可以是{"discount": 0.8}表示打八折
  37. * 格式很自由,可以自定义数据,如自定义优惠券为满200减50,低于200打95折,这里则存储着优惠券类型会使用到的数据
  38. */
  39. private String metadata;
  40. /**
  41. * 生效时间
  42. */
  43. private LocalDateTime startTime;
  44. /**
  45. * 失效时间
  46. */
  47. private LocalDateTime endTime;
  48. /**
  49. * 优惠券是否可用 true可用 false失效(一次性的券使用后就失效 或 网站关闭活动)
  50. */
  51. @Getter(AccessLevel.NONE)
  52. private Boolean valid;
  53. /**
  54. * 能否与其他优惠券同时使用 true可同时使用 false不能同时使用
  55. */
  56. @Getter(AccessLevel.NONE)
  57. private Boolean sharable;
  58. public Boolean isValid() {
  59. return valid;
  60. }
  61. public Boolean isSharable() {
  62. return sharable;
  63. }
  64. public Coupon(CouponVO couponVO) {
  65. this.id = couponVO.getId();
  66. this.type = CouponType.valueOf(couponVO.getType());
  67. this.scope = CouponScope.valueOf(couponVO.getScope());
  68. this.name = couponVO.getName();
  69. this.description = couponVO.getDescription();
  70. this.metadata = couponVO.getMetadata();
  71. this.startTime = couponVO.getStartTime();
  72. this.endTime = couponVO.getEndTime();
  73. this.valid = couponVO.isValid();
  74. this.sharable = couponVO.isSharable();
  75. }
  76. }