修改任务领取

This commit is contained in:
chy
2025-07-09 14:33:44 +08:00
parent c1056552da
commit d8b4bcf1a0

View File

@ -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())
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 {
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 {
return nil, ecode.Fail.Sub("查询用户该任务记录失败")
}
//if userTask != nil {
// return nil, ecode.Fail.Sub("该任务记录已存在")
//}
if userTask != nil {
return nil, ecode.Fail.Sub("该任务记录已存在")
}
if userTask == nil {
// TODO 流水号未知
serialNumber, err := snowid.GetSnowClient().GenerateSerialNumber()
// TODO 流水号未知
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 {
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, 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 {
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 {
//查询该任务相关联的奖励, 创建对应奖励下发记录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("获取任务关联奖励列表失败")
}
for _, v := range array {
var reward entity.Rewards
if err := dao.Rewards.Ctx(ctx).WherePri(v["reward_id"].Int64()).Scan(&reward); err != nil {
return ecode.Fail.Sub("获取任务关联奖励列表失败")
}
for _, v := range array {
var reward entity.Rewards
if err := dao.Rewards.Ctx(ctx).WherePri(v["reward_id"].Int64()).Scan(&reward); err != nil {
return ecode.Fail.Sub("获取任务关联奖励列表失败")
}
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
UserTaskId: id,
RewardId: v["reward_id"].Int64(),
RewardName: reward.Name,
Status: consts.RewardInitStatus,
IssueQuantity: reward.GrantQuantity,
Source: reward.Source,
RewardTypeId: reward.RewardTypeId,
}).Insert()
if err != nil {
return ecode.Fail.Sub("创建用户任务奖励记录失败")
}
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
UserTaskId: id,
RewardId: v["reward_id"].Int64(),
RewardName: reward.Name,
Status: consts.RewardInitStatus,
IssueQuantity: reward.GrantQuantity,
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{