From 4e39cb4afe0c9426501cd98c4981f408d6f7cf2e Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 18 Jul 2023 11:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=A5=96=E5=8A=B1=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E5=95=86=E9=98=9F=E9=87=8D=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 4 ++ modules/atlas/module.go | 5 +-- modules/caravan/api_buyorsell.go | 36 +++++++--------- modules/caravan/api_getlist.go | 9 ++-- modules/caravan/comp_configure.go | 20 --------- modules/caravan/model_caravan.go | 3 +- modules/mail/module.go | 62 +++++++++++++++++++++++++++ pb/caravan_db.pb.go | 69 +++++++++++++++++++------------ 8 files changed, 135 insertions(+), 73 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index c42d22cc8..6a3131183 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -45,10 +45,14 @@ type ( //邮件业务模块对外接口定义 提供给其他模块使用的 Imail interface { + // 注意 此接口逐步废弃 SendMailByCid(session IUserSession, cid string, res []*pb.UserAssets) bool SendNewMail(mail *pb.DBMailData, uid ...string) bool // 批量发送邮件 支持跨服 SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Param []string) bool IGetReddot + + // 所有邮件奖励统一调这个接口 + SendRewardMailByCid(session IUserSession, cid string, res []*cfg.Gameatn) bool } //道具背包接口 IItems interface { diff --git a/modules/atlas/module.go b/modules/atlas/module.go index b7e42c903..55cbd4a71 100644 --- a/modules/atlas/module.go +++ b/modules/atlas/module.go @@ -73,9 +73,8 @@ func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) (e Time: configure.Now().Unix(), Activate: false, } - update := make(map[string]interface{}, 0) - update["collect"] = atlas.Collect - if err = model.Add(uid, update); err != nil { + + if err = model.Add(uid, atlas); err != nil { this.Errorf("err:%v", err) } return diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index cf4ed01e4..d57f0b4c4 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -147,28 +147,24 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe } // 商队盈利收益奖励 - var old int64 // 计算之前的结果 - if u := this.module.ModuleUser.GetUser(session.GetUserId()); u != nil { - old = u.Profit - } reward := this.configure.GetCaravanReward() - for index, v := range reward { - if v.Key == 0 || v.Key <= int32(old) { - - continue - } - if len(reward) > index+1 && reward[index+1].Key > int32(old)+addScore { - var ( - res []*pb.UserAssets - ) - for _, v := range reward[index+1].Reward { - res = append(res, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) + for _, v := range reward { + if v.Key > 0 { + if caravan.Profit > int64(v.Key) { + if _, ok := caravan.Reward[v.Key]; !ok { + var res []*pb.UserAssets + for _, v1 := range v.Reward { + res = append(res, &pb.UserAssets{ + A: v1.A, + T: v1.T, + N: v1.N, + }) + } + this.module.ModuleMail.SendMailByCid(session, "CaravanProfitRewards", res) + caravan.Reward[v.Key] = true + update["reward"] = caravan.Reward + } } - this.module.ModuleMail.SendMailByCid(session, "CaravanProfitRewards", res) } } } else { // 买入 diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index 2e90bbec9..901a1582b 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -40,9 +40,12 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe return } // list.Merchantmoney = conf.Moneynumtop.N - // update := make(map[string]interface{}) - // update["merchantmoney"] = list.Merchantmoney // 更新虚拟币 - // this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) + update := make(map[string]interface{}) + list.Reward = make(map[int32]bool, 0) + list.Profit = 0 + update["reward"] = list.Reward // 初始化利润奖励 + update["profit"] = list.Profit // 初始化商品利润 + this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) } } // 刷新城市货物信息 diff --git a/modules/caravan/comp_configure.go b/modules/caravan/comp_configure.go index fb0b862bb..d48b721d9 100644 --- a/modules/caravan/comp_configure.go +++ b/modules/caravan/comp_configure.go @@ -53,7 +53,6 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp this.lock.Unlock() }) - this.FindCaravanReward(4500) return } @@ -210,25 +209,6 @@ func (this *configureComp) GetCaravanReward() (reward []*cfg.GameCaravanRewardDa return } -// 找到指定奖励区间的数据 -func (this *configureComp) FindCaravanReward(score int32) (index int32) { - score = 2500 - if v, err := this.GetConfigure(game_caravan_reward); err == nil { - if configure, ok := v.(*cfg.GameCaravanReward); ok { - reward := configure.GetDataList() - for ipos, v := range reward { - if score >= v.Key && len(reward) > ipos+1 && score <= reward[ipos+1].Key { - index = int32(ipos) + 1 - return - } - } - } - } else { - log.Errorf("get GetCaravanInitCity conf err:%v", err) - } - return -} - func (this *configureComp) GetCaravanMoreReward() (reward []*cfg.Gameatn) { if v, err := this.GetConfigure(game_caravan_reward); err == nil { if configure, ok := v.(*cfg.GameCaravanReward); ok { diff --git a/modules/caravan/model_caravan.go b/modules/caravan/model_caravan.go index 351d532c6..9fd42d6db 100644 --- a/modules/caravan/model_caravan.go +++ b/modules/caravan/model_caravan.go @@ -40,7 +40,8 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err Goods: map[string]*pb.Goods{}, City: map[int32]*pb.CityInfo{}, Oldprice: map[string]int32{}, - Group: make(map[int32]bool), + Group: make(map[int32]bool, 0), + Reward: make(map[int32]bool, 0), } if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { // 创建一条数据 diff --git a/modules/mail/module.go b/modules/mail/module.go index 553537e76..7596c9d34 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -301,3 +301,65 @@ func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Para } return true } +func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res []*cfg.Gameatn) bool { + var ( + resReward []*pb.UserAssets + ) + + // 获取额外配置 + conf := this.configure.GetMailConf(cid) + if conf == nil { + this.Errorf("can't found mail by cid: %s", cid) + return false + } + if len(conf.Reword) > 0 { + res = append(res, conf.Reword...) + + } + for _, v := range res { + resReward = append(resReward, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + // 构建一个每日奖励邮件对象 + mail := &pb.DBMailData{ + ObjId: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + CreateTime: uint64(configure.Now().Unix()), + DueTime: uint64(configure.Now().Unix() + 30*24*3600), + Items: resReward, + Cid: cid, + Param: []string{}, + } + mail.Check = false + mail.Reward = true + + if len(mail.GetItems()) > 0 { + mail.Reward = false + } + + if db.IsCross() { // 如果是跨服 则取本服的db + tag, _, b := utils.UIdSplit(session.GetUserId()) + if b { + if conn, err := db.ServerDBConn(tag); err == nil { + dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + + if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil { + this.Errorf("InsertOne mail failed:%v", err) + } + } + } + } else { + err := this.modelMail.MailInsertUserMail(mail) + if err != nil { + this.Errorf("create mail failed :%v", err) + return false + } + } + // 通知玩家 + this.AddNewMailPush(session, mail) + + return true +} diff --git a/pb/caravan_db.pb.go b/pb/caravan_db.pb.go index 24c24f052..b8b5a2de6 100644 --- a/pb/caravan_db.pb.go +++ b/pb/caravan_db.pb.go @@ -248,6 +248,7 @@ type DBCaravan struct { Oldprice map[string]int32 `protobuf:"bytes,16,rep,name=oldprice,proto3" json:"oldprice" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 上一次价格 key 货物ID Rtime int64 `protobuf:"varint,17,opt,name=rtime,proto3" json:"rtime"` // 客户端不用这个时间 Group map[int32]bool `protobuf:"bytes,18,rep,name=group,proto3" json:"group" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //服务器用 + Reward map[int32]bool `protobuf:"bytes,19,rep,name=reward,proto3" json:"reward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 记录盈利奖励 } func (x *DBCaravan) Reset() { @@ -401,6 +402,13 @@ func (x *DBCaravan) GetGroup() map[int32]bool { return nil } +func (x *DBCaravan) GetReward() map[int32]bool { + if x != nil { + return x.Reward + } + return nil +} + type CaravanRankInfo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -527,7 +535,7 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{ 0x22, 0x35, 0x0a, 0x07, 0x42, 0x61, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0xd3, 0x06, 0x0a, 0x09, 0x44, 0x42, 0x43, 0x61, + 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0xbe, 0x07, 0x0a, 0x09, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x2b, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, @@ -560,7 +568,10 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{ 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x2e, 0x47, 0x72, 0x6f, 0x75, 0x70, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x1a, 0x42, 0x0a, 0x0a, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x2e, 0x0a, 0x06, + 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x18, 0x13, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x44, + 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x2e, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x1a, 0x42, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, @@ -580,20 +591,24 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{ 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xbf, 0x01, - 0x0a, 0x0f, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x66, - 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x6c, - 0x76, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x6c, 0x76, 0x12, - 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0d, 0x6d, - 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x0d, 0x6d, 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x6d, 0x6f, 0x6e, 0x65, - 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x4c, 0x76, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x4c, 0x76, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x39, 0x0a, + 0x0b, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xbf, 0x01, 0x0a, 0x0f, 0x43, 0x61, 0x72, + 0x61, 0x76, 0x61, 0x6e, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, + 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x6c, 0x76, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x6c, 0x76, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, + 0x61, 0x74, 0x61, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, + 0x61, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0d, 0x6d, 0x65, 0x72, 0x63, 0x68, 0x61, + 0x6e, 0x74, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x6d, + 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x09, + 0x63, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x4c, 0x76, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x09, 0x63, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x4c, 0x76, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -608,7 +623,7 @@ func file_caravan_caravan_db_proto_rawDescGZIP() []byte { return file_caravan_caravan_db_proto_rawDescData } -var file_caravan_caravan_db_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_caravan_caravan_db_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_caravan_caravan_db_proto_goTypes = []interface{}{ (*Goods)(nil), // 0: Goods (*CityInfo)(nil), // 1: CityInfo @@ -621,6 +636,7 @@ var file_caravan_caravan_db_proto_goTypes = []interface{}{ nil, // 8: DBCaravan.CityEntry nil, // 9: DBCaravan.OldpriceEntry nil, // 10: DBCaravan.GroupEntry + nil, // 11: DBCaravan.RewardEntry } var file_caravan_caravan_db_proto_depIdxs = []int32{ 5, // 0: CityInfo.count:type_name -> CityInfo.CountEntry @@ -629,14 +645,15 @@ var file_caravan_caravan_db_proto_depIdxs = []int32{ 8, // 3: DBCaravan.city:type_name -> DBCaravan.CityEntry 9, // 4: DBCaravan.oldprice:type_name -> DBCaravan.OldpriceEntry 10, // 5: DBCaravan.group:type_name -> DBCaravan.GroupEntry - 2, // 6: DBCaravan.ItemsEntry.value:type_name -> BagInfo - 0, // 7: DBCaravan.GoodsEntry.value:type_name -> Goods - 1, // 8: DBCaravan.CityEntry.value:type_name -> CityInfo - 9, // [9:9] is the sub-list for method output_type - 9, // [9:9] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 11, // 6: DBCaravan.reward:type_name -> DBCaravan.RewardEntry + 2, // 7: DBCaravan.ItemsEntry.value:type_name -> BagInfo + 0, // 8: DBCaravan.GoodsEntry.value:type_name -> Goods + 1, // 9: DBCaravan.CityEntry.value:type_name -> CityInfo + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_caravan_caravan_db_proto_init() } @@ -712,7 +729,7 @@ func file_caravan_caravan_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_caravan_caravan_db_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 0, },