|
@@ -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 {
|