alilog.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import (
  3. "active/tools"
  4. "fmt"
  5. "git.jiaxianghudong.com/webs/pkg/ali"
  6. "time"
  7. )
  8. //SendSlsPacket 插入日志
  9. type SendSlsPacket struct {
  10. AppID int32 `json:"app_id"`
  11. ChannelID int32 `json:"channel_id"`
  12. ProductID int `json:"product_id"`
  13. Region string `json:"region"`
  14. DataID int `json:"dataid"`
  15. Value int `json:"value"`
  16. InvNum int `json:"inv_num"`
  17. HelperID int `json:"helper_id"`
  18. UserID uint32 `json:"user_id"`
  19. NewSmallGameUser int `json:"new_small_game_user"`
  20. OpType int `json:"op_type"`
  21. ActType int `json:"act_type"`
  22. Ext string `json:"ext"`
  23. Ext1 string `json:"ext_1"`
  24. IP string
  25. WxOpenId string `json:"wx_open_id"`
  26. }
  27. //SendSlsLog 插入阿里日志
  28. func (this *SendSlsPacket) SendSlsLog() {
  29. data := map[string]string{
  30. "app_id": fmt.Sprintf("%d", this.AppID),
  31. "channel_id": fmt.Sprintf("%d", this.ChannelID),
  32. "product_id": fmt.Sprintf("%d", GetProductID(this.AppID)),
  33. "region": this.Region,
  34. "dataid": fmt.Sprintf("%d", this.DataID),
  35. "value": fmt.Sprintf("%d", this.Value),
  36. "inv_num": fmt.Sprintf("%d", this.InvNum),
  37. "user_id": fmt.Sprintf("%d", this.UserID),
  38. "helper_id": fmt.Sprintf("%d", this.HelperID),
  39. "new_small_game_user": fmt.Sprintf("%d", FromSmallGame(int(this.ChannelID))),
  40. "op_type": fmt.Sprintf("%d", this.OpType),
  41. "act_type": fmt.Sprintf("%d", this.ActType),
  42. "time": time.Now().Format("2006-01-02 15:04:05"),
  43. "ext": fmt.Sprintf("%v", this.Ext),
  44. "ext1": fmt.Sprintf("%v", this.Ext1),
  45. "wx_open_id": fmt.Sprintf("%v", this.WxOpenId),
  46. }
  47. ali.SendLog("redpack_activity", this.IP, data)
  48. }
  49. //FromSmallGame 来源小游戏
  50. func FromSmallGame(ChannelID int) int {
  51. if tools.InIntArray(ChannelID, []int{818, 821, 820, 851}) {
  52. return 1
  53. }
  54. return 0
  55. }
  56. //GetProductID 获取产品ID
  57. func GetProductID(appID int32) int32 {
  58. //偶数变基数
  59. if appID%2 == 0 {
  60. return appID - 1
  61. }
  62. return appID
  63. }
  64. //GetPlatformID 获取平台ID
  65. func GetPlatformID(platFromName string) int {
  66. if platFromName == "ios" {
  67. return 11
  68. }
  69. return 12
  70. }