shop.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package shop
  2. import (
  3. "bet24.com/log"
  4. item "bet24.com/servers/micros/item_inventory/proto"
  5. )
  6. const (
  7. ShopType_All = iota
  8. ShopType_Gold // 1 = 金币
  9. ShopType_Diamond // 2 = 钻石
  10. ShopType_Item // 3 = 消耗道具
  11. ShopType_VipPackage // 4 = VIP礼包
  12. ShopType_RechargeGift // 5 = 充值礼包
  13. ShopType_GrowthGift // 6 = 成长礼包
  14. ShopType_MonthlyCard // 7 = 月卡
  15. ShopType_VipCard // 8 = vip会员卡(周卡、月卡)
  16. ShopType_FirstCharge // 9 = 首充
  17. ShopType_Web // 10 = 页面支付
  18. ShopType_Giving // 11 = 语聊房礼物
  19. ShopType_LevelRewards // 12 = 等级礼包
  20. ShopType_SavingPot // 13=存钱罐
  21. ShopType_HighlyProfitable // 14=一本万利
  22. ShopType_Max
  23. )
  24. // 支付类型
  25. const (
  26. PayType_Diamond int = iota // 0=钻石
  27. PayType_RMB // 1=人民币购买
  28. PayType_Gold // 2=金币购买
  29. )
  30. type Shop_Item struct {
  31. ProductId string // 产品ID
  32. ProductName string // 产品名称
  33. Price float64 // 基础价格(实际支付价格)
  34. ShowPrice float64 // 显示价格(显示价格)
  35. PayType int // 支付类型(1=RMB 0=钻石 2=金币)
  36. ShopType int // 产品类型(1=金币 2=钻石 3=炮台 4=礼包)
  37. IsHot int // 是否热销 1=热销
  38. Bonus int // 额外赠送(多送百分比)
  39. Extra []item.ItemPack // 扩展信息
  40. Status int // 状态(1=正常 2=不可用或没有购买次数)
  41. Sort int // 排序
  42. AnimationType int // 动画类型
  43. UserType int // 用户类型(0=普通 1=成员)
  44. IsBottom int // 是否置底
  45. ProductDesc string // 产品描述
  46. }
  47. // 汇率
  48. type exchangeRate struct {
  49. Currency string // 币种
  50. CountryName string // 国家名称
  51. CountryCode string // 国家编码
  52. Rate float64 // 汇率
  53. }
  54. var mgr *shopmgr
  55. func Run() {
  56. log.Debug("shop running")
  57. mgr = newShopMgr()
  58. }
  59. /*func GetExchangeRateList() []*exchangeRate {
  60. return mgr.getExchangeRateList()
  61. }
  62. */
  63. func GetShopList(userId, shopType int, productID string) []*Shop_Item {
  64. if productID == "" {
  65. return mgr.getShopList(userId, shopType)
  66. }
  67. item := GetProduct(userId, shopType, productID)
  68. var ret []*Shop_Item
  69. if item != nil {
  70. ret = append(ret, item)
  71. }
  72. return ret
  73. }
  74. func GetShopListByUserId(shopType int, userId int, partnerId int) []*Shop_Item {
  75. list := mgr.getShopList(userId, shopType)
  76. // 苹果渠道,特殊处理
  77. // 100美元以下
  78. price := mgr.getUserPrice(userId, 400)
  79. log.Debug("GetShopListByUserId UserId[%d] PartnerId[%d] price[%.1f]", userId, partnerId, price)
  80. if partnerId >= 20000 && partnerId < 30000 {
  81. for i := 0; i < len(list); {
  82. if list[i].PayType != PayType_RMB {
  83. i++
  84. continue
  85. }
  86. if list[i].Price <= price {
  87. i++
  88. continue
  89. }
  90. log.Debug("GetShopListByUserId UserId[%d] PartnerId[%d] removing[%s] price[%.1f]", userId, partnerId, list[i].ProductId, list[i].Price)
  91. list = append(list[:i], list[i+1:]...)
  92. }
  93. }
  94. return list
  95. }
  96. func GetProduct(userId, shopType int, productId string) *Shop_Item {
  97. return mgr.getProduct(userId, productId)
  98. }
  99. func Exchange(userId int, productId string) (int, string) {
  100. return mgr.exchange(userId, productId)
  101. }
  102. func ExchangeInBulk(userId int, productIds []string) (int, string) {
  103. return mgr.exchangeInBulk(userId, productIds)
  104. }
  105. func SendFirstChargeItem(userId int, productId string) (int, string) {
  106. return mgr.sendFirstChargeItem(userId, productId)
  107. }
  108. func Recharge(userId int, productId string) (int, string) {
  109. return mgr.recharge(userId, productId)
  110. }
  111. // 获取币种信息,传空信息的话,默认选择一个币种
  112. /*
  113. func ExchangeRateInfo(currency string) *exchangeRate {
  114. return mgr.exchangeRateInfo(currency)
  115. }
  116. */
  117. func Dump(param1, param2 string) {
  118. mgr.dump(param1, param2)
  119. }
  120. func GetUserPrice(userId int, price float64) float64 {
  121. return mgr.getUserPrice(userId, price)
  122. }