cardmgr.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package card
  2. import (
  3. "strings"
  4. "bet24.com/log"
  5. "bet24.com/servers/common"
  6. inventory "bet24.com/servers/micros/item_inventory/proto"
  7. )
  8. type cardMgr struct {
  9. }
  10. func newCardMgr() *cardMgr {
  11. obj := &cardMgr{}
  12. log.Debug("card manager running")
  13. return obj
  14. }
  15. // 使用卡
  16. func (this *cardMgr) use(userId int, cardNo string) *cardInfo {
  17. cardNo = strings.ToUpper(cardNo)
  18. switch {
  19. case strings.HasPrefix(cardNo, card_recharge): // 充值卡
  20. return this.useRechargeCard(userId, cardNo)
  21. case strings.HasPrefix(cardNo, card_exchange): // 兑换卡
  22. fallthrough
  23. case strings.HasPrefix(cardNo, card_exchange_vip): // 兑换卡,vip
  24. return this.useExchangeCard(userId, cardNo)
  25. case strings.HasPrefix(cardNo, card_match): // 比赛卡
  26. return this.useMatchCard(userId, cardNo)
  27. }
  28. return nil
  29. }
  30. // 使用充值卡
  31. func (this *cardMgr) useRechargeCard(userId int, cardNo string) *cardInfo {
  32. resp := useRechargeCard(userId, cardNo)
  33. if resp.RetCode == 1 {
  34. // 加道具
  35. if success := inventory.AddItems(userId, resp.Items, "使用充值卡", common.LOGTYPE_RECHARGE_CARD); !success {
  36. log.Debug("useRechargeCard userId=%d cardNo=%s 使用充值卡加金币失败", userId, cardNo)
  37. }
  38. }
  39. return resp
  40. }
  41. // 使用兑换卡
  42. func (this *cardMgr) useExchangeCard(userId int, cardNo string) *cardInfo {
  43. resp := useExchangeCard(userId, cardNo)
  44. if resp.RetCode == 1 {
  45. // 加道具
  46. if success := inventory.AddItems(userId, resp.Items, "使用兑换卡", common.LOGTYPE_EXCHANGE_CARD); !success {
  47. log.Debug("useExchangeCard userId=%d cardNo=%s 使用兑换卡加道具失败", userId, cardNo)
  48. }
  49. }
  50. return resp
  51. }
  52. // 使用比赛卡
  53. func (this *cardMgr) useMatchCard(userId int, cardNo string) *cardInfo {
  54. return useMatchCard(userId, cardNo)
  55. }