getallactivitylogic.go 4.2 KB

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