蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.2 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. if task.ActiveNum != "" {
  37. m[i].ActiveNum = utils.StrToInt(task.ActiveNum)
  38. }
  39. }
  40. taskDb := implement.NewUserLevelTaskDb(db.Db)
  41. _, err = taskDb.UserLevelTaskBatchInsertBySession(session, m)
  42. if err != nil {
  43. return err
  44. }
  45. return nil
  46. }
  47. func LevelManagementGetLevelList(page, limit string) ([]md.LevelListNode, int64, error) {
  48. levelDb := implement.NewUserLevelDb(db.Db)
  49. levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
  50. if err != nil {
  51. return nil, 0, err
  52. }
  53. sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level"
  54. results, err := db.QueryNativeString(db.Db, sql)
  55. if err != nil {
  56. return nil, 0, err
  57. }
  58. var countMap = map[int]string{}
  59. for _, res := range results {
  60. countMap[utils.StrToInt(res["level"])] = res["total"]
  61. }
  62. list := make([]md.LevelListNode, len(levels))
  63. for i, level := range levels {
  64. list[i].LevelWeight = level.LevelWeight
  65. list[i].LevelID = level.Id
  66. list[i].LevelName = level.LevelName
  67. list[i].Count = countMap[level.Id]
  68. list[i].CreateAt = level.CreateAt
  69. list[i].IsUse = level.IsUse
  70. list[i].Memo = level.Memo
  71. }
  72. return list, total, nil
  73. }