getallactivitylogic.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. lottery.IsReceive = false
  63. } else {
  64. if value.UserCount == 0 {
  65. lottery.IsReceive = true
  66. }
  67. }
  68. }
  69. }
  70. } else {
  71. //活动未开始
  72. lottery.IsReceive = false
  73. }
  74. //奖券领取线坠
  75. lottery.IsUser = false
  76. if value.UserCount > 0 {
  77. lottery.IsUser = true
  78. }
  79. lottery.LotteryBeginDate = value.BeginDate.Format("2006-01-02 15:04:05")
  80. lottery.LotteryendDate = value.EndDate.Format("2006-01-02 15:04:05")
  81. } else {
  82. //其他奖券领取限制
  83. /*if timeBool {
  84. if value.StockNumber == 0 {
  85. //库存不足
  86. lottery.IsReceive = false
  87. } else {
  88. lottery.IsReceive = true
  89. }
  90. }*/
  91. lottery.IsReceive = false
  92. lottery.PromotionalPrice = value.PromotionalPrice
  93. lottery.GiftCode = value.GiftCode
  94. }
  95. lottery.LotteryType = value.LotteryType
  96. lottery.Instructions = value.Instructions
  97. lottery.StockNumber = value.StockNumber
  98. lottery.ReceiveNumber = value.ReceiveNumber
  99. lottery.Full = value.Full
  100. lottery.Reduce = value.Reduce
  101. lottery.Remark = value.Remark
  102. lottery.Discount = float32(value.Discount)
  103. lotteryList = append(lotteryList, &lottery)
  104. }
  105. activityEntity.LotteryJson = lotteryList
  106. endDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.EndDate, time.Local)
  107. activityEntity.ActivityendDate = endDate.Format("2006年01月02日 15时04分05秒")
  108. beginDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.BeginDate, time.Local)
  109. activityEntity.ActivityBeginDate = beginDate.Format("2006年01月02日 15时04分05秒")
  110. activityEntity.ActivityName = activityValue.Name
  111. activityEntity.ActivityDesc = activityValue.ActivityDesc
  112. activityEntity.ReceivingLocation = activityValue.ReceivingLocation
  113. switch activityValue.ActivityType {
  114. case 0:
  115. activityEntity.ActivityType = "满减券"
  116. case 1:
  117. activityEntity.ActivityType = "满折券"
  118. case 2:
  119. activityEntity.ActivityType = "满赠"
  120. case 3:
  121. activityEntity.ActivityType = "促销"
  122. case 4:
  123. activityEntity.ActivityType = "限时折扣"
  124. case 5:
  125. activityEntity.ActivityType = "限时减免"
  126. }
  127. if activityValue.PreheatingTime == "" {
  128. activityEntity.PreheatingTime = 0
  129. } else {
  130. PreheatingTime, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.PreheatingTime, time.Local)
  131. activityEntity.PreheatingTime = PreheatingTime.Unix()
  132. }
  133. activityArr = append(activityArr, &activityEntity)
  134. }
  135. result.Code = code
  136. result.Message = msg
  137. result.ActivityJson = activityArr
  138. return result, nil
  139. }