github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/game/internal/records.go (about) 1 package internal 2 3 import ( 4 "common" 5 "github.com/name5566/leaf/log" 6 "gopkg.in/mgo.v2/bson" 7 "time" 8 ) 9 10 type GameRecord struct { 11 AccountId int //用户Id 12 Desc string //房间描述 13 RoomNumber string //房间号 14 Profit int64 //资金变化 15 Amount int64 //当前余额 16 StartTimestamp int64 // 开始时间 17 EndTimestamp int64 // 结束时间 18 Results []ResultData //对战详情 19 Nickname string // 昵称 20 IsSpring bool //这一局是否为春天 21 LastThree []string //三张底牌 22 Channel int //渠道号 23 } 24 25 type ResultData struct { 26 AccountId int //用户Id 27 Nickname string // 昵称 28 Desc string 29 Dealer bool //是否是庄家 30 Hands []string //手牌 31 Chips int64 //金币 32 Headimgurl string //头像地址 33 } 34 35 func saveGameRecord(temp *GameRecord) { 36 log.Release("保存战绩") 37 skeleton.Go(func() { 38 db := mongoDB.Ref() 39 defer mongoDB.UnRef(db) 40 err := db.DB(DB).C("gamerecord").Insert(temp) 41 if err != nil { 42 log.Error("insert redpacketmatchresult data error: %v", err) 43 } 44 }, nil) 45 } 46 47 type RedPacketGrantRecord struct { 48 CreatedAt int64 //用户充值时间 49 Nickname string //昵称 50 AccountID int //用户ID 51 GrantType int //发放类型,1 为红包任务 2 为分享赚钱 52 Desc string //原因 53 Value float64 //金额 54 Channel int //渠道号 55 } 56 57 func (ctx *RedPacketGrantRecord)Save() error { 58 db := mongoDB.Ref() 59 defer mongoDB.UnRef(db) 60 return db.DB(DB).C("red_packet_grant_record").Insert(ctx) 61 } 62 63 func WriteRedPacketGrantRecord(userData *UserData, grantType int, desc string, fee float64) { 64 redPacketGrantRecord := &RedPacketGrantRecord{ 65 CreatedAt:time.Now().Unix(), 66 Nickname:userData.Nickname, 67 AccountID:userData.AccountID, 68 GrantType:grantType, 69 Desc:desc, 70 Value:fee, 71 Channel:userData.Channel, 72 } 73 74 go func() { 75 if err := redPacketGrantRecord.Save();err != nil { 76 log.Error(err.Error()) 77 } 78 }() 79 } 80 81 type RechargeRecord struct { 82 CreatedAt int64 //完成时间 83 AccountID int //用户id 84 NickName string //用户昵称 85 Desc string //购买商品类型:金币、钻石 86 Value float64 //金额 87 Channel int //充值渠道 1. wxpay 2. alipay 3. applepay 88 DownChannel int //渠道号 89 } 90 91 func (ctx *RechargeRecord) Save () error { 92 se := mongoDB.Ref() 93 defer mongoDB.UnRef(se) 94 return se.DB(DB).C("recharge_record").Insert(ctx) 95 } 96 97 func WriteRechageRecord (userData *UserData, createdAt int64, desc string, value float64, channel int) { 98 rechargeRedcord := &RechargeRecord{ 99 CreatedAt: createdAt, 100 AccountID:userData.AccountID, 101 NickName:userData.Nickname, 102 Desc:desc, 103 Value:value, 104 Channel:channel, 105 DownChannel:userData.Channel, 106 } 107 108 go func() { 109 if err := rechargeRedcord.Save(); err != nil { 110 log.Error(err.Error()) 111 } 112 }() 113 } 114 115 //搜狗活跃人数统计 116 type SougouActivityRecord struct { 117 Num int 118 CreatedAt int64 119 } 120 121 func (ctx *SougouActivityRecord) Save () error { 122 se := mongoDB.Ref() 123 defer mongoDB.UnRef(se) 124 _,err := se.DB(DB).C("sougou_activity_record").Upsert( 125 bson.M{"createdat" : common.OneDay0ClockTimestamp(time.Now())}, 126 bson.M{"$inc" : bson.M{"num" : 1}}) 127 return err 128 } 129 130 func WriteSougouActivityRecord() { 131 sougouActivityRecord := &SougouActivityRecord{} 132 go func() { 133 if err := sougouActivityRecord.Save(); err != nil { 134 log.Error(err.Error()) 135 } 136 }() 137 } 138 139 type ChipsRecord struct { 140 AccountID int 141 CreatedAt int64 142 ActionType int 143 NickName string 144 AddChips int64 145 Chips int64 146 DownChannel int //渠道号 147 } 148 149 func (ctx *ChipsRecord) Save() error { 150 se := mongoDB.Ref() 151 defer mongoDB.UnRef(se) 152 return se.DB(DB).C("chip_record").Insert(ctx) 153 } 154 155 const ( 156 rechargeChip = 1 157 subsidyChip = 2 158 SignInChip = 3 159 ) 160 func WriteChipsRecord(userData *UserData, addChip int64, actionType int) { 161 chipsRecord := &ChipsRecord{ 162 AccountID :userData.AccountID, 163 CreatedAt :time.Now().Unix(), 164 ActionType :actionType, 165 NickName :userData.Nickname, 166 AddChips :addChip, 167 Chips :userData.Chips, 168 DownChannel :userData.Channel, 169 } 170 171 go func() { 172 if err := chipsRecord.Save(); err != nil { 173 log.Error(err.Error()) 174 } 175 }() 176 }