This commit is contained in:
liwei1dao 2022-06-09 11:26:10 +08:00
commit f9185698e0
7 changed files with 87 additions and 47 deletions

View File

@ -13,15 +13,11 @@ import (
) )
const ( const (
QueryUserMailReq = "mail.queryusermailreq" QueryUserMailResp = "queryusermailresp"
QueryUserMailResp = "mail.queryusermailresp" ReadUserMailResp = "readusermailresp"
ReadUserMailReq = "mail.readusermailreq" GetUserMailAttachmentResp = "getusermailattachmentresp"
ReadUserMailResp = "mail.readusermailresp" DelUserMailResp = "delusermailresp"
GetUserMailAttachmentReq = "mail.getusermailattachmentreq" GetNewEMailResp = "getnewEmailresp"
GetUserMailAttachmentResp = "mail.getusermailattachmentresp"
DelUserMailReq = "mail.delusermailreq"
DelUserMailResp = "mail.delusermailresp"
GetNewEMailResp = "mail.getnewEmailresp"
) )
type Api_Comp struct { type Api_Comp struct {
@ -56,7 +52,7 @@ func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSe
code := pb.ErrorCode_Success code := pb.ErrorCode_Success
mailinfo := make([]*pb.DB_MailData, 0) mailinfo := make([]*pb.DB_MailData, 0)
defer func() { defer func() {
session.SendMsg("mail", "queryusermailresp", code, &pb.QueryUserMailResp{Mails: mailinfo}) session.SendMsg(string(this.module.GetType()), QueryUserMailResp, code, &pb.QueryUserMailResp{Mails: mailinfo})
}() }()
if session.GetUserId() == "" { if session.GetUserId() == "" {
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
@ -78,14 +74,14 @@ func (this *Api_Comp) ReadUserMailReq(ctx context.Context, session comm.IUserSes
mail *pb.DB_MailData mail *pb.DB_MailData
) )
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), "readusermailresp", code, &pb.ReadUserMailResp{Mail: mail}) session.SendMsg(string(this.module.GetType()), ReadUserMailResp, code, &pb.ReadUserMailResp{Mail: mail})
}() }()
if session.GetUserId() == "" { if session.GetUserId() == "" {
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
mail, err = db.Defsys.ReadOneMail(req.ObjID) mail, err = db.Defsys.Mail_ReadOneMail(req.ObjID)
if err != nil { if err != nil {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }
@ -101,28 +97,35 @@ func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm
mail *pb.DB_MailData mail *pb.DB_MailData
) )
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), "getusermailattachmentresp", code, &pb.GetUserMailAttachmentResp{Mail: mail}) session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, code, &pb.GetUserMailAttachmentResp{Mail: mail})
}() }()
if session.GetUserId() == "" { if session.GetUserId() == "" {
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
_bGet := db.Defsys.GetMailAttachmentState(req.ObjID) _bGet := db.Defsys.Mail_GetMailAttachmentState(req.ObjID)
if !_bGet { if !_bGet {
code = pb.ErrorCode_StateInvalid code = pb.ErrorCode_StateInvalid
return return
} }
_data, err := db.Defsys.GetMailAttachment(req.ObjID) _data, err := db.Defsys.Mail_GetMailAttachment(req.ObjID)
if err != nil { if err != nil {
if len(_data) > 0 { if len(_data) > 0 {
// todo 领取附件 // todo 领取附件
} else { _items := make(map[uint32]uint32, 0)
return for _, v := range _data {
_items[v.ItemId] += v.ItemCount
}
// bRet := this.pack.GetRewaredItems(mail.UserId, _items)
// if bRet {
// // 修改状态
// db.Defsys.Mail_UpdateMailAttachmentState(req.ObjID)
// mail.Reward = true
// return
// }
} }
code = pb.ErrorCode_SystemError
} }
// 修改状态
db.Defsys.UpdateMailAttachmentState(req.ObjID)
mail.Reward = true
return return
} }
@ -133,13 +136,13 @@ func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSess
code := pb.ErrorCode_Success code := pb.ErrorCode_Success
mailinfo := make([]*pb.DB_MailData, 0) mailinfo := make([]*pb.DB_MailData, 0)
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), "delusermailresp", code, &pb.DelUserMailResp{Mail: mailinfo}) session.SendMsg(string(this.module.GetType()), DelUserMailResp, code, &pb.DelUserMailResp{Mail: mailinfo})
}() }()
if session.GetUserId() == "" { if session.GetUserId() == "" {
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
bRet := db.Defsys.DelUserMail(req.ObjID) bRet := db.Defsys.Mail_DelUserMail(req.ObjID)
if !bRet { if !bRet {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -3,8 +3,15 @@ package mail
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db"
"time"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
/* /*
@ -32,3 +39,27 @@ func (this *Mail) OnInstallComp() {
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
} }
func (this *Mail) CreateNewMail(uId string) {
mail := &pb.DB_MailData{
ObjId: primitive.NewObjectID().Hex(),
UserId: uId,
Title: "系统邮件",
Contex: "恭喜获得专属礼包一份",
CreateTime: uint64(time.Now().Unix()),
DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件
Check: false,
Reward: false,
}
err := db.Defsys.Mail_InsertUserMail(mail)
if err != nil {
log.Error("create mail failed")
}
// 通知玩家
_cache := cache.Defsys.Get(uId)
if _cache == nil {
return
}
this.SendMsgToUser(string(this.GetType()), GetNewEMailResp, mail, _cache)
}

View File

@ -37,6 +37,7 @@ const (
ErrorCode_SecKeyInvalid ErrorCode = 20 //秘钥无效 ErrorCode_SecKeyInvalid ErrorCode = 20 //秘钥无效
ErrorCode_StateInvalid ErrorCode = 21 //无效状态 ErrorCode_StateInvalid ErrorCode = 21 //无效状态
ErrorCode_DBError ErrorCode = 22 // 数据库操作失败 ErrorCode_DBError ErrorCode = 22 // 数据库操作失败
ErrorCode_SystemError ErrorCode = 23 // 通用错误
) )
// Enum value maps for ErrorCode. // Enum value maps for ErrorCode.
@ -56,6 +57,7 @@ var (
20: "SecKeyInvalid", 20: "SecKeyInvalid",
21: "StateInvalid", 21: "StateInvalid",
22: "DBError", 22: "DBError",
23: "SystemError",
} }
ErrorCode_value = map[string]int32{ ErrorCode_value = map[string]int32{
"Success": 0, "Success": 0,
@ -72,6 +74,7 @@ var (
"SecKeyInvalid": 20, "SecKeyInvalid": 20,
"StateInvalid": 21, "StateInvalid": 21,
"DBError": 22, "DBError": 22,
"SystemError": 23,
} }
) )
@ -106,7 +109,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{ var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0x97, 0x02, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x6f, 0x2a, 0xa8, 0x02, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
@ -123,8 +126,9 @@ var file_errorcode_proto_rawDesc = []byte{
0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0x13, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x65, 0x63, 0x06, 0x53, 0x65, 0x63, 0x4b, 0x65, 0x79, 0x10, 0x13, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x65, 0x63,
0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x14, 0x12, 0x10, 0x0a, 0x0c, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x14, 0x12, 0x10, 0x0a, 0x0c,
0x53, 0x74, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x15, 0x12, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x10, 0x15, 0x12, 0x0b,
0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x0f, 0x0a, 0x0b, 0x53,
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x17, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

View File

@ -13,8 +13,10 @@ enum ErrorCode {
InsufficientPermissions = 16; // InsufficientPermissions = 16; //
NoLogin = 17; // NoLogin = 17; //
UserSessionNobeing = 18; // UserSessionNobeing = 18; //
SecKey = 19; // SecKey = 19; //
SecKeyInvalid = 20; // SecKeyInvalid = 20; //
StateInvalid = 21; // StateInvalid = 21; //
DBError = 22; // DBError = 22; //
SystemError = 23; //
} }

2
sys/cache/mail.go vendored
View File

@ -25,6 +25,6 @@ func (this *Cache) QueryUserMail(uId string) (mail []*pb.DB_MailData, err error)
// mail[i] = v.(*pb.DB_MailData) // mail[i] = v.(*pb.DB_MailData)
// } // }
// } // }
mail, _ = db.Defsys.QueryUserMail(uId) mail, _ = db.Defsys.Mail_QueryUserMail(uId)
return return
} }

View File

@ -16,16 +16,16 @@ const (
) )
type IMail interface { type IMail interface {
QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err error)
InsertUserMail(mail *pb.DB_MailData) (err error) Mail_InsertUserMail(mail *pb.DB_MailData) (err error)
ReadOneMail(objId string) (mail *pb.DB_MailData, err error) Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err error)
GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error) Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error)
GetMailAttachmentState(objId string) bool Mail_GetMailAttachmentState(objId string) bool
UpdateMailAttachmentState(objId string) bool Mail_UpdateMailAttachmentState(objId string) bool
DelUserMail(objId string) bool Mail_DelUserMail(objId string) bool
} }
func (this *DB) QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) { func (this *DB) Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) {
if _data, err := this.mgo.Find(DB_MailTable, bson.M{"userid": uId}); err == nil { if _data, err := this.mgo.Find(DB_MailTable, bson.M{"userid": uId}); err == nil {
for _data.Next(context.TODO()) { for _data.Next(context.TODO()) {
@ -39,7 +39,7 @@ func (this *DB) QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) {
} }
// 插入一封新的邮件 // 插入一封新的邮件
func (this *DB) InsertUserMail(mail *pb.DB_MailData) (err error) { func (this *DB) Mail_InsertUserMail(mail *pb.DB_MailData) (err error) {
mail.ObjId = primitive.NewObjectID().Hex() mail.ObjId = primitive.NewObjectID().Hex()
mail.Check = false mail.Check = false
@ -53,7 +53,7 @@ func (this *DB) InsertUserMail(mail *pb.DB_MailData) (err error) {
return err return err
} }
func (this *DB) ReadOneMail(objId string) (mail *pb.DB_MailData, err error) { func (this *DB) Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err error) {
err = this.mgo.FindOneAndUpdate( err = this.mgo.FindOneAndUpdate(
DB_MailTable, DB_MailTable,
@ -68,7 +68,7 @@ func (this *DB) ReadOneMail(objId string) (mail *pb.DB_MailData, err error) {
} }
// 查询附件信息 // 查询附件信息
func (this *DB) GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error) { func (this *DB) Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error) {
obj := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}) obj := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId})
var nd *pb.DB_MailData var nd *pb.DB_MailData
@ -79,7 +79,7 @@ func (this *DB) GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err
} }
// 查看领取附件状态 // 查看领取附件状态
func (this *DB) GetMailAttachmentState(objId string) bool { func (this *DB) Mail_GetMailAttachmentState(objId string) bool {
var nd *pb.DB_MailData var nd *pb.DB_MailData
err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(nd) err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(nd)
if err != nil { if err != nil {
@ -89,7 +89,7 @@ func (this *DB) GetMailAttachmentState(objId string) bool {
} }
// 更新领取附件状态 // 更新领取附件状态
func (this *DB) UpdateMailAttachmentState(objId string) bool { func (this *DB) Mail_UpdateMailAttachmentState(objId string) bool {
this.mgo.FindOneAndUpdate( this.mgo.FindOneAndUpdate(
DB_MailTable, DB_MailTable,
bson.M{"_id": objId}, bson.M{"_id": objId},
@ -103,7 +103,7 @@ func (this *DB) UpdateMailAttachmentState(objId string) bool {
} }
// 删除一封邮件 // 删除一封邮件
func (this *DB) DelUserMail(objId string) bool { func (this *DB) Mail_DelUserMail(objId string) bool {
var obj *pb.DB_MailData var obj *pb.DB_MailData
err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(obj) err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(obj)
if err != nil { if err != nil {

View File

@ -10,7 +10,7 @@ import (
) )
func TestCreateEmail(t *testing.T) { func TestCreateEmail(t *testing.T) {
err := db.InsertUserMail(&pb.DB_MailData{ err := db.Mail_InsertUserMail(&pb.DB_MailData{
UserId: "uid123", UserId: "uid123",
Title: "系统邮件", Title: "系统邮件",
@ -20,7 +20,7 @@ func TestCreateEmail(t *testing.T) {
Check: false, Check: false,
Reward: false, Reward: false,
}) })
_data, err := db.QueryUserMail("uid123") _data, err := db.Mail_QueryUserMail("uid123")
for _, v := range _data { for _, v := range _data {
log.Printf("userid = %s", v.UserId) log.Printf("userid = %s", v.UserId)
@ -29,7 +29,7 @@ func TestCreateEmail(t *testing.T) {
} }
func TestReadEmail(t *testing.T) { func TestReadEmail(t *testing.T) {
data, err := db.ReadOneMail("62a078c0726ea54890c34937") data, err := db.Mail_ReadOneMail("62a078c0726ea54890c34937")
if err != nil { if err != nil {
log.Printf("%v", data.Reward) log.Printf("%v", data.Reward)
} }