|
- 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
-
- }
-
- func LevelManagementGetLevelList(page, limit string) ([]md.LevelListNode, int64, error) {
- levelDb := implement.NewUserLevelDb(db.Db)
- levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
- if err != nil {
- return nil, 0, err
- }
-
- sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level"
- results, err := db.QueryNativeString(db.Db, sql)
- if err != nil {
- return nil, 0, err
- }
- var countMap = map[int]string{}
- for _, res := range results {
- countMap[utils.StrToInt(res["level"])] = res["total"]
- }
-
- list := make([]md.LevelListNode, len(levels))
- for i, level := range levels {
- list[i].LevelWeight = level.LevelWeight
- list[i].LevelID = level.Id
- list[i].LevelName = level.LevelName
- list[i].Count = countMap[level.Id]
- list[i].CreateAt = level.CreateAt
- list[i].IsUse = level.IsUse
- list[i].Memo = level.Memo
- }
-
- return list, total, nil
- }
|