v1.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package http
  2. import (
  3. "strconv"
  4. v1 "go-common/app/service/main/account/api"
  5. "go-common/app/service/main/account/model"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // v1Info
  9. func v1Info(c *bm.Context) {
  10. p := new(model.ParamMid)
  11. if err := c.Bind(p); err != nil {
  12. return
  13. }
  14. card, err := accSvc.Card(c, p.Mid)
  15. if err != nil {
  16. c.JSON(nil, err)
  17. return
  18. }
  19. i := &V1Info{}
  20. i.FromCard(card)
  21. c.JSON(i, nil)
  22. }
  23. // v1Infos
  24. func v1Infos(c *bm.Context) {
  25. p := new(model.ParamMids)
  26. if err := c.Bind(p); err != nil {
  27. return
  28. }
  29. cards, err := accSvc.Cards(c, p.Mids)
  30. if err != nil {
  31. c.JSON(nil, err)
  32. return
  33. }
  34. im := make(map[int64]*V1Info, len(cards))
  35. for _, card := range cards {
  36. i := &V1Info{}
  37. i.FromCard(card)
  38. im[card.Mid] = i
  39. }
  40. c.JSON(im, nil)
  41. }
  42. // card
  43. func v1Card(c *bm.Context) {
  44. p := new(model.ParamMid)
  45. if err := c.Bind(p); err != nil {
  46. return
  47. }
  48. ps, err := accSvc.ProfileWithStat(c, p.Mid)
  49. if err != nil {
  50. c.JSON(nil, err)
  51. return
  52. }
  53. card := &V1Card{}
  54. card.FromProfile(ps)
  55. c.JSON(card, nil)
  56. }
  57. // vip
  58. func v1Vip(c *bm.Context) {
  59. p := new(model.ParamMid)
  60. if err := c.Bind(p); err != nil {
  61. return
  62. }
  63. vi, err := accSvc.Vip(c, p.Mid)
  64. if err != nil {
  65. c.JSON(nil, err)
  66. return
  67. }
  68. v := &V1Vip{}
  69. v.FromVip(vi)
  70. c.JSON(v, nil)
  71. }
  72. // V1Info info.
  73. type V1Info struct {
  74. Mid string `json:"mid"`
  75. Name string `json:"uname"`
  76. Sex string `json:"sex"`
  77. Sign string `json:"sign"`
  78. Avatar string `json:"avatar"`
  79. Rank string `json:"rank"`
  80. DisplayRank string `json:"DisplayRank"`
  81. LevelInfo struct {
  82. Cur int `json:"current_level"`
  83. Min int `json:"current_min"`
  84. NowExp int `json:"current_exp"`
  85. NextExp interface{} `json:"next_exp"`
  86. } `json:"level_info"`
  87. Pendant v1.PendantInfo `json:"pendant"`
  88. Nameplate v1.NameplateInfo `json:"nameplate"`
  89. OfficialVerify model.OldOfficial `json:"official_verify"`
  90. Vip struct {
  91. Type int `json:"vipType"`
  92. DueDate int64 `json:"vipDueDate"`
  93. DueRemark string `json:"dueRemark"`
  94. AccessStatus int `json:"accessStatus"`
  95. VipStatus int `json:"vipStatus"`
  96. VipStatusWarn string `json:"vipStatusWarn"`
  97. } `json:"vip"`
  98. }
  99. // FromCard from card.
  100. func (i *V1Info) FromCard(c *v1.Card) {
  101. i.Mid = strconv.FormatInt(c.Mid, 10)
  102. i.Name = c.Name
  103. i.Sex = c.Sex
  104. i.Sign = c.Sign
  105. i.Avatar = c.Face
  106. i.Rank = strconv.FormatInt(int64(c.Rank), 10)
  107. i.DisplayRank = "0"
  108. i.LevelInfo.Cur = int(c.Level)
  109. i.LevelInfo.Min = 0
  110. i.LevelInfo.NowExp = 0
  111. i.LevelInfo.NextExp = 0
  112. i.Pendant = c.Pendant
  113. i.Nameplate = c.Nameplate
  114. i.OfficialVerify = model.CvtOfficial(c.Official)
  115. i.Vip.Type = int(c.Vip.Type)
  116. i.Vip.VipStatus = int(c.Vip.Status)
  117. i.Vip.DueDate = c.Vip.DueDate
  118. }
  119. // V1Card card
  120. type V1Card struct {
  121. Mid string `json:"mid"`
  122. Name string `json:"name"`
  123. Approve bool `json:"approve"`
  124. Sex string `json:"sex"`
  125. Rank string `json:"rank"`
  126. Face string `json:"face"`
  127. DisplayRank string `json:"DisplayRank"`
  128. Regtime int64 `json:"regtime"`
  129. Spacesta int `json:"spacesta"`
  130. Birthday string `json:"birthday"`
  131. Place string `json:"place"`
  132. Description string `json:"description"`
  133. Article int `json:"article"`
  134. Attentions []int64 `json:"attentions"`
  135. Fans int `json:"fans"`
  136. Friend int `json:"friend"`
  137. Attention int `json:"attention"`
  138. Sign string `json:"sign"`
  139. LevelInfo struct {
  140. Cur int `json:"current_level"`
  141. Min int `json:"current_min"`
  142. NowExp int `json:"current_exp"`
  143. NextExp interface{} `json:"next_exp"`
  144. } `json:"level_info"`
  145. Pendant v1.PendantInfo `json:"pendant"`
  146. Nameplate v1.NameplateInfo `json:"nameplate"`
  147. OfficialVerify model.OldOfficial `json:"official_verify"`
  148. Vip struct {
  149. Type int `json:"vipType"`
  150. DueDate int64 `json:"vipDueDate"`
  151. DueRemark string `json:"dueRemark"`
  152. AccessStatus int `json:"accessStatus"`
  153. VipStatus int `json:"vipStatus"`
  154. VipStatusWarn string `json:"vipStatusWarn"`
  155. } `json:"vip"`
  156. }
  157. // FromProfile from profile.
  158. func (i *V1Card) FromProfile(c *model.ProfileStat) {
  159. i.Mid = strconv.FormatInt(c.Mid, 10)
  160. i.Name = c.Name
  161. i.Sex = c.Sex
  162. i.Sign = c.Sign
  163. i.Face = c.Face
  164. i.Rank = strconv.FormatInt(int64(c.Rank), 10)
  165. i.DisplayRank = "0"
  166. i.Regtime = int64(c.JoinTime)
  167. if c.Silence == 1 {
  168. i.Spacesta = -2
  169. }
  170. i.Attentions = []int64{}
  171. i.Fans = int(c.Follower)
  172. i.Attention = int(c.Following)
  173. i.LevelInfo.Cur = int(c.Level)
  174. i.LevelInfo.Min = int(c.LevelExp.Min)
  175. i.LevelInfo.NowExp = int(c.LevelExp.NowExp)
  176. i.LevelInfo.NextExp = c.LevelExp.NextExp
  177. if c.LevelExp.NowExp == -1 {
  178. i.LevelInfo.NextExp = "--"
  179. }
  180. i.Pendant = c.Pendant
  181. i.Nameplate = c.Nameplate
  182. i.OfficialVerify = model.CvtOfficial(c.Official)
  183. i.Vip.Type = int(c.Vip.Type)
  184. i.Vip.VipStatus = int(c.Vip.Status)
  185. i.Vip.DueDate = c.Vip.DueDate
  186. }
  187. // V1Vip vip
  188. type V1Vip struct {
  189. Type int `json:"vipType"`
  190. DueDate int64 `json:"vipDueDate"`
  191. DueRemark string `json:"dueRemark"`
  192. AccessStatus int `json:"accessStatus"`
  193. VipStatus int `json:"vipStatus"`
  194. VipStatusWarn string `json:"vipStatusWarn"`
  195. }
  196. // FromVip from vip.
  197. func (v *V1Vip) FromVip(vi *v1.VipInfo) {
  198. v.Type = int(vi.Type)
  199. v.VipStatus = int(vi.Status)
  200. v.DueDate = vi.DueDate
  201. }