125 lines
3.1 KiB
Go
125 lines
3.1 KiB
Go
package model
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"mongo.games.com/goserver/core/logger"
|
|
)
|
|
|
|
//go:generate mongoctl -model-dir=. -model-names=RedPacket -dao-dir=../dao/
|
|
type RedPacket struct {
|
|
ID primitive.ObjectID `bson:"_id" gen:"autoFill"`
|
|
Cid int64 `bson:"cid"` // 红包活动id
|
|
Use map[int64]int64 `bson:"use"` // 已发红包 红包奖励数量:已发个数
|
|
Ts int64 `bson:"ts"` // 更新时间戳
|
|
}
|
|
|
|
func (r *RedPacket) DatabaseName() string {
|
|
return "log"
|
|
}
|
|
|
|
func (r *RedPacket) CollectionName() string {
|
|
return "log_redpacket"
|
|
}
|
|
|
|
func GetRedPacketAll(plt string) (res []*RedPacket, err error) {
|
|
if rpcCli == nil {
|
|
logger.Logger.Error("model.GetRedPacketAll rpcCli == nil")
|
|
return nil, errors.New("rpc client is nil")
|
|
}
|
|
|
|
res = make([]*RedPacket, 0)
|
|
|
|
err = rpcCli.CallWithTimeout("RedPacketService.GetAll", &plt, &res, time.Second*30)
|
|
if err != nil {
|
|
logger.Logger.Errorf("GetRedPacketAll error: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
type UpdateRedPacketAllReq struct {
|
|
Plt string
|
|
List []*RedPacket
|
|
}
|
|
|
|
func UpdateRedPacketAll(plt string, list []*RedPacket) error {
|
|
if rpcCli == nil {
|
|
logger.Logger.Error("model.UpdateRedPacketAll rpcCli == nil")
|
|
return errors.New("rpc client is nil")
|
|
}
|
|
req := &UpdateRedPacketAllReq{
|
|
Plt: plt,
|
|
List: list,
|
|
}
|
|
res := false
|
|
|
|
err := rpcCli.CallWithTimeout("RedPacketService.UpdateAll", req, &res, time.Second*30)
|
|
if err != nil {
|
|
logger.Logger.Errorf("UpdateRedPacketAll error: %v", err)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// BackRedPacket 红包统计数据
|
|
type BackRedPacket struct {
|
|
Platform string // 平台
|
|
Id int32 // 红包活动id
|
|
SnId int32 // 玩家id
|
|
ItemId int32 // 道具id
|
|
ItemNum int64 // 道具数量
|
|
Ts int64 // 时间戳
|
|
}
|
|
|
|
//go:generate mongoctl -model-dir=. -model-names=RedPacketHistory -dao-dir=../dao/
|
|
type RedPacketHistory struct {
|
|
Platform string `bson:"-"` // 平台
|
|
ID primitive.ObjectID `bson:"_id" gen:"autoFill"`
|
|
Cid int64 `bson:"cid"` // 红包活动id
|
|
Snid int32 `bson:"snid"` // 玩家id
|
|
Ts int64 `bson:"ts"` // 时间戳
|
|
ItemId int32 `bson:"itemid"` // 道具id
|
|
ItemNum int64 `bson:"itemnum"` // 道具数量
|
|
}
|
|
|
|
func (r *RedPacketHistory) DatabaseName() string {
|
|
return "log"
|
|
}
|
|
|
|
func (r *RedPacketHistory) CollectionName() string {
|
|
return "log_redpackethistory"
|
|
}
|
|
|
|
type GetRedPacketHistoryReq struct {
|
|
Plt string
|
|
Snid int32
|
|
Cid int64
|
|
}
|
|
|
|
func GetRedPacketHistory(plt string, snid int32, cid int64) (res []*RedPacketHistory, err error) {
|
|
if rpcCli == nil {
|
|
logger.Logger.Error("model.GetRedPacketHistory rpcCli == nil")
|
|
return nil, errors.New("rpc client is nil")
|
|
}
|
|
|
|
req := &GetRedPacketHistoryReq{
|
|
Plt: plt,
|
|
Snid: snid,
|
|
Cid: cid,
|
|
}
|
|
res = make([]*RedPacketHistory, 0)
|
|
|
|
err = rpcCli.CallWithTimeout("RedPacketService.GetHistory", req, &res, time.Second*30)
|
|
if err != nil {
|
|
logger.Logger.Errorf("GetRedPacketHistory error: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|