medal.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package model
  2. import (
  3. "fmt"
  4. "math/rand"
  5. xtime "go-common/library/time"
  6. )
  7. const (
  8. // OwnerInstall is_activated=1.
  9. OwnerInstall = 1
  10. // OwnerUninstall is_activated=0.
  11. OwnerUninstall = 0
  12. // Level1 medal_info.level 普通.
  13. Level1 = int32(1)
  14. // Level2 medal_info.level 高级.
  15. Level2 = int32(2)
  16. // Level3 medal_info.level 稀有.
  17. Level3 = int32(3)
  18. // IsGet medal has get.
  19. IsGet = int32(1)
  20. // NotGet medal not get.
  21. NotGet = int32(0)
  22. )
  23. var medalLevel = map[int32]string{Level1: "普通勋章", Level2: "高级勋章", Level3: "稀有勋章"}
  24. // MedalOwner struct.
  25. type MedalOwner struct {
  26. ID int64 `json:"id"`
  27. MID int64 `json:"mid"`
  28. NID int64 `json:"nid"`
  29. IsActivated int8 `json:"is_activated"`
  30. CTime xtime.Time `json:"ctime"`
  31. MTime xtime.Time `json:"mtime"`
  32. }
  33. // MedalGroup struct.
  34. type MedalGroup struct {
  35. ID int64 `json:"id"`
  36. Name string `json:"name"`
  37. PID int64 `json:"pid"`
  38. Rank int8 `json:"rank"`
  39. IsOnline int8 `josn:"is_online"`
  40. CTime xtime.Time `json:"ctime"`
  41. MTime xtime.Time `json:"mtime"`
  42. }
  43. // MedalMsg struct.
  44. type MedalMsg struct {
  45. ID int64 `json:"id"`
  46. MID int64 `json:"mid"`
  47. NID int64 `json:"nid"`
  48. CTime xtime.Time `json:"ctime"`
  49. MTime xtime.Time `json:"mtime"`
  50. }
  51. // MedalCheck struct.
  52. type MedalCheck struct {
  53. Has int32 `json:"has"`
  54. Info interface{} `json:"info"`
  55. }
  56. // Build build image and level info.
  57. func (mi *MedalInfo) Build() {
  58. mi.Image = getImageURL(mi.Image)
  59. mi.ImageSmall = getImageURL(mi.ImageSmall)
  60. mi.LevelDesc = medalLevel[mi.Level]
  61. }
  62. // getImageUrl get image from BFS.
  63. func getImageURL(imgSrc string) (imgURL string) {
  64. return fmt.Sprintf("http://i%d.hdslb.com%s", rand.Int63n(3), imgSrc)
  65. }