蛋蛋星球 后台端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
2.1 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. md "applet/app/md/member_center"
  5. "applet/app/utils"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  8. "time"
  9. "xorm.io/xorm"
  10. )
  11. func BatchAddLevelTask(session *xorm.Session, tasks []md.LevelTaskNode, levelId int) (err error) {
  12. nowStr := time.Now().Format("2006-01-02 15:04:05")
  13. m := make([]model.UserLevelTask, len(tasks))
  14. for i, task := range tasks {
  15. m[i].LevelId = levelId
  16. m[i].CreateAt = nowStr
  17. m[i].UpdateAt = nowStr
  18. if task.IsMustTask != "" {
  19. m[i].IsMustTask = utils.StrToInt(task.IsMustTask)
  20. }
  21. if task.TaskType != "" {
  22. m[i].TaskType = utils.StrToInt(task.TaskType)
  23. }
  24. if task.WithinDays != "" {
  25. m[i].WithinDays = utils.StrToInt(task.WithinDays)
  26. }
  27. if task.FinishCount != "" {
  28. m[i].FinishCount = utils.StrToInt(task.FinishCount)
  29. }
  30. if task.TaskTypeLevelId != "" {
  31. m[i].TaskTypeLevelId = utils.StrToInt(task.TaskTypeLevelId)
  32. }
  33. if task.ActiveDays != "" {
  34. m[i].ActiveDays = utils.StrToInt(task.ActiveDays)
  35. }
  36. }
  37. taskDb := implement.NewUserLevelTaskDb(db.Db)
  38. _, err = taskDb.UserLevelTaskBatchInsertBySession(session, m)
  39. if err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. func LevelManagementGetLevelList(page, limit string) ([]md.LevelListNode, int64, error) {
  45. levelDb := implement.NewUserLevelDb(db.Db)
  46. levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
  47. if err != nil {
  48. return nil, 0, err
  49. }
  50. sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level"
  51. results, err := db.QueryNativeString(db.Db, sql)
  52. if err != nil {
  53. return nil, 0, err
  54. }
  55. var countMap = map[int]string{}
  56. for _, res := range results {
  57. countMap[utils.StrToInt(res["level"])] = res["total"]
  58. }
  59. list := make([]md.LevelListNode, len(levels))
  60. for i, level := range levels {
  61. list[i].LevelWeight = level.LevelWeight
  62. list[i].LevelID = level.Id
  63. list[i].LevelName = level.LevelName
  64. list[i].Count = countMap[level.Id]
  65. list[i].CreateAt = level.CreateAt
  66. list[i].IsUse = level.IsUse
  67. list[i].Memo = level.Memo
  68. }
  69. return list, total, nil
  70. }