common.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package model
  2. import (
  3. "fmt"
  4. "math"
  5. )
  6. const (
  7. LoginPlatAccount = "h5"
  8. LoginPlatWeiXin = "wx"
  9. LoginPlatQQ = "qq"
  10. LoginPlatTouTiao = "tt"
  11. LoginPlatMgc = "mt"
  12. LoginPlatQuick = "QuickSDK"
  13. )
  14. const (
  15. CostSourceFortLevel = 1 //联盟升级
  16. CostSourceEnterChapter = 2 //进入章节
  17. CostSourcePartRuneLevel = 3 //符文升级
  18. CostSourcePartRuneRecast = 4 //符文重铸
  19. CostSourceHeroLevel = 5 //英雄升级
  20. CostSourceTreasureLevel = 6 //宝物升级
  21. CostSourceTreasureStar = 7 //宝物升星
  22. CostSourceHeroRecruit = 8 //英雄招募
  23. CostSourceTreasureRecruit = 9 //宝物招募
  24. CostSourceEpigraphRecruit = 10 //铭文招募
  25. CostSourcePointsRecruit = 11 //积分招募
  26. CostSourceRuneDisintegration = 12 //符文分解
  27. CostSourceHeroBuy = 13 //购买英雄
  28. CostSourceHeroSkinActive = 14 //英雄皮肤兑换
  29. CostSourceAdmin = 15 //后台添加
  30. CostItemBuy = 16 //游戏货币购买道具
  31. CostSourceChapterSettle = 17 // 章节结算
  32. CostSourceEmojiUnlock = 18 //表情解锁
  33. CostSourceLegendReset = 19 //铭文重铸
  34. CostSourceLegendExcelIn = 20 //铭文精通
  35. CostSourcePatrol = 21 //巡逻
  36. CostSourceTask = 22 //任务
  37. CostSourceDrawLetterExtra = 23 //邮件
  38. CostSourceUnlock = 24 //解锁
  39. CostSourcePlayerLevelUp = 25 //玩家升级
  40. CostSourceRefreshShop = 26 //刷新商店
  41. CostSourceShopBuy = 27 //商店购买商品
  42. CostSourceUseBox = 28 //开箱子
  43. CostSourceActivities = 29 //精彩活动
  44. CostSourcePayBuy = 30 //充值
  45. CostSourceInviteFriend = 31 //邀请好友
  46. CostSourceSevenDayTask = 32 //七日任务
  47. CostSourceGacha = 33 //扭蛋
  48. CostSourceHuntTreasure = 34 //寻宝
  49. CostSourceFirstCharge = 35 //首充
  50. CostSourceWarOrder = 36 //战令
  51. CostSourceSevenDaySignIn = 37 //7日签到
  52. CostSourceDailyDeal = 38 //每日特惠
  53. CostSourceDiscountPack = 39 //特惠礼包
  54. CostSourceFriendGive = 40 //好友赠送体力
  55. )
  56. const (
  57. LineBit = 12
  58. LineMask = 0x0fff
  59. )
  60. func CalcDocId2(dbId int64, line int64) int64 {
  61. return (dbId << LineBit) + int64(line)
  62. }
  63. func SplitDocId(docId int64) (dbId int64, line int) {
  64. // 分离出 dbId 和 line
  65. dbId = (docId >> LineBit) & math.MaxInt64 // 这里使用右移和位与操作来提取 dbId
  66. line = int(docId & LineMask)
  67. return
  68. }
  69. type VersionControl struct {
  70. Version string `json:"version"`
  71. }
  72. type PlatGroup struct {
  73. GId int `json:"id"`
  74. Plats []string `json:"group"`
  75. ChangeItems [][]int64 `json:"change"`
  76. }
  77. // SumMaterialToSlice 材料信息切片到map的转换
  78. func SumMaterialToMap(materials [][]int64) (map[int64]int64, error) {
  79. if len(materials) == 0 {
  80. return make(map[int64]int64), nil
  81. }
  82. costMap := make(map[int64]int64)
  83. for _, v := range materials {
  84. if len(v) != 2 {
  85. return nil, fmt.Errorf("material slice must have length of 2, but got %d", len(v))
  86. }
  87. costMap[v[0]] += v[1] // 使用 += 操作符更简洁
  88. }
  89. return costMap, nil
  90. }
  91. // func ExtractLineId(docId int64) int {
  92. // return int(docId & LineMask)
  93. // }
  94. // 合并同种材料
  95. // func MergeSameMaterials(lst []*MaterialData) []*MaterialData {
  96. // ret := make([]*MaterialData, 0)
  97. // for _, v := range lst {
  98. // isOk := false
  99. // for _, vv := range ret {
  100. // if vv.ID == v.ID {
  101. // vv.Count += v.Count
  102. // isOk = true
  103. // break
  104. // }
  105. // }
  106. // if !isOk {
  107. // tmp := &MaterialData{ID: v.ID, Count: v.Count}
  108. // ret = append(ret, tmp)
  109. // }
  110. // }
  111. // return ret
  112. // }