|
@@ -9,6 +9,7 @@ import (
|
|
|
"log"
|
|
|
"time"
|
|
|
)
|
|
|
+
|
|
|
type ActivityService struct{}
|
|
|
|
|
|
//奖券获取
|
|
@@ -77,7 +78,7 @@ func (service *ActivityService) LotteryReceive(data *activity.LotteryOperation,
|
|
|
userLettry.AppId = data.AppId
|
|
|
userLettry.UserId = data.UserId
|
|
|
userLettry.PrizeType = 0
|
|
|
- userLettry.CreateTime =time.Now().Local()
|
|
|
+ userLettry.CreateTime = time.Now().Local()
|
|
|
userLettry.LotteryId = lotteryId
|
|
|
userLettry.PrizeId = prizeData.PrizeId
|
|
|
userLettry.ValidityDates = prizeData.ValidityDates
|
|
@@ -130,6 +131,7 @@ 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()
|
|
@@ -159,10 +161,10 @@ func (service *ActivityService) ActivityUse(data *activity.LotteryOperation) (in
|
|
|
return entity.ErrorCode, "此卷已过期不可使用"
|
|
|
}
|
|
|
//3、奖券状态改为已使用
|
|
|
- userLottery.UseDate = time.Now().Local()
|
|
|
+ userLottery.UseDate = time.Now().Local()
|
|
|
userLottery.PrizeType = 1
|
|
|
userLottery.OrderCode = data.OrderCode
|
|
|
- numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "useDate","orderCode").Update(userLottery)
|
|
|
+ numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "useDate", "orderCode").Update(userLottery)
|
|
|
if err != nil || numb == 0 {
|
|
|
log.Println("修改用户奖券失败:", err)
|
|
|
orm.Rollback()
|
|
@@ -181,6 +183,7 @@ func (service *ActivityService) ActivityUse(data *activity.LotteryOperation) (in
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "使用奖券成功"
|
|
|
}
|
|
|
+
|
|
|
//活动下的奖券
|
|
|
func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, string, []entity.LotteryJson) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -201,6 +204,7 @@ func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, st
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "活动下的奖券", lotteryJsonList
|
|
|
}
|
|
|
+
|
|
|
//用户下的奖券(不包含待使用的 )
|
|
|
func (service *ActivityService) UserLottery(data *activity.Request) (int64, string, []entity.UserPrizeJson, int64) {
|
|
|
orm := entity.Engine.NewSession()
|
|
@@ -212,17 +216,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{
|
|
|
-
|
|
|
+ condition := ""
|
|
|
+ if data.UserLottertId != 0 {
|
|
|
+ condition = "( (up.prizeType=0 and up.beginDate<='"+nowStr+"' ) or up.id=" + fmt.Sprint(data.UserLottertId) + ") "
|
|
|
+ } else {
|
|
|
+ condition = " up.prizeType=0 and up.beginDate<='"+nowStr+"'"
|
|
|
}
|
|
|
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 ").
|
|
|
- Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).
|
|
|
+ And(condition).
|
|
|
Desc("up.createTime").
|
|
|
FindAndCount(&userLettryList)
|
|
|
case 1:
|
|
@@ -247,6 +250,16 @@ func (service *ActivityService) UserLottery(data *activity.Request) (int64, stri
|
|
|
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)
|
|
|
+
|
|
|
+ case 4:
|
|
|
+ //未用的奖券
|
|
|
+ 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").
|
|
|
+ Limit(int(data.PageSize), (int(data.Page - 1))*int(data.PageSize)).
|
|
|
+ Desc("up.createTime").
|
|
|
+ FindAndCount(&userLettryList)
|
|
|
}
|
|
|
if err != nil {
|
|
|
log.Println("用户下的奖券查询失败:", err)
|
|
@@ -265,6 +278,7 @@ 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()
|
|
@@ -310,7 +324,7 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
|
|
|
var userLottery entity.UserPrize
|
|
|
bool := true
|
|
|
bool, err = orm.Table("user_prize").
|
|
|
- Where("userId=? and appId=? and id=? ", data.UserId, data.AppId,data.UserLotteryId).
|
|
|
+ Where("userId=? and appId=? and id=? ", data.UserId, data.AppId, data.UserLotteryId).
|
|
|
Asc("createTime").Get(&userLottery)
|
|
|
if err != nil {
|
|
|
log.Println("查询奖券库存失败:", err)
|
|
@@ -336,7 +350,7 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "修改用户奖券成功"
|
|
|
- }else if userLottery.PrizeType==3{
|
|
|
+ } else if userLottery.PrizeType == 3 {
|
|
|
return entity.SuccessCode, "修改用户奖券成功"
|
|
|
}
|
|
|
return entity.ErrorCode, "该奖券状态不可修改"
|
|
@@ -344,8 +358,8 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
|
|
|
if (userLottery.PrizeType == 3) {
|
|
|
//奖券状态改为待使用
|
|
|
userLottery.PrizeType = 0
|
|
|
- userLottery.OrderCode =""
|
|
|
- numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType","orderCode").Update(userLottery)
|
|
|
+ userLottery.OrderCode = ""
|
|
|
+ numb, err := orm.Table("user_prize").ID(userLottery.Id).Cols("prizeType", "orderCode").Update(userLottery)
|
|
|
if err != nil || numb == 0 {
|
|
|
log.Println("修改用户奖券失败:", err)
|
|
|
orm.Rollback()
|
|
@@ -353,13 +367,10 @@ func (service *ActivityService) LotteryStateChange(data *activity.UpdateStateReq
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "修改用户奖券成功"
|
|
|
- }else if(userLottery.PrizeType==2){
|
|
|
+ } else if (userLottery.PrizeType == 2) {
|
|
|
orm.Commit()
|
|
|
return entity.SuccessCode, "修改用户奖券成功"
|
|
|
}
|
|
|
return entity.ErrorCode, "该奖券状态不可修改"
|
|
|
}
|
|
|
-
|
|
|
- //待使用改为未使用
|
|
|
-
|
|
|
}
|