修改领取奖励部分
This commit is contained in:
@ -213,6 +213,7 @@ type CallbackRes struct {
|
||||
type GetLiftReq struct {
|
||||
g.Meta `path:"/reward/getLift" method:"post" tags:"Reward" summary:"(PC)奖励领取"`
|
||||
RewradType int `json:"rewardType" v:"required#奖励类型不能为空" dc:"奖励类型"`
|
||||
RewradId int `json:"rewardId" v:"required#奖励id不能为空" dc:"奖励id"`
|
||||
PopenId string `json:"popenid" v:"required#popenId不能为空" dc:"popenId不能为空"`
|
||||
Source int `json:"source" v:"required#来源不能为空" dc:"来源" d:"1:系统 2:门店"`
|
||||
TaskId string `json:"taskId" v:"required#任务id不能为空" dc:"任务Id"`
|
||||
@ -220,6 +221,7 @@ type GetLiftReq struct {
|
||||
BindType int `json:"bindType" v:"required#绑定类型不能为空" dc:"绑定类型"`
|
||||
AreaId int `json:"areaId" dc:"大区Id"`
|
||||
RoleIdx string `json:"roleIdx" dc:"角色索引"`
|
||||
UserTaskId int `json:"userTaskId" v:"required#用户任务记录id不能为空" dc:"用户任务记录"`
|
||||
}
|
||||
|
||||
type GetLiftRes struct {
|
||||
|
||||
@ -2,12 +2,15 @@ package reward
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"server/api/reward/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) GetLift(ctx context.Context, req *v1.GetLiftReq) (res *v1.GetLiftRes, err error) {
|
||||
|
||||
userId := g.RequestFromCtx(ctx).Get("id")
|
||||
out, err := service.Reward().GetLift(ctx, &model.GetRewardIn{
|
||||
GameId: req.GameId,
|
||||
TaskId: req.TaskId,
|
||||
@ -17,6 +20,9 @@ func (c *ControllerV1) GetLift(ctx context.Context, req *v1.GetLiftReq) (res *v1
|
||||
AreaId: req.AreaId,
|
||||
Source: req.Source,
|
||||
BindType: req.BindType,
|
||||
UserTaskId: req.UserTaskId,
|
||||
UserId: userId.Int(),
|
||||
RewardId: req.RewradId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@ -396,27 +396,56 @@ func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *mode
|
||||
|
||||
// 根据 result判断
|
||||
if item.Result == 1 {
|
||||
// 奖励发放成功,修改状态,扣除数量
|
||||
if _, err = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{ExternalOrderId: item.Water.OrderId}).Update(consts.RewardSuccessStatus); err != nil {
|
||||
return ecode.Fail.Sub("修改奖励领取记录状态异常")
|
||||
//// 奖励发放成功,修改状态,扣除数量
|
||||
|
||||
// 查询当前奖励是否为最后一个, 如果是则更新任务状态为2 完成
|
||||
count, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: in.UserTaskId}).Where(do.UserTaskRewards{Status: 2}).Count()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("查询用户任务奖励失败")
|
||||
}
|
||||
|
||||
value, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{ExternalOrderId: item.Water.OrderId}).Value(dao.UserTaskRewards.Columns().RewardId)
|
||||
if count <= 1 {
|
||||
// 修改任务记录状态2
|
||||
_, err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{Id: in.UserTaskId}).Data(do.UserTasks{
|
||||
Status: 2,
|
||||
}).Update()
|
||||
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务状态失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 增加奖励已领取数量
|
||||
_, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.RewardId}).Increment(dao.Rewards.Columns().ReceivedNum, 1)
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("获取奖励领取记录异常")
|
||||
}
|
||||
if value.IsEmpty() {
|
||||
return ecode.Fail.Sub("获取奖励领取记录异常")
|
||||
}
|
||||
// 扣除数量
|
||||
if _, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: value.Int()}).One(); err != nil {
|
||||
return ecode.Fail.Sub("获取奖励记录异常")
|
||||
|
||||
// 修改用户任务奖励记录状态
|
||||
_, err = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: in.UserTaskId, RewardId: in.RewardId}).Data(do.UserTaskRewards{
|
||||
Status: consts.RewardSuccessStatus,
|
||||
}).Update()
|
||||
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务奖励记录状态异常")
|
||||
}
|
||||
|
||||
return
|
||||
} else if item.Result == 2 || item.Result == 3 {
|
||||
// 发放背包成功,修改状态
|
||||
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
|
||||
Status: consts.RewardExchangeStatus,
|
||||
}).Where(do.UserTaskRewards{
|
||||
Id: in.UserTaskId,
|
||||
RewardId: in.RewardId,
|
||||
}).Update()
|
||||
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务奖励记录状态异常")
|
||||
}
|
||||
} else if item.Result == 4 {
|
||||
// 奖励领取失败,不做操作,直接返回
|
||||
return ecode.Fail.Sub("领取奖励失败")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -153,11 +153,14 @@ type GetRewardIn struct {
|
||||
AreaId int
|
||||
GameId int
|
||||
RewradTypeId int
|
||||
RewardId int
|
||||
RoleIdx string
|
||||
TaskId string
|
||||
PopenId string
|
||||
Source int
|
||||
BindType int
|
||||
UserTaskId int
|
||||
UserId int
|
||||
}
|
||||
type GetRewardOut struct {
|
||||
List interface{} `json:"list"`
|
||||
|
||||
Reference in New Issue
Block a user