betmgr.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package bet
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. "bet24.com/servers/common"
  6. )
  7. type betmgr struct {
  8. }
  9. func newBetMgr() *betmgr {
  10. log.Debug("bet manager running")
  11. return &betmgr{}
  12. }
  13. // 投注列表
  14. func (bm *betmgr) betList(userId, gameId, days, pageIndex, pageSize int, betZone string) *BetInfo_Resp {
  15. return betList(userId, gameId, days, pageIndex, pageSize, betZone)
  16. }
  17. // 游戏历史
  18. func (bm *betmgr) gameHistory(userId, pageIndex, pageSize int) (int, []*History) {
  19. return gameHistory(userId, pageIndex, pageSize)
  20. }
  21. // 游戏记录
  22. func (bm *betmgr) getGameCount(userId, gameId int) []*GameCount {
  23. return getGameCount(userId, gameId)
  24. }
  25. // 更新domino游戏记录
  26. func (bm *betmgr) updateDominoGameCount(userId, double, triple, quariter, qunitet int, cardData string) {
  27. //log.Debug("betmgr.updateDominoGameCount userId=%d double=%d triple=%d quariter=%d qunitet=%d cardData=%s",
  28. // userId, double, triple, quariter, qunitet, cardData)
  29. list := bm.getGameCount(userId, common.Game_Domino)
  30. if len(list) <= 0 {
  31. return
  32. }
  33. var d dominoStat
  34. if len(list[0].CardStat) > 0 {
  35. if err := json.Unmarshal([]byte(list[0].CardStat), &d); err != nil {
  36. log.Error("betmgr.updateDominoGameCount json unmarshal fail %v ==> %s", err, list[0].CardStat)
  37. }
  38. }
  39. d.Double = d.Double + double
  40. d.Triple = d.Triple + triple
  41. d.Quariter = d.Quariter + quariter
  42. d.Qunitet = d.Qunitet + qunitet
  43. buf, _ := json.Marshal(d)
  44. updateCardStat(userId, common.Game_Domino, string(buf), cardData)
  45. }
  46. // 更新qiuqiu游戏记录
  47. func (bm *betmgr) updateQiuqiuGameCount(userId, sixDevil, twinCards, smallCards, bigCards, qiuqiu int, cardData string) {
  48. //log.Debug("betmgr.updateQiuqiuGameCount userId=%d sixDeivl=%d twinCards=%d smallCards=%d bigCards=%d qiuqiu=%d cardData=%s",
  49. // userId, sixDevil, twinCards, smallCards, bigCards, qiuqiu, cardData)
  50. list := bm.getGameCount(userId, common.Game_Qiuqiu)
  51. if len(list) <= 0 {
  52. return
  53. }
  54. var d qiuqiuStat
  55. if len(list[0].CardStat) > 0 {
  56. if err := json.Unmarshal([]byte(list[0].CardStat), &d); err != nil {
  57. log.Error("betmgr.updateQiuqiuGameCount json unmarshal fail %v ==> %s", err, list[0].CardStat)
  58. }
  59. }
  60. d.SixDevil = d.SixDevil + sixDevil
  61. d.TwinCards = d.TwinCards + twinCards
  62. d.SmallCards = d.SmallCards + smallCards
  63. d.BigCards = d.BigCards + bigCards
  64. d.QiuQiu = d.QiuQiu + qiuqiu
  65. buf, _ := json.Marshal(d)
  66. updateCardStat(userId, common.Game_Qiuqiu, string(buf), cardData)
  67. }