getallactivitylogic.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyMarketing/util"
  4. "app.yhyue.com/moapp/jybase/common"
  5. "context"
  6. "time"
  7. "app.yhyue.com/moapp/jyMarketing/rpc/activity"
  8. "app.yhyue.com/moapp/jyMarketing/rpc/internal/svc"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetAllActivityLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetAllActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllActivityLogic {
  17. return &GetAllActivityLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 商品下活动获取
  24. func (l *GetAllActivityLogic) GetAllActivity(in *activity.Request) (*activity.ActivityResp, error) {
  25. result := &activity.ActivityResp{}
  26. code, msg, activityData := activityServiceNew.GetAllActivity(in)
  27. var activityArr []*activity.ActivityJson
  28. for _, activityValue := range activityData {
  29. activityEntity := activity.ActivityJson{}
  30. timeBool := util.ActivityTime(activityValue.BeginDate) && !util.ActivityTimeOther(activityValue.EndDate) && util.ActivityTime(activityValue.PreheatingTime)
  31. var lotteryList []*activity.LotteryJson
  32. for _, value := range activityValue.LotteryData {
  33. lottery := activity.LotteryJson{}
  34. lottery.LotteryId = value.LotteryId
  35. lottery.LotteryName = value.Name
  36. lottery.IsReceive = false
  37. //IsReceive 是否可以领取true可以领取false不可领取
  38. //IsUser 是否使用 true 使用 false未使用
  39. if activityValue.ActivityType < 2 {
  40. //活动已开始 时间判断 剩余量判断
  41. if timeBool {
  42. if value.StockNumber == 0 {
  43. //库存不足
  44. lottery.IsReceive = false
  45. } else {
  46. //还有库存
  47. if value.IsLimitNumber == 0 {
  48. if value.Count > 0 {
  49. lottery.IsReceive = false
  50. } else {
  51. if value.AllUserCount >= common.Int64All(value.LimitNumber) {
  52. lottery.IsReceive = false
  53. } else {
  54. if value.UserCount >= common.Int64All(value.LimitNumber) {
  55. } else {
  56. lottery.IsReceive = true
  57. }
  58. }
  59. }
  60. } else {
  61. if value.Count > 0 {
  62. if value.UserCount == 0 {
  63. lottery.IsReceive = true
  64. }
  65. }
  66. }
  67. }
  68. } else {
  69. //活动未开始
  70. lottery.IsReceive = false
  71. }
  72. //奖券领取线坠
  73. lottery.IsUser = false
  74. if value.UserCount > 0 {
  75. lottery.IsUser = true
  76. }
  77. lottery.LotteryBeginDate = value.BeginDate
  78. lottery.LotteryendDate = value.EndDate
  79. } else {
  80. //其他奖券领取限制
  81. /*if timeBool {
  82. if value.StockNumber == 0 {
  83. //库存不足
  84. lottery.IsReceive = false
  85. } else {
  86. lottery.IsReceive = true
  87. }
  88. }*/
  89. lottery.IsReceive = false
  90. lottery.PromotionalPrice = value.PromotionalPrice
  91. lottery.GiftCode = value.GiftCode
  92. }
  93. lottery.LotteryType = value.LotteryType
  94. lottery.Instructions = value.Instructions
  95. lottery.StockNumber = value.StockNumber
  96. lottery.ReceiveNumber = value.ReceiveNumber
  97. lottery.Full = value.Full
  98. lottery.Reduce = value.Reduce
  99. lottery.Remark = value.Remark
  100. lottery.Discount = float32(value.Discount)
  101. lotteryList = append(lotteryList, &lottery)
  102. }
  103. activityEntity.LotteryJson = lotteryList
  104. endDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.EndDate, time.Local)
  105. activityEntity.ActivityendDate = endDate.Format("2006年01月02日 15时04分05秒")
  106. beginDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.BeginDate, time.Local)
  107. activityEntity.ActivityBeginDate = beginDate.Format("2006年01月02日 15时04分05秒")
  108. activityEntity.ActivityName = activityValue.Name
  109. activityEntity.ActivityDesc = activityValue.ActivityDesc
  110. activityEntity.ReceivingLocation = activityValue.ReceivingLocation
  111. switch activityValue.ActivityType {
  112. case 0:
  113. activityEntity.ActivityType = "满减券"
  114. case 1:
  115. activityEntity.ActivityType = "满折券"
  116. case 2:
  117. activityEntity.ActivityType = "满赠"
  118. case 3:
  119. activityEntity.ActivityType = "促销"
  120. case 4:
  121. activityEntity.ActivityType = "限时折扣"
  122. case 5:
  123. activityEntity.ActivityType = "限时减免"
  124. }
  125. if activityValue.PreheatingTime == "" {
  126. activityEntity.PreheatingTime = 0
  127. } else {
  128. PreheatingTime, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.PreheatingTime, time.Local)
  129. activityEntity.PreheatingTime = PreheatingTime.Unix()
  130. }
  131. activityArr = append(activityArr, &activityEntity)
  132. }
  133. result.Code = code
  134. result.Message = msg
  135. result.ActivityJson = activityArr
  136. return result, nil
  137. }