github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/game/internal/agents.go (about)

     1  package internal
     2  
     3  import (
     4  	"github.com/name5566/leaf/log"
     5  	mgo "gopkg.in/mgo.v2"
     6  	"gopkg.in/mgo.v2/bson"
     7  )
     8  
     9  type AgentProfit struct {
    10  	Accountid       int
    11  	Chips           int64
    12  	FirstLevelChips int64
    13  	OtherLevelChips int64
    14  	CreateDat       int64
    15  	Str             string
    16  }
    17  
    18  func (a *AgentProfit) insert() {
    19  	db := mongoDB.Ref()
    20  	defer mongoDB.UnRef(db)
    21  	selector := bson.M{"accountid": a.Accountid, "createdat": a.CreateDat}
    22  	b := new(AgentProfit)
    23  	err := db.DB(DB).C("agent_profit").Find(selector).One(b)
    24  	if err != nil && err != mgo.ErrNotFound {
    25  		log.Release("查找玩家当日收益失败")
    26  		return
    27  	}
    28  	if err == mgo.ErrNotFound {
    29  		db.DB(DB).C("agent_profit").Insert(a)
    30  		return
    31  	}
    32  	update := bson.M{
    33  		"$inc": bson.M{
    34  			"firstlevelchips": a.FirstLevelChips,
    35  			"otherlevelchips": a.OtherLevelChips,
    36  			"chips":           a.Chips,
    37  		},
    38  	}
    39  	db.DB(DB).C("agent_profit").Update(selector, update)
    40  }