|
@@ -106,7 +106,6 @@ func (service *ActivityService) LotteryReceive(data *activity.LotteryOperation,
|
|
|
orm.Rollback()
|
|
|
return entity.ErrorCode, "领取奖券失败"
|
|
|
}
|
|
|
-
|
|
|
//6、修改奖券余额数量
|
|
|
lottery := entity.Lottery{}
|
|
|
lottery.Id = lotteryId
|
|
@@ -131,7 +130,6 @@ func (service *ActivityService) LotteryReceive(data *activity.LotteryOperation,
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "奖券领取成功"
|
|
|
}
|
|
|
-
|
|
|
//奖券使用
|
|
|
func (service *ActivityService) ActivityUse(data *activity.LotteryOperation) (int64, string) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -179,13 +177,10 @@ func (service *ActivityService) ActivityUse(data *activity.LotteryOperation) (in
|
|
|
orm.Rollback()
|
|
|
return entity.ErrorCode, "修改奖券使用数量失败"
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "使用奖券成功"
|
|
|
}
|
|
|
-
|
|
|
//活动下的奖券
|
|
|
func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, string, []entity.LotteryJson) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -199,14 +194,13 @@ func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, st
|
|
|
Join("left", "lottery l", " l.prizeId = p.id ").
|
|
|
Where("a.id = ? and a.appId=? ", in.ActivityId, in.AppId).Find(&lotteryJsonList)
|
|
|
if err != nil {
|
|
|
- log.Println("用户单位下的奖券查询失败:", err)
|
|
|
+ log.Println("用户下的奖券查询失败:", err)
|
|
|
orm.Rollback()
|
|
|
- return entity.ErrorCode, "用户单位下的奖券查询失败", lotteryJsonList
|
|
|
+ return entity.ErrorCode, "用户下的奖券查询失败", lotteryJsonList
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "活动下的奖券", lotteryJsonList
|
|
|
}
|
|
|
-
|
|
|
//用户下的奖券(不包含待使用的 )
|
|
|
func (service *ActivityService) UserLottery(data *activity.Request) (int64, string, []entity.UserPrizeJson, int64) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -218,11 +212,16 @@ func (service *ActivityService) UserLottery(data *activity.Request) (int64, stri
|
|
|
switch data.Model {
|
|
|
case 0:
|
|
|
//查看可以使用的奖券(没有过期的)
|
|
|
+ condition:=""
|
|
|
+ if data.Model!=0{
|
|
|
+ condition="( up.prizeType=0 or up.id="+data.Model+") "
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
count, err = orm.Table("user_prize").Alias("up").Select("up.*,a.useProductList").
|
|
|
Join("left", "activity a ", "a.prizeId=up.prizeId").
|
|
|
Where("up.userId=? and up.appId=? and up.endDate>=?", data.UserId, data.AppId, nowStr).
|
|
|
And("up.prizeType=0 ").
|
|
|
- And("up.prizeType!=3 ").
|
|
|
Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).
|
|
|
Desc("up.createTime").
|
|
|
FindAndCount(&userLettryList)
|
|
@@ -230,8 +229,7 @@ func (service *ActivityService) UserLottery(data *activity.Request) (int64, stri
|
|
|
//查看名下所有奖券
|
|
|
count, err = orm.Table("user_prize").Alias("up").Select("up.*,a.useProductList").
|
|
|
Join("left", "activity a ", "a.prizeId=up.prizeId").
|
|
|
- Where("up.userId=? and up.appId=?", data.UserId, data.AppId).
|
|
|
- And("up.prizeType!=3 ").Desc("up.createTime").
|
|
|
+ Where("up.userId=? and up.appId=?", data.UserId, data.AppId).Desc("up.createTime").
|
|
|
Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).
|
|
|
FindAndCount(&userLettryList)
|
|
|
case 2:
|
|
@@ -239,26 +237,24 @@ func (service *ActivityService) UserLottery(data *activity.Request) (int64, stri
|
|
|
count, err = orm.Table("user_prize").Alias("up").Select("up.*,a.useProductList").
|
|
|
Join("left", "activity a ", "a.prizeId=up.prizeId").
|
|
|
Where("up.userId=? and up.appId=? ", data.UserId, data.AppId, ).
|
|
|
- And("up.prizeType=2").And("up.prizeType!=3 ").
|
|
|
+ And("up.prizeType=2").
|
|
|
Desc("up.createTime").Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).
|
|
|
FindAndCount(&userLettryList)
|
|
|
case 3:
|
|
|
//已用的奖券
|
|
|
count, err = orm.Table("user_prize").Alias("up").Select("up.*,a.useProductList").
|
|
|
Join("left", "activity a ", "a.prizeId=up.prizeId").
|
|
|
- Where("up.userId=? and up.appId=? ", data.UserId, data.AppId, ).
|
|
|
- And("up.prizeType=1").
|
|
|
- And("up.prizeType!=3 ").
|
|
|
+ Where("up.userId=? and up.appId=? and (up.prizeType=1 or up.prizeType=3)", data.UserId, data.AppId, ).
|
|
|
Desc("up.createTime").
|
|
|
Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).FindAndCount(&userLettryList)
|
|
|
}
|
|
|
if err != nil {
|
|
|
- log.Println("用户单位下的奖券查询失败:", err)
|
|
|
+ log.Println("用户下的奖券查询失败:", err)
|
|
|
orm.Rollback()
|
|
|
- return entity.ErrorCode, "用户单位下的奖券查询失败", userLettryList, count
|
|
|
+ return entity.ErrorCode, "用户下的奖券查询失败", userLettryList, count
|
|
|
}
|
|
|
orm.Commit()
|
|
|
- return entity.SuccessCode, "用户单位下的奖券查询成功", userLettryList, count
|
|
|
+ return entity.SuccessCode, "用户下的奖券查询成功", userLettryList, count
|
|
|
}
|
|
|
|
|
|
//计算几天之后的时间
|
|
@@ -269,7 +265,6 @@ func (service *ActivityService) ObtainAppointTimeString(now string, beApartDay i
|
|
|
stopTimeStr := stopTime.Format("2006-01-02")
|
|
|
return stopTimeStr
|
|
|
}
|
|
|
-
|
|
|
//查询过期的奖券改为已过期
|
|
|
func (service *ActivityService) UpdateLottery(endDate string) (int64, string) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -341,6 +336,8 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "修改用户奖券成功"
|
|
|
+ }else if userLottery.PrizeType==3{
|
|
|
+ return entity.SuccessCode, "修改用户奖券成功"
|
|
|
}
|
|
|
return entity.ErrorCode, "该奖券状态不可修改"
|
|
|
} else {
|