From d8b4bcf1a04d95b05fecbabd7b1ea7581f57e075 Mon Sep 17 00:00:00 2001 From: chy <2463300564@qq.com> Date: Wed, 9 Jul 2025 14:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E9=A2=86?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/task/task.go | 98 ++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 7488fd8..5c76a24 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -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{