WH01243 2 жил өмнө
parent
commit
742f3dc8c6

+ 2 - 1
entity/activity.go

@@ -67,7 +67,8 @@ type LotteryJson struct {
 	Name             string        `xorm:"name" form:"name" json:"name"`                                     //奖券名字
 	Count            int64         `xorm:"count" form:"count" json:"count"`                                  //领取次数
 	DayCount         int64         `xorm:"dayCount" form:"dayCount" json:"dayCount"`                         //领取次数
-	UserCount        int64         `xorm:"UserCount" form:"UserCount" json:"UserCount"`                      //使用次数
+	UserCount        int64         `xorm:"userCount" form:"userCount" json:"userCount"`                      //使用次数
+	AllUserCount     int64         `xorm:"allUserCount" form:"allUserCount" json:"allUserCount"`             //领取次数
 	UseProduct       string        `xorm:"useProduct" form:"useProduct" json:"useProduct"`                   //使用商品
 	UseProductList   []ProductJson `xorm:"useProductList" form:"useProductList" json:"useProductList"`       //使用商品列表
 	StockNumber      int64         `xorm:"stockNumber" form:"stockNumber" json:"stockNumber"`                //库存

+ 59 - 40
rpc/internal/logic/getallactivitylogic.go

@@ -2,6 +2,7 @@ package logic
 
 import (
 	"app.yhyue.com/moapp/jyMarketing/util"
+	"app.yhyue.com/moapp/jybase/common"
 	"context"
 	"time"
 
@@ -31,79 +32,97 @@ func (l *GetAllActivityLogic) GetAllActivity(in *activity.Request) (*activity.Ac
 	code, msg, activityData := activityServiceNew.GetAllActivity(in)
 	var activityArr []*activity.ActivityJson
 	for _, activityValue := range activityData {
-		activityJson := activity.ActivityJson{}
+		activityEntity := activity.ActivityJson{}
 		timeBool := util.ActivityTime(activityValue.BeginDate) && !util.ActivityTimeOther(activityValue.EndDate)
-		var userLotteryList []*activity.LotteryJson
+		var lotteryList []*activity.LotteryJson
 		for _, value := range activityValue.LotteryData {
-			userLottery := activity.LotteryJson{}
-			userLottery.LotteryId = value.LotteryId
-			userLottery.LotteryName = value.Name
-			userLottery.IsReceive = false
+			lottery := activity.LotteryJson{}
+			lottery.LotteryId = value.LotteryId
+			lottery.LotteryName = value.Name
+			lottery.IsReceive = false
 			//IsReceive  是否可以领取true可以领取false不可领取
 			//IsUser  是否使用 true 使用 false未使用
 			if activityValue.ActivityType < 2 {
 				if timeBool {
 					if value.StockNumber == 0 {
 						//库存不足
-						userLottery.IsReceive = false
+						lottery.IsReceive = false
 					} else {
 						//还有库存
-						if value.Count > 0 {
-							userLottery.IsReceive = false
+						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 {
-							userLottery.IsReceive = true
+							if value.UserCount == 0 {
+								lottery.IsReceive = true
+							}
 						}
 					}
 				}
-				userLottery.IsUser = false
+				lottery.IsUser = false
 				if value.UserCount > 0 {
-					userLottery.IsUser = true
+					lottery.IsUser = true
 				}
-				userLottery.LotteryBeginDate = value.BeginDate
-				userLottery.LotteryendDate = value.EndDate
+				lottery.LotteryBeginDate = value.BeginDate
+				lottery.LotteryendDate = value.EndDate
 			} else {
-				userLottery.PromotionalPrice = value.PromotionalPrice
-				userLottery.GiftCode = value.GiftCode
+				if timeBool {
+					if value.StockNumber == 0 {
+						//库存不足
+						lottery.IsReceive = false
+					} else {
+						lottery.IsReceive = true
+					}
+				}
+				lottery.PromotionalPrice = value.PromotionalPrice
+				lottery.GiftCode = value.GiftCode
 			}
-			userLottery.LotteryType = value.LotteryType
-			userLottery.Instructions = value.Instructions
-			userLottery.StockNumber = value.StockNumber
-			userLottery.ReceiveNumber = value.ReceiveNumber
-			userLottery.Full = value.Full
-			userLottery.Reduce = value.Reduce
-			userLottery.Remark = value.Remark
-			userLottery.Discount = float32(value.Discount)
-			userLotteryList = append(userLotteryList, &userLottery)
+			lottery.LotteryType = value.LotteryType
+			lottery.Instructions = value.Instructions
+			lottery.StockNumber = value.StockNumber
+			lottery.ReceiveNumber = value.ReceiveNumber
+			lottery.Full = value.Full
+			lottery.Reduce = value.Reduce
+			lottery.Remark = value.Remark
+			lottery.Discount = float32(value.Discount)
+			lotteryList = append(lotteryList, &lottery)
 		}
-		activityJson.LotteryJson = userLotteryList
+		activityEntity.LotteryJson = lotteryList
 		endDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.EndDate, time.Local)
-		activityJson.ActivityendDate = endDate.Format("2006年01月02日 15时04分05秒")
+		activityEntity.ActivityendDate = endDate.Format("2006年01月02日 15时04分05秒")
 		beginDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.BeginDate, time.Local)
-		activityJson.ActivityBeginDate = beginDate.Format("2006年01月02日 15时04分05秒")
-		activityJson.ActivityName = activityValue.Name
-		activityJson.ActivityDesc = activityValue.ActivityDesc
-		activityJson.ReceivingLocation = activityValue.ReceivingLocation
+		activityEntity.ActivityBeginDate = beginDate.Format("2006年01月02日 15时04分05秒")
+		activityEntity.ActivityName = activityValue.Name
+		activityEntity.ActivityDesc = activityValue.ActivityDesc
+		activityEntity.ReceivingLocation = activityValue.ReceivingLocation
 		switch activityValue.ActivityType {
 		case 0:
-			activityJson.ActivityType = "满减券"
+			activityEntity.ActivityType = "满减券"
 		case 1:
-			activityJson.ActivityType = "满折券"
+			activityEntity.ActivityType = "满折券"
 		case 2:
-			activityJson.ActivityType = "满赠"
+			activityEntity.ActivityType = "满赠"
 		case 3:
-			activityJson.ActivityType = "促销"
+			activityEntity.ActivityType = "促销"
 		case 4:
-			activityJson.ActivityType = "限时折扣"
+			activityEntity.ActivityType = "限时折扣"
 		case 5:
-			activityJson.ActivityType = "限时减免"
+			activityEntity.ActivityType = "限时减免"
 		}
 		if activityValue.PreheatingTime == "" {
-			activityJson.PreheatingTime = 0
+			activityEntity.PreheatingTime = 0
 		} else {
 			PreheatingTime, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.PreheatingTime, time.Local)
-			activityJson.PreheatingTime = PreheatingTime.Unix()
+			activityEntity.PreheatingTime = PreheatingTime.Unix()
 		}
-		activityArr = append(activityArr, &activityJson)
+		activityArr = append(activityArr, &activityEntity)
 	}
 	result.Code = code
 	result.Message = msg

+ 3 - 1
service/activityServiceNew.go

@@ -60,12 +60,14 @@ func (service *ActivityServiceNew) GetAllActivity(in *activity.Request) (int64,
 				logx.Info("用户不在该分组中:", err)
 				continue
 			}
+		} else if userRange == int64(3) {
+			//新用户
 		}
 		if activityType < 2 {
 			//赠品、限时活动之外的活动
 			//2、先查找活动下的奖品Id
 			err = orm.Table("activity").Alias("a").
-				Select("l.discount,( SELECT count( up.id ) FROM user_prize up WHERE up.lotteryId = l.id  and  up.prizeId!=0 and   up.userId ='"+in.UserId+"' and up.prizeType=0 ) AS usercount,p.prizeType as lotteryType,l.full,l.reduce, p.beginDate,p.endDate,l.stockNumber,l.receiveNumber,p.limitNumber,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id  and  up.prizeId!=0 AND up.userId ='"+in.UserId+"' ) AS count,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id  and  up.prizeId!=0 AND up.userId ='"+in.UserId+"' and  to_days(createTime) = to_days(now())) AS daycount,p.isLimitNumber,p.validityTimeType,p.validityDates,p.instructions,p.remark,l.id as lotteryId ,l.name ").
+				Select("l.discount,( SELECT count( up.id ) FROM user_prize up WHERE up.lotteryId = l.id  and  up.prizeId!=0 and   up.userId ='"+in.UserId+"' and (up.prizeType=0 or up.prizeType=3)) AS usercount,( SELECT count( up.id ) FROM user_prize up WHERE up.lotteryId = l.id  and  up.prizeId!=0 and   up.userId ='\"+in.UserId+\"'  ) AS allUsercount,p.prizeType as lotteryType,l.full,l.reduce, p.beginDate,p.endDate,l.stockNumber,l.receiveNumber,p.limitNumber,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id  and  up.prizeId!=0 AND up.userId ='"+in.UserId+"' ) AS count,( select  count(up.id) FROM user_prize up where  up.lotteryId = l.id  and  up.prizeId!=0 AND up.userId ='"+in.UserId+"' and  to_days(createTime) = to_days(now())) AS daycount,p.isLimitNumber,p.validityTimeType,p.validityDates,p.instructions,p.remark,l.id as lotteryId ,l.name ").
 				Join("left", "discount d", "d.activityId=a.id and  d.state=1").
 				Join("left", "prize p", "d.prizeId=p.id").
 				Join("left", "lottery l", " l.id = d.lotteryId  ").