Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2022-08-01 15:02:34 +08:00
commit fb40ce3f19
19 changed files with 98 additions and 62 deletions

View File

@ -67,7 +67,7 @@ type (
//获取用户expand
GetUserExpand(uid string) (result *pb.DBUserExpand, err error)
//更新用户expand
ChanageUserExpand(uid string, value map[string]interface{}) error
ChangeUserExpand(uid string, value map[string]interface{}) error
}
//武器模块
IEquipment interface {

View File

@ -28,7 +28,7 @@ func (this *apiComp) ChanageChannel(session comm.IUserSession, req *pb.ChatChana
code = pb.ErrorCode_DBError
return
}
this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
"chatchannel": req.ChannelId,
})
}

View File

@ -23,7 +23,7 @@ func (this *apiComp) CrossChannel(session comm.IUserSession, req *pb.ChatCrossCh
code = pb.ErrorCode_DBError
return
}
this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
"chatchannel": channel,
})
session.SendMsg(string(this.module.GetType()), "crosschannel", &pb.ChatCrossChannelResp{ChannelId: channel})

View File

@ -11,11 +11,9 @@ import (
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db"
"reflect"
"time"
"unsafe"
"github.com/modern-go/reflect2"
@ -671,31 +669,31 @@ func (this *MCompModel) logOpt(uid string, data interface{}, attrs ...*cache.Ope
}
//获取用户通过扩展表
func (this *MCompModel) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) {
result = &pb.DBUserRecord{}
key := fmt.Sprintf("userrecord:%s{userrecord}", uid)
if err = this.Redis.HGetAll(key, result); err != nil && err != redis.RedisNil {
return
}
if err == redis.RedisNil {
if err = this.DB.FindOne(core.SqlTable("userrecord"), bson.M{"uid": uid}).Decode(result); err != nil {
return
}
err = this.Redis.HMSet(key, result)
}
return
}
// func (this *MCompModel) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) {
// result = &pb.DBUserRecord{}
// key := fmt.Sprintf("userrecord:%s{userrecord}", uid)
// if err = this.Redis.HGetAll(key, result); err != nil && err != redis.RedisNil {
// return
// }
// if err == redis.RedisNil {
// if err = this.DB.FindOne(core.SqlTable("userrecord"), bson.M{"uid": uid}).Decode(result); err != nil {
// return
// }
// err = this.Redis.HMSet(key, result)
// }
// return
// }
//修改用户扩展数据
func (this *MCompModel) ChangeUserRecord(uid string, value map[string]interface{}) (err error) {
value["mtime"] = time.Now().Unix() // 更新时间
key := fmt.Sprintf("userrecord:%s{userrecord}", uid)
if err = this.Redis.HMSet(key, value); err != nil && err != redis.RedisNil {
return
}
err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value)
return
}
// //修改用户扩展数据
// func (this *MCompModel) ChangeUserRecord(uid string, value map[string]interface{}) (err error) {
// value["mtime"] = time.Now().Unix() // 更新时间
// key := fmt.Sprintf("userrecord:%s{userrecord}", uid)
// if err = this.Redis.HMSet(key, value); err != nil && err != redis.RedisNil {
// return
// }
// err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value)
// return
// }
// 删除玩家缓存信息
func (this *MCompModel) CleanUserRecord(uid string) (err error) {

View File

@ -53,27 +53,39 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
}
}
// =======活动数据记录完成
rst, _ := this.module.modelHero.GetUserRecord(session.GetUserId())
rst, _ := this.module.modelRecord.GetUserRecord(session.GetUserId())
if req.DrawType%2 == 0 { // 转成对应阵营信息 1~5
race = int32((int(req.DrawType)) / 2)
} else {
race = int32(int(req.DrawType+1) / 2)
}
if race == comm.RacePt { // 普通卡池
curStar4Count = rst.Race0.H4
curStar5Count = rst.Race0.H5
if rst.Race0 != nil {
curStar4Count = rst.Race0.H4
curStar5Count = rst.Race0.H5
}
} else if race == comm.RaceZr { // 灼热
curStar4Count = rst.Race1.H4
curStar5Count = rst.Race1.H5
if rst.Race1 != nil {
curStar4Count = rst.Race1.H4
curStar5Count = rst.Race1.H5
}
} else if race == comm.RaceYd { // 涌动
curStar4Count = rst.Race2.H4
curStar5Count = rst.Race2.H5
if rst.Race2 != nil {
curStar4Count = rst.Race2.H4
curStar5Count = rst.Race2.H5
}
} else if race == comm.RaceHx { // 呼啸
curStar4Count = rst.Race3.H4
curStar5Count = rst.Race3.H5
if rst.Race3 != nil {
curStar4Count = rst.Race3.H4
curStar5Count = rst.Race3.H5
}
} else if race == comm.RaceSy { // 闪耀
curStar4Count = rst.Race4.H4
curStar5Count = rst.Race4.H5
if rst.Race4 != nil {
curStar4Count = rst.Race4.H4
curStar5Count = rst.Race4.H5
}
}
// 获取配置文件的权重信息
_conf, err := this.module.configure.GetHeroDrawConfig(race)
@ -185,7 +197,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
update := map[string]interface{}{}
update["race"+strconv.Itoa(int(race)-1)] = raceData
this.module.modelHero.ChangeUserRecord(session.GetUserId(), update)
this.module.modelRecord.ChangeUserRecord(session.GetUserId(), update)
// 消耗道具
code = this.module.ConsumeRes(session, sz, true)
if code != pb.ErrorCode_Success {

View File

@ -123,7 +123,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
"tujian": sz,
}
this.moduleHero.ModuleUser.ChanageUserExpand(uid, initUpdate)
this.moduleHero.ModuleUser.ChangeUserExpand(uid, initUpdate)
}
}
hero.SameCount = count

