add 添加订单号

This commit is contained in:
sk 2025-04-09 16:50:05 +08:00
parent 5614a844b6
commit fec3f97533
6 changed files with 85 additions and 20 deletions

View File

@ -34,6 +34,7 @@ func CoinLogsCollection(plt string) *mongo.Collection {
c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"ts"}, Background: true, Sparse: true})
c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"channel"}, Background: true, Sparse: true})
c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"-ts", "logtype", "cointype", "channel"}, Background: true, Sparse: true})
c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"transferid"}, Background: true, Sparse: true})
}
return c_coinlogrec
}

View File

@ -44,6 +44,7 @@ type CoinLog struct {
DiamondAdd int64 // 钻石加成
GameFreeId int64 // 场次id
BaseCoin int64 // 底分
TransferID string // 订单号
}
type CoinLogV1 struct {
@ -90,6 +91,7 @@ type CoinLogParam struct {
BaseCoin int64 // 底注
Operator string // 操作人
Remark string // 备注
TransferID string
}
func NewCoinLogEx(param *CoinLogParam) *CoinLog {
@ -110,6 +112,7 @@ func NewCoinLogEx(param *CoinLogParam) *CoinLog {
cl.Ts = tNow.Unix()
cl.GameFreeId = param.GameFreeID
cl.BaseCoin = param.BaseCoin
cl.TransferID = param.TransferID
//todo 后期修改数据结构,余额,加成,各用一个字段存储; NewCoinLogExV2
switch param.ChangeType {

View File

@ -259,17 +259,19 @@ type PlatfromGameLoginRsp struct {
// 上分请求
type PlatfromUpScoreReq struct {
Username string `json:"username"`
Channel string `json:"channel"`
Timestamp string `json:"timestamp"`
Count string `json:"count"`
Username string `json:"username"`
Channel string `json:"channel"`
Timestamp string `json:"timestamp"`
Count string `json:"count"`
TransferID string `json:"transferid"`
}
// 上分返回
type PlatfromUpScoreRsp struct {
Code int `json:"code"`
Data struct {
Count int64 `json:"count"`
Count int64 `json:"count"`
TransferID string `json:"transferid"`
} `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
@ -277,16 +279,18 @@ type PlatfromUpScoreRsp struct {
// 下分请求
type PlatfromDownScoreReq struct {
Username string `json:"username"`
Channel string `json:"channel"`
Timestamp string `json:"timestamp"`
Username string `json:"username"`
Channel string `json:"channel"`
Timestamp string `json:"timestamp"`
TransferID string `json:"transferid"`
}
// 下分返回
type PlatfromDownScoreRsp struct {
Code int `json:"code"`
Data struct {
Money string `json:"money"`
Money string `json:"money"`
TransferID string `json:"transferid"`
} `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`

View File

@ -129,6 +129,25 @@ func (this *CacheDataManager) ClearCacheBill(billNo int, platform string) {
this.HourCache.Delete(key)
}
func (this *CacheDataManager) CacheBillStr(billNo string, platform string) {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
this.addCacheData(AfterHour, key, key)
}
func (this *CacheDataManager) CacheBillStrCheck(billNo string, platform string) bool {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
if _, ok := this.HourCache.Load(key); ok {
return true
} else {
return false
}
}
func (this *CacheDataManager) ClearCacheStrBill(billNo string, platform string) {
key := fmt.Sprintf("BillNo-%v-%v", billNo, platform)
this.HourCache.Delete(key)
}
func init() {
common.ClockMgrSingleton.RegisterSinker(CacheDataMgr)
}

View File

@ -1436,7 +1436,7 @@ func (this *Player) AddDiamond(num, add int64, gainWay int32, oper, remark strin
// AddCoin 添加钻石
// num 总数
// add num总数中有多少是加成获得
func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string) {
func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string, param ...string) {
if num == 0 {
return
}
@ -1467,6 +1467,10 @@ func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string)
this.SendDiffData()
if !this.IsRob {
var transferID string
if len(param) > 0 {
transferID = param[0]
}
log := model.NewCoinLogEx(&model.CoinLogParam{
Platform: this.Platform,
SnID: this.SnId,
@ -1482,7 +1486,9 @@ func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string)
BaseCoin: 0,
Operator: oper,
Remark: remark,
TransferID: transferID,
})
if log != nil {
mq.Write(log)
}

View File

@ -3010,8 +3010,15 @@ func init() {
//玩家在线
if player != nil {
if CacheDataMgr.CacheBillStrCheck(msg.TransferID, player.Platform) {
jsonDataRsp, err = json.Marshal(pack)
return common.ResponseTag_ParamError, jsonDataRsp
}
CacheDataMgr.CacheBillStr(msg.TransferID, player.Platform)
remainNum = player.Coin
if player.Coin+addCoin < 0 {
CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform)
pack.Code = int(webapiproto.TagCode_FAILED)
pack.Message = "coin not enough!"
return common.ResponseTag_ParamError, pack
@ -3030,7 +3037,7 @@ func init() {
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = data.(error).Error()
} else {
player.AddCoin(addCoin, 0, common.GainWayPlatformUpScore, "platform", "平台上分")
player.AddCoin(addCoin, 0, common.GainWayPlatformUpScore, "platform", "平台上分", msg.TransferID)
player.SendDiffData()
}
@ -3043,15 +3050,23 @@ func init() {
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform)
}), "/api/platform/upscore").StartByFixExecutor("UserName:" + msg.Username)
} else {
//玩家不在线
var acc *model.Account
acc, err = model.GetAccountByName("1", msg.Username)
if acc == nil {
return common.ResponseTag_ParamError, pack
}
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
acc, err = model.GetAccountByName("1", msg.Username)
if acc == nil {
return errors.New("not found")
}
if CacheDataMgr.CacheBillStrCheck(msg.TransferID, acc.Platform) {
jsonDataRsp, err = json.Marshal(pack)
return errors.New("transfer repeat")
}
CacheDataMgr.CacheBillStr(msg.TransferID, acc.Platform)
findPlayer, _ := model.GetPlayerDataBySnId("1", int32(acc.SnId), false, true)
if findPlayer != nil {
remainNum = findPlayer.Coin
@ -3072,13 +3087,14 @@ func init() {
BaseCoin: 0,
Operator: "休闲平台",
Remark: "不在线平台上分",
TransferID: msg.TransferID,
})
err := model.UpdatePlayerCoin(findPlayer.Platform, findPlayer.SnId, findPlayer.Coin+addCoin,
findPlayer.Diamond, findPlayer.SafeBoxCoin, findPlayer.CoinPayTs, findPlayer.SafeBoxCoinTs, findPlayer.MoneyPayTotal, findPlayer.ShopID)
if err != nil {
logger.Logger.Errorf("model.UpdatePlayerCoin err:%v.", err)
return nil
return err
}
//账变记录
@ -3113,6 +3129,7 @@ func init() {
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
CacheDataMgr.ClearCacheStrBill(msg.TransferID, acc.Platform)
}), "/api/platform/upscore").StartByFixExecutor("UserName:" + msg.Username)
}
@ -3159,6 +3176,12 @@ func init() {
return common.ResponseTag_ParamError, jsonDataRsp
}
if CacheDataMgr.CacheBillStrCheck(msg.TransferID, player.Platform) {
jsonDataRsp, err = json.Marshal(pack)
return common.ResponseTag_ParamError, jsonDataRsp
}
CacheDataMgr.CacheBillStr(msg.TransferID, player.Platform)
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
return nil
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
@ -3167,7 +3190,7 @@ func init() {
remainNum = player.Coin
logger.Logger.Tracef("/api/platform/downscore player online snid:%v, player.Coin:%v", player.SnId, player.Coin)
player.AddCoin(addCoin, 0, common.GainWayPlatformDownScore, "platform", "平台下分")
player.AddCoin(addCoin, 0, common.GainWayPlatformDownScore, "platform", "平台下分", msg.TransferID)
player.SendDiffData()
pack.Code = int(webapiproto.TagCode_SUCCESS)
@ -3182,16 +3205,23 @@ func init() {
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform)
}), "/api/platform/downscore").StartByFixExecutor("UserName:" + msg.Username)
} else {
//玩家不在线
var acc *model.Account
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
var acc *model.Account
acc, err = model.GetAccountByName("1", msg.Username)
if acc == nil {
return nil
return errors.New("not found")
}
if CacheDataMgr.CacheBillStrCheck(msg.TransferID, acc.Platform) {
jsonDataRsp, err = json.Marshal(pack)
return errors.New("transfer repeat")
}
CacheDataMgr.CacheBillStr(msg.TransferID, acc.Platform)
findPlayer, _ := model.GetPlayerDataBySnId(acc.Platform, int32(acc.SnId), false, true)
if findPlayer != nil {
@ -3219,13 +3249,14 @@ func init() {
BaseCoin: 0,
Operator: "休闲平台",
Remark: "不在线平台下分",
TransferID: msg.TransferID,
})
err := model.UpdatePlayerCoin(findPlayer.Platform, findPlayer.SnId, findPlayer.Coin+addCoin,
findPlayer.Diamond, findPlayer.SafeBoxCoin, findPlayer.CoinPayTs, findPlayer.SafeBoxCoinTs, findPlayer.MoneyPayTotal, findPlayer.ShopID)
if err != nil {
logger.Logger.Errorf("model.UpdatePlayerCoin err:%v.", err)
return nil
return err
}
//账变记录
@ -3260,6 +3291,7 @@ func init() {
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
CacheDataMgr.ClearCacheStrBill(msg.TransferID, acc.Platform)
}), "/api/platform/downscore").StartByFixExecutor("UserName:" + msg.Username)
}
return common.ResponseTag_TransactYield, jsonDataRsp