修改任务领取
This commit is contained in:
@ -368,71 +368,69 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
|
|||||||
// 当天结束时间
|
// 当天结束时间
|
||||||
end := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
end := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
||||||
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).
|
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).
|
||||||
WhereBetween(dao.UserTasks.Columns().CreatedAt, start, end).WhereNot("status", 3).Scan(&userTask)
|
WhereBetween(dao.UserTasks.Columns().CreatedAt, start, end).Scan(&userTask)
|
||||||
} else {
|
} else {
|
||||||
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).WhereNot("status", 3).Scan(&userTask)
|
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).Scan(&userTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ecode.Fail.Sub("查询用户该任务记录失败")
|
return nil, ecode.Fail.Sub("查询用户该任务记录失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
//if userTask != nil {
|
if userTask != nil {
|
||||||
// return nil, ecode.Fail.Sub("该任务记录已存在")
|
return nil, ecode.Fail.Sub("该任务记录已存在")
|
||||||
//}
|
}
|
||||||
|
|
||||||
if userTask == nil {
|
// TODO 流水号未知
|
||||||
// TODO 流水号未知
|
serialNumber, err := snowid.GetSnowClient().GenerateSerialNumber()
|
||||||
serialNumber, err := snowid.GetSnowClient().GenerateSerialNumber()
|
if err != nil {
|
||||||
|
return nil, ecode.Fail.Sub("生成流水号异常")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = dao.UserTasks.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||||
|
// 创建任务记录
|
||||||
|
id, err := dao.UserTasks.Ctx(ctx).InsertAndGetId(do.UserTasks{
|
||||||
|
UserId: in.UserId,
|
||||||
|
TaskId: in.TaskId,
|
||||||
|
StoreId: storeId,
|
||||||
|
Status: 1,
|
||||||
|
SerialNumber: serialNumber,
|
||||||
|
TaskName: in.TaskName,
|
||||||
|
GameId: in.GameId,
|
||||||
|
TaskType: in.TaskType,
|
||||||
|
UserTimes: in.UserTimes,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ecode.Fail.Sub("生成流水号异常")
|
return ecode.Fail.Sub("创建用户任务记录失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dao.UserTasks.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
//查询该任务相关联的奖励, 创建对应奖励下发记录id
|
||||||
// 创建任务记录
|
array, err := dao.TaskRewards.Ctx(ctx).LeftJoin(dao.Rewards.Table(), "rewards.id = task_rewards.reward_id").Where(do.TaskRewards{TaskId: in.TaskId}).
|
||||||
id, err := dao.UserTasks.Ctx(ctx).InsertAndGetId(do.UserTasks{
|
Fields(dao.TaskRewards.Columns().RewardId).All()
|
||||||
UserId: in.UserId,
|
if err != nil {
|
||||||
TaskId: in.TaskId,
|
return ecode.Fail.Sub("获取任务关联奖励列表失败")
|
||||||
StoreId: storeId,
|
}
|
||||||
Status: 1,
|
for _, v := range array {
|
||||||
SerialNumber: serialNumber,
|
var reward entity.Rewards
|
||||||
TaskName: in.TaskName,
|
if err := dao.Rewards.Ctx(ctx).WherePri(v["reward_id"].Int64()).Scan(&reward); err != nil {
|
||||||
GameId: in.GameId,
|
|
||||||
TaskType: in.TaskType,
|
|
||||||
UserTimes: in.UserTimes,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("创建用户任务记录失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询该任务相关联的奖励, 创建对应奖励下发记录id
|
|
||||||
array, err := dao.TaskRewards.Ctx(ctx).LeftJoin(dao.Rewards.Table(), "rewards.id = task_rewards.reward_id").Where(do.TaskRewards{TaskId: in.TaskId}).
|
|
||||||
Fields(dao.TaskRewards.Columns().RewardId).All()
|
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("获取任务关联奖励列表失败")
|
return ecode.Fail.Sub("获取任务关联奖励列表失败")
|
||||||
}
|
}
|
||||||
for _, v := range array {
|
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
|
||||||
var reward entity.Rewards
|
UserTaskId: id,
|
||||||
if err := dao.Rewards.Ctx(ctx).WherePri(v["reward_id"].Int64()).Scan(&reward); err != nil {
|
RewardId: v["reward_id"].Int64(),
|
||||||
return ecode.Fail.Sub("获取任务关联奖励列表失败")
|
RewardName: reward.Name,
|
||||||
}
|
Status: consts.RewardInitStatus,
|
||||||
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
|
IssueQuantity: reward.GrantQuantity,
|
||||||
UserTaskId: id,
|
Source: reward.Source,
|
||||||
RewardId: v["reward_id"].Int64(),
|
RewardTypeId: reward.RewardTypeId,
|
||||||
RewardName: reward.Name,
|
}).Insert()
|
||||||
Status: consts.RewardInitStatus,
|
if err != nil {
|
||||||
IssueQuantity: reward.GrantQuantity,
|
return ecode.Fail.Sub("创建用户任务奖励记录失败")
|
||||||
Source: reward.Source,
|
|
||||||
RewardTypeId: reward.RewardTypeId,
|
|
||||||
}).Insert()
|
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("创建用户任务奖励记录失败")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.GetTaskOut{
|
return &model.GetTaskOut{
|
||||||
|
|||||||
Reference in New Issue
Block a user