Browse Source

满减卷预热活动处理

WH01243 2 years ago
parent
commit
c0b9de4b0f
3 changed files with 73 additions and 19 deletions
  1. 25 18
      rpc/internal/logic/getallactivitylogic.go
  2. 47 0
      service/activityService.go
  3. 1 1
      service/activityServiceNew.go

+ 25 - 18
rpc/internal/logic/getallactivitylogic.go

@@ -43,30 +43,36 @@ func (l *GetAllActivityLogic) GetAllActivity(in *activity.Request) (*activity.Ac
 			//IsReceive  是否可以领取true可以领取false不可领取
 			//IsUser  是否使用 true 使用 false未使用
 			if activityValue.ActivityType < 2 {
-				//奖券领取线坠
-				if timeBool {
-					if value.StockNumber == 0 {
-						//库存不足
-						lottery.IsReceive = false
-					} else {
-						//还有库存
-						if value.IsLimitNumber == 0 {
-							if value.AllUserCount >= common.Int64All(value.LimitNumber) {
-								lottery.IsReceive = false
-							} else {
-								if value.UserCount >= common.Int64All(value.LimitNumber) {
+				if util.ActivityTime(activityValue.PreheatingTime) {
+					//活动已开始 时间判断  剩余量判断
+					if timeBool {
+						if value.StockNumber == 0 {
+							//库存不足
+							lottery.IsReceive = false
+						} else {
+							//还有库存
+							if value.IsLimitNumber == 0 {
+								if value.AllUserCount >= common.Int64All(value.LimitNumber) {
 									lottery.IsReceive = false
 								} else {
+									if value.UserCount >= common.Int64All(value.LimitNumber) {
+										lottery.IsReceive = false
+									} else {
+										lottery.IsReceive = true
+									}
+								}
+							} else {
+								if value.UserCount == 0 {
 									lottery.IsReceive = true
 								}
 							}
-						} else {
-							if value.UserCount == 0 {
-								lottery.IsReceive = true
-							}
 						}
 					}
+				} else {
+					//活动未开始
+					lottery.IsReceive = false
 				}
+				//奖券领取线坠
 				lottery.IsUser = false
 				if value.UserCount > 0 {
 					lottery.IsUser = true
@@ -75,14 +81,15 @@ func (l *GetAllActivityLogic) GetAllActivity(in *activity.Request) (*activity.Ac
 				lottery.LotteryendDate = value.EndDate
 			} else {
 				//其他奖券领取限制
-				if timeBool {
+				/*if timeBool {
 					if value.StockNumber == 0 {
 						//库存不足
 						lottery.IsReceive = false
 					} else {
 						lottery.IsReceive = true
 					}
-				}
+				}*/
+				lottery.IsReceive = false
 				lottery.PromotionalPrice = value.PromotionalPrice
 				lottery.GiftCode = value.GiftCode
 			}

+ 47 - 0
service/activityService.go

@@ -261,6 +261,7 @@ func (service *ActivityService) UserLottery(data *activity.Request) (int64, stri
 			FindAndCount(&userLotteryList)
 		//其他查询
 		NoLotteryHandle(data.ProductCode, data.UserId, data.AppId, &userLotteryList)
+		LotteryWaitHandle(data.ProductCode, data.UserId, data.AppId, &userLotteryList)
 	case 0:
 		//查看名下所有奖券
 		count, err = orm.Table("user_prize").Alias("up").Select("DISTINCT up.activityId, d.useProductList as  userProduct,up.*,p.instructions,p.remark,p.prizeType as activityType").
@@ -881,6 +882,52 @@ func NoLotteryHandle(productCode, userId, appId string, userPrice *[]entity.User
 		}
 	}
 }
+func LotteryWaitHandle(productCode, userId, appId string, userPrice *[]entity.UserPrizeJson) {
+	productQuery := "and  1=1 "
+	if productCode != "" {
+		productQuery = "and ( p.productCode=" + productCode + " )"
+	}
+	orm := entity.Engine.NewSession()
+	//var err error
+	//没有商品标识时处理
+	// 判断活动是否为全部用户参加
+	nowStr := time.Now().Format("2006-01-02 15:04:05")
+	activityList := []entity.Activity{}
+	err := orm.Table("activity").Alias("a").Select(" DISTINCT a.*").
+		Join("left", "discount d", "d.activityId = a.id").
+		Join("left", "product p", "FIND_IN_SET(p.ProductCode,d.useProductList )").
+		Where("a.activityType < 2 and a.state=1  and  a.preheatingTime  is not  null and   a.beginDate>?  and a.endDate>=? "+productQuery, nowStr, nowStr).Find(&activityList)
+	if len(activityList) == 0 {
+		return
+	}
+	for _, value := range activityList {
+		//分组判断处理
+		if !UserGroupingHandle(value.UserRange, userId, value.UserGroupId, "", "", "") {
+			continue
+		}
+		//预热已经开始
+		if !util.ActivityTime(value.PreheatingTime) || util.ActivityTime(value.BeginDate) {
+			continue
+		}
+		oneuserPrice := []entity.UserPrizeJson{}
+		err = orm.Table("activity").Alias("a").Select("DISTINCT a.id as activityId, a.name as activityName,a.beginDate as activityBeginDate,a.endDate as activityEndDate ,d.stockNumber, a.activityType,a.beginDate ,a.endDate,l.full ,d.promotionalPrice,l.discount,l.reduce,d.useProductList as  userProduct,a.preheatingTime,a.activityDesc,d.id as lotteryId").
+			Join("left", " discount d", "d.activityId = a.id ").
+			Join("left", "lottery  l ", "l.id=d.lotteryId").
+			Join("left", "product p", "FIND_IN_SET(p.ProductCode,d.useProductList )").
+			Where(" a.id=?  "+productQuery+" AND a.activityType < 2 AND a.appId = ?  and  a.state=1 and d.state=1 ", value.Id, appId).
+			Find(&oneuserPrice)
+		//先查找产品参与的活动
+		if err != nil {
+			logx.Info("用户下的奖券查询失败:", err)
+			continue
+		}
+		for _, prizeJson := range oneuserPrice {
+			*userPrice = append(*userPrice, prizeJson)
+		}
+	}
+}
+
+//有券预热开始活动未开始
 
 //分组计算
 func UserGroupingHandle(userRange int64, userId, userGroupId string, startTime, endTime, preheatingTime string) bool {

+ 1 - 1
service/activityServiceNew.go

@@ -74,7 +74,7 @@ func (service *ActivityServiceNew) GetAllActivity(in *activity.Request) (int64,
 			orm := entity.Engine
 			//先查找产品参与的活动
 			var giftData = []entity.LotteryJson{}
-			err = orm.Table("activity").Alias("a").Select("DISTINCT  d.stockNumber,d.promotionalPrice,d.discount,d.reduce,p.productCode,g.giftCode,g.parentCode,g.name,g.time,g.timeType,d.id as lotteryId").
+			err = orm.Table("activity").Alias("a").Select("DISTINCT  d.stockNumber,d.promotionalPrice,d.discount,d.reduce,g.giftCode,g.parentCode,g.name,g.time,g.timeType,d.id as lotteryId").
 				Join("left", " discount d", "d.activityId = a.id ").
 				Join("left", "gift g ", "g.giftCode=d.giftCode").
 				Join("left", "product p", "FIND_IN_SET(p.ProductCode,d.useProductList)").