View File

@ -1,10 +1,12 @@
package user
package hero
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/mongo"
)
// 记录一些扩展数据 图鉴 改名次数等
@ -27,3 +29,22 @@ func (this *ModelRecord) getUserSession(uid string) (cuser *pb.CacheUser) {
}
return
}
//获取用户通过扩展表
func (this *ModelRecord) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) {
result = &pb.DBUserRecord{}
if err = this.Get(uid, result); err != nil && err != mongo.ErrNoDocuments {
return
}
err = nil
return result, err
}
//修改用户扩展数据
func (this *ModelRecord) ChangeUserRecord(uid string, value map[string]interface{}) (err error) {
if len(value) == 0 {
return nil
}
return this.Change(uid, value)
}

View File

@ -16,9 +16,10 @@ func NewModule() core.IModule {
type Hero struct {
modules.ModuleBase
api *apiComp
configure *configureComp
modelHero *ModelHero
api *apiComp
configure *configureComp
modelHero *ModelHero
modelRecord *ModelRecord
}
//模块名
@ -37,6 +38,7 @@ func (this *Hero) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelHero = this.RegisterComp(new(ModelHero)).(*ModelHero)
this.modelRecord = this.RegisterComp(new(ModelRecord)).(*ModelRecord)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}

View File

@ -21,9 +21,7 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq
err error
mail *pb.DBMailData
)
defer func() {
session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail})
}()
code = this.ReadMailCheck(session, req) // check
if code != pb.ErrorCode_Success {
return
@ -31,7 +29,9 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq
mail, err = this.module.modelMail.Mail_ReadOneMail(req.ObjID)
if err != nil {
code = pb.ErrorCode_ReqParameterError
return
}
mail.Check = true
session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail})
return
}

View File

@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq
userexpand = &pb.DBUserExpand{}
}
//修改最后公告读取时间
this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
"lastreadnotiftime": time.Now().Unix(),
})
session.SendMsg(string(this.module.GetType()), "getlist", &pb.NotifyGetListResp{LastReadTime: userexpand.Lastreadnotiftime, SysNotify: notify})

View File

@ -63,7 +63,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
update["activeweek"] = ue.Activeweek + conf.Active
}
if len(update) > 0 {
if err = this.moduleTask.ModuleUser.ChanageUserExpand(session.GetUserId(), update); err != nil {
if err = this.moduleTask.ModuleUser.ChangeUserExpand(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_DBError
return
}

View File

@ -72,7 +72,7 @@ func (this *ModuleTask) resetActive(uid string, taskTag comm.TaskTag) {
update["activeweek"] = 0
}
if len(update) > 0 {
this.ModuleUser.ChanageUserExpand(uid, update)
this.ModuleUser.ChangeUserExpand(uid, update)
}
}

View File

@ -62,7 +62,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
initUpdate := map[string]interface{}{
"modifynameCount": 1, //修改名称1次
}
if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), initUpdate); err != nil {
if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), initUpdate); err != nil {
code = pb.ErrorCode_DBError
return
}

View File

@ -82,7 +82,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c
update = utils.StructToMap(curFigure)
this.module.modelExpand.ChanageUserExpand(session.GetUserId(), update)
this.module.modelExpand.ChangeUserExpand(session.GetUserId(), update)
}
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil {

View File

@ -56,7 +56,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
mc := map[string]interface{}{
"modifynameCount": left,
}
if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), mc); err != nil {
if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), mc); err != nil {
code = pb.ErrorCode_DBError
return
}

View File

@ -31,7 +31,7 @@ func (this *apiComp) Modifysign(session comm.IUserSession, req *pb.UserModifysig
update := map[string]interface{}{
"sign": req.Sign,
}
this.module.ChanageUserExpand(session.GetUserId(), update)
this.module.ChangeUserExpand(session.GetUserId(), update)
}
if err = session.SendMsg(string(this.module.GetType()), UserSubTypeModifySign, &pb.UserModifysignResp{

View File

@ -5,6 +5,8 @@ import (
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/mongo"
)
// 记录一些扩展数据
@ -33,14 +35,15 @@ func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) {
//获取用户通过扩展表
func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) {
result = &pb.DBUserExpand{}
if err = this.moduleUser.modelExpand.Get(uid, result); err != nil {
if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && err != mongo.ErrNoDocuments {
return
}
err = nil
return result, err
}
//修改用户扩展数据
func (this *ModelExpand) ChanageUserExpand(uid string, value map[string]interface{}) (err error) {
func (this *ModelExpand) ChangeUserExpand(uid string, value map[string]interface{}) (err error) {
if len(value) == 0 {
return nil
}

View File

@ -152,7 +152,7 @@ func (this *ModelUser) InitFigure(uid string) {
update := map[string]interface{}{
"preinstall": figureMap,
}
this.moduleUser.modelExpand.ChanageUserExpand(uid, update)
this.moduleUser.modelExpand.ChangeUserExpand(uid, update)
}
// change exp

View File

@ -176,6 +176,6 @@ func (this *User) GetUserExpand(uid string) (result *pb.DBUserExpand, err error)
return this.modelExpand.GetUserExpand(uid)
}
func (this *User) ChanageUserExpand(uid string, value map[string]interface{}) error {
return this.modelExpand.ChanageUserExpand(uid, value)
func (this *User) ChangeUserExpand(uid string, value map[string]interface{}) error {
return this.modelExpand.ChangeUserExpand(uid, value)
}