getallactivitylogic.go 4.1 KB

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