exchange.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package controller
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/adminserver/character"
  5. "bet24.com/servers/adminserver/dao"
  6. "bet24.com/servers/adminserver/item"
  7. "bet24.com/servers/coreservice/client"
  8. item_inventory "bet24.com/servers/micros/item_inventory/proto"
  9. "fmt"
  10. "github.com/gin-gonic/gin"
  11. "net/http"
  12. )
  13. func SysExchange(c *gin.Context) {
  14. c.JSON(http.StatusOK, struct {
  15. RecordCount int
  16. List interface{}
  17. }{
  18. RecordCount: 0,
  19. List: client.GetExchangeType(),
  20. })
  21. return
  22. }
  23. // 兑换历史
  24. func ExchangeHistory(c *gin.Context) {
  25. obj := dao.NewExchangeHistory()
  26. if err := c.ShouldBind(&obj.In); err != nil {
  27. log.Debug("%s shouldBind err %v", "ExchangeHistory", err)
  28. return
  29. }
  30. obj.DoAction()
  31. tools := item.GetSysItems()
  32. for i := 0; i < len(obj.Out.List); i++ {
  33. list := &obj.Out.List[i]
  34. for j := 0; j < len(list.ItemPack); j++ {
  35. history := &list.ItemPack[j]
  36. sysItem, ok := tools[history.ItemId]
  37. if !ok {
  38. continue
  39. }
  40. obj.Out.List[i].Item = fmt.Sprintf("<b>%s</b>(Num:%d)", sysItem.Name, history.Count)
  41. if sysItem.Type == item_inventory.Item_Physical || sysItem.Type == item_inventory.Item_GiftCard {
  42. obj.Out.List[i].IsMust = 1
  43. }
  44. }
  45. }
  46. c.JSON(http.StatusOK, obj.Out)
  47. }
  48. // 兑换历史
  49. func ExchangeCash(c *gin.Context) {
  50. obj := dao.NewExchangeCash()
  51. if err := c.ShouldBind(&obj.In); err != nil {
  52. log.Debug("%s shouldBind err %v", "ExchangeCash", err)
  53. return
  54. }
  55. obj.DoAction()
  56. tools := item.GetSysItems()
  57. for i := 0; i < len(obj.Out.List); i++ {
  58. list := &obj.Out.List[i]
  59. for j := 0; j < len(list.ItemPack); j++ {
  60. history := &list.ItemPack[j]
  61. item, ok := tools[history.ItemId]
  62. if !ok {
  63. continue
  64. }
  65. obj.Out.List[i].Item = fmt.Sprintf("<b>%s</b>(Num:%d)", item.Name, history.Count)
  66. if item.Type == item_inventory.Item_Physical || item.Type == item_inventory.Item_GiftCard {
  67. obj.Out.List[i].IsMust = 1
  68. }
  69. }
  70. }
  71. c.JSON(http.StatusOK, obj.Out)
  72. }
  73. // 修改兑换历史
  74. func ExchangeHistoryUpdate(c *gin.Context) {
  75. obj := dao.NewExchangeHistoryUpdate()
  76. if err := c.ShouldBind(&obj.In); err != nil {
  77. log.Debug("%s shouldBind err %v", "ExchangeHistoryUpdate", err)
  78. return
  79. }
  80. if obj.In.Status == 0 {
  81. obj.Out.RetCode = 11
  82. obj.Out.ErrorMsg = "修改失败"
  83. c.JSON(http.StatusOK, obj.Out)
  84. return
  85. }
  86. obj.In.Items = character.GetSpecialCharacter(obj.In.Items)
  87. obj.DoAction()
  88. /*
  89. // 兑换成功
  90. if obj.Out.RetCode != 1 {
  91. c.JSON(http.StatusOK, obj.Out)
  92. return
  93. }
  94. // 拒绝,返还
  95. if obj.In.Status == 2 {
  96. itemId := 0
  97. switch obj.In.ExchangeType {
  98. case 1: // 奖券
  99. itemId = item_inventory.Item_GiftCard
  100. case 5: // 金币提现
  101. itemId = item_inventory.Item_Gold
  102. }
  103. // 返还道具
  104. if itemId > 0 && obj.In.Price > 0 {
  105. var tools []item_inventory.ItemPack
  106. tools = append(tools, item_inventory.ItemPack{
  107. ItemId: itemId,
  108. Count: obj.In.Price,
  109. })
  110. client.SendSysMail(obj.In.UserID, mail.SysMail{
  111. Id: 0,
  112. Title: config.Server.Exchange_Title,
  113. Content: config.Server.Exchange_Content,
  114. Status: 0,
  115. SourceName: "admin exchange",
  116. Crdate: common.GetTimeStamp(),
  117. Tools: tools,
  118. })
  119. }
  120. c.JSON(http.StatusOK, obj.Out)
  121. return
  122. }
  123. // 查询用户信息
  124. resp := client.GetUserInfo(obj.In.UserID)
  125. if resp.Data == "" {
  126. c.JSON(http.StatusOK, obj.Out)
  127. return
  128. }
  129. // 用户信息
  130. var UserHotInfo struct {
  131. UserId int
  132. NickName string
  133. Vip int
  134. FaceUrl string
  135. FaceId int
  136. Sex int
  137. UserWords string
  138. IsRobot int // 是否机器人
  139. Achievements []int // 成就列表
  140. }
  141. if err := json.Unmarshal([]byte(resp.Data), &UserHotInfo); err != nil {
  142. c.JSON(http.StatusOK, obj.Out)
  143. return
  144. }
  145. tools := item.GetSysItems()
  146. var items []item_inventory.ItemPack
  147. if err := json.Unmarshal([]byte(obj.In.Items), &items); err != nil {
  148. c.JSON(http.StatusOK, obj.Out)
  149. return
  150. }
  151. for _, v := range items {
  152. tmpItem, ok := tools[v.ItemId]
  153. if !ok {
  154. continue
  155. }
  156. broadcastMsg := ""
  157. // 8=话费
  158. if tmpItem.Type == 8 {
  159. // SNG赛 Cash 类处理
  160. if splitRemarks := strings.Split(obj.Out.Remark, ","); len(splitRemarks) > 0 {
  161. if rid, err := strconv.Atoi(splitRemarks[0]); err != nil {
  162. log.Error("ExchangeHistoryUpdate SNG 赛 Cash 处理 obj.In=%+v obj.Out=%+v ,err ==>%v", obj.In, obj.Out, err)
  163. } else {
  164. log.Debug("ExchangeHistoryUpdate SNG 赛 Cash 处理调用 rid=%d obj.In=%+v obj.Out=%+v", rid, obj.In, obj.Out)
  165. go gameHistory.MyMatch_UpdateStatus(obj.In.UserID, rid, gameHistory.MyMatch_Status_Received)
  166. }
  167. continue
  168. }
  169. broadcastMsg = config.Server.Exchange_Broadcast_Phone
  170. } else if tmpItem.Type == 11 { // 11=Cash
  171. broadcastMsg = config.Server.Exchange_Broadcast_Cash
  172. }
  173. broadcastMsg = strings.ReplaceAll(broadcastMsg, "数量", fmt.Sprintf("<color=#04ff0a>%d</color>", v.Count))
  174. broadcastMsg = strings.ReplaceAll(broadcastMsg, "玩家昵称", fmt.Sprintf("<color=#ffafd8>%s</color>", UserHotInfo.NickName))
  175. go client.SendBroadcast(obj.In.UserID, 0, 0, broadcastMsg, "")
  176. }
  177. */
  178. c.JSON(http.StatusOK, obj.Out)
  179. return
  180. }