创建用户任务奖励记录表
This commit is contained in:
@ -3,6 +3,7 @@ package task
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"server/internal/consts"
|
||||
"server/internal/dao"
|
||||
"server/internal/model"
|
||||
@ -343,19 +344,39 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
|
||||
return nil, ecode.Fail.Sub("生成流水号异常")
|
||||
}
|
||||
|
||||
dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId})
|
||||
_, err = dao.UserTasks.Ctx(ctx).Insert(do.UserTasks{
|
||||
UserId: in.UserId,
|
||||
TaskId: in.TaskId,
|
||||
StoreId: storeId,
|
||||
Status: 1,
|
||||
SerialNumber: serialNumber,
|
||||
TaskName: in.TaskName,
|
||||
GameId: in.GameId,
|
||||
})
|
||||
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,
|
||||
})
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("创建用户任务记录失败")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("添加任务记录异常")
|
||||
// 查询该任务相关联的奖励, 创建对应奖励下发记录id
|
||||
array, err := dao.TaskRewards.Ctx(ctx).Where(do.TaskRewards{TaskId: in.TaskId}).Fields(dao.TaskRewards.Columns().RewardId).Array()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("获取任务关联奖励列表失败")
|
||||
}
|
||||
for _, v := range array {
|
||||
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
|
||||
UserTaskId: id,
|
||||
RewardId: v.Int64(),
|
||||
Status: consts.RewardInitStatus,
|
||||
}).Insert()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("创建用户任务奖励记录失败")
|
||||
}
|
||||
}
|
||||
return
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.GetTaskOut{
|
||||
Success: true,
|
||||
|
||||
Reference in New Issue
Block a user