package svc import ( "applet/app/db" md "applet/app/md/member_center" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "time" "xorm.io/xorm" ) func BatchAddLevelTask(session *xorm.Session, tasks []md.LevelTaskNode, levelId int) (err error) { nowStr := time.Now().Format("2006-01-02 15:04:05") m := make([]model.UserLevelTask, len(tasks)) for i, task := range tasks { m[i].LevelId = levelId m[i].CreateAt = nowStr m[i].UpdateAt = nowStr if task.IsMustTask != "" { m[i].IsMustTask = utils.StrToInt(task.IsMustTask) } if task.TaskType != "" { m[i].TaskType = utils.StrToInt(task.TaskType) } if task.WithinDays != "" { m[i].WithinDays = utils.StrToInt(task.WithinDays) } if task.FinishCount != "" { m[i].FinishCount = utils.StrToInt(task.FinishCount) } if task.TaskTypeLevelId != "" { m[i].TaskTypeLevelId = utils.StrToInt(task.TaskTypeLevelId) } if task.ActiveDays != "" { m[i].ActiveDays = utils.StrToInt(task.ActiveDays) } } taskDb := implement.NewUserLevelTaskDb(db.Db) _, err = taskDb.UserLevelTaskBatchInsertBySession(session, m) if err != nil { return err } return nil }