Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into liwei
This commit is contained in:
commit
f9185698e0
@ -13,15 +13,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
QueryUserMailReq = "mail.queryusermailreq"
|
||||
QueryUserMailResp = "mail.queryusermailresp"
|
||||
ReadUserMailReq = "mail.readusermailreq"
|
||||
ReadUserMailResp = "mail.readusermailresp"
|
||||
GetUserMailAttachmentReq = "mail.getusermailattachmentreq"
|
||||
GetUserMailAttachmentResp = "mail.getusermailattachmentresp"
|
||||
DelUserMailReq = "mail.delusermailreq"
|
||||
DelUserMailResp = "mail.delusermailresp"
|
||||
GetNewEMailResp = "mail.getnewEmailresp"
|
||||
QueryUserMailResp = "queryusermailresp"
|
||||
ReadUserMailResp = "readusermailresp"
|
||||
GetUserMailAttachmentResp = "getusermailattachmentresp"
|
||||
DelUserMailResp = "delusermailresp"
|
||||
GetNewEMailResp = "getnewEmailresp"
|
||||
)
|
||||
|
||||
type Api_Comp struct {
|
||||
@ -56,7 +52,7 @@ func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSe
|
||||
code := pb.ErrorCode_Success
|
||||
mailinfo := make([]*pb.DB_MailData, 0)
|
||||
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() == "" {
|
||||
code = pb.ErrorCode_NoLogin
|
||||
@ -78,14 +74,14 @@ func (this *Api_Comp) ReadUserMailReq(ctx context.Context, session comm.IUserSes
|
||||
mail *pb.DB_MailData
|
||||
)
|
||||
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() == "" {
|
||||
code = pb.ErrorCode_NoLogin
|
||||
return
|
||||
}
|
||||
|
||||
mail, err = db.Defsys.ReadOneMail(req.ObjID)
|
||||
mail, err = db.Defsys.Mail_ReadOneMail(req.ObjID)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
@ -101,28 +97,35 @@ func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm
|
||||
mail *pb.DB_MailData
|
||||
)
|
||||
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() == "" {
|
||||
code = pb.ErrorCode_NoLogin
|
||||
return
|
||||
}
|
||||
_bGet := db.Defsys.GetMailAttachmentState(req.ObjID)
|
||||
_bGet := db.Defsys.Mail_GetMailAttachmentState(req.ObjID)
|
||||
if !_bGet {
|
||||
code = pb.ErrorCode_StateInvalid
|
||||
return
|
||||
}
|
||||
_data, err := db.Defsys.GetMailAttachment(req.ObjID)
|
||||
_data, err := db.Defsys.Mail_GetMailAttachment(req.ObjID)
|
||||
if err != nil {
|
||||
if len(_data) > 0 {
|
||||
// todo 领取附件
|
||||
} else {
|
||||
return
|
||||
_items := make(map[uint32]uint32, 0)
|
||||
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
|
||||
}
|
||||
@ -133,13 +136,13 @@ func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSess
|
||||
code := pb.ErrorCode_Success
|
||||
mailinfo := make([]*pb.DB_MailData, 0)
|
||||
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() == "" {
|
||||
code = pb.ErrorCode_NoLogin
|
||||
return
|
||||
}
|
||||
bRet := db.Defsys.DelUserMail(req.ObjID)
|
||||
bRet := db.Defsys.Mail_DelUserMail(req.ObjID)
|
||||
if !bRet {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -3,8 +3,15 @@ package mail
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
"time"
|
||||
|
||||
"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.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)
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ const (
|
||||
ErrorCode_SecKeyInvalid ErrorCode = 20 //秘钥无效
|
||||
ErrorCode_StateInvalid ErrorCode = 21 //无效状态
|
||||
ErrorCode_DBError ErrorCode = 22 // 数据库操作失败
|
||||
ErrorCode_SystemError ErrorCode = 23 // 通用错误
|
||||
)
|
||||
|
||||
// Enum value maps for ErrorCode.
|
||||
@ -56,6 +57,7 @@ var (
|
||||
20: "SecKeyInvalid",
|
||||
21: "StateInvalid",
|
||||
22: "DBError",
|
||||
23: "SystemError",
|
||||
}
|
||||
ErrorCode_value = map[string]int32{
|
||||
"Success": 0,
|
||||
@ -72,6 +74,7 @@ var (
|
||||
"SecKeyInvalid": 20,
|
||||
"StateInvalid": 21,
|
||||
"DBError": 22,
|
||||
"SystemError": 23,
|
||||
}
|
||||
)
|
||||
|
||||
@ -106,7 +109,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_errorcode_proto_rawDesc = []byte{
|
||||
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,
|
||||
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,
|
||||
@ -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,
|
||||
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,
|
||||
0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x42, 0x06, 0x5a, 0x04, 0x2e,
|
||||
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x0a, 0x07, 0x44, 0x42, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x16, 0x12, 0x0f, 0x0a, 0x0b, 0x53,
|
||||
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 (
|
||||
|
@ -13,8 +13,10 @@ enum ErrorCode {
|
||||
InsufficientPermissions = 16; //权限不足
|
||||
NoLogin = 17; //未登录
|
||||
UserSessionNobeing = 18; //用户不存在
|
||||
SecKey = 19; //秘钥格式错误
|
||||
SecKeyInvalid = 20; //秘钥无效
|
||||
StateInvalid = 21; //无效状态
|
||||
DBError = 22; // 数据库操作失败
|
||||
SecKey = 19; //秘钥格式错误
|
||||
SecKeyInvalid = 20; //秘钥无效
|
||||
StateInvalid = 21; //无效状态
|
||||
DBError = 22; // 数据库操作失败
|
||||
SystemError = 23; // 通用错误
|
||||
|
||||
}
|
2
sys/cache/mail.go
vendored
2
sys/cache/mail.go
vendored
@ -25,6 +25,6 @@ func (this *Cache) QueryUserMail(uId string) (mail []*pb.DB_MailData, err error)
|
||||
// mail[i] = v.(*pb.DB_MailData)
|
||||
// }
|
||||
// }
|
||||
mail, _ = db.Defsys.QueryUserMail(uId)
|
||||
mail, _ = db.Defsys.Mail_QueryUserMail(uId)
|
||||
return
|
||||
}
|
||||
|
@ -16,16 +16,16 @@ const (
|
||||
)
|
||||
|
||||
type IMail interface {
|
||||
QueryUserMail(uId string) (mail []*pb.DB_MailData, err error)
|
||||
InsertUserMail(mail *pb.DB_MailData) (err error)
|
||||
ReadOneMail(objId string) (mail *pb.DB_MailData, err error)
|
||||
GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error)
|
||||
GetMailAttachmentState(objId string) bool
|
||||
UpdateMailAttachmentState(objId string) bool
|
||||
DelUserMail(objId string) bool
|
||||
Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err error)
|
||||
Mail_InsertUserMail(mail *pb.DB_MailData) (err error)
|
||||
Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err error)
|
||||
Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error)
|
||||
Mail_GetMailAttachmentState(objId string) bool
|
||||
Mail_UpdateMailAttachmentState(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 {
|
||||
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.Check = false
|
||||
@ -53,7 +53,7 @@ func (this *DB) InsertUserMail(mail *pb.DB_MailData) (err error) {
|
||||
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(
|
||||
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})
|
||||
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
|
||||
err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(nd)
|
||||
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(
|
||||
DB_MailTable,
|
||||
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
|
||||
err := this.mgo.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(obj)
|
||||
if err != nil {
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateEmail(t *testing.T) {
|
||||
err := db.InsertUserMail(&pb.DB_MailData{
|
||||
err := db.Mail_InsertUserMail(&pb.DB_MailData{
|
||||
|
||||
UserId: "uid123",
|
||||
Title: "系统邮件",
|
||||
@ -20,7 +20,7 @@ func TestCreateEmail(t *testing.T) {
|
||||
Check: false,
|
||||
Reward: false,
|
||||
})
|
||||
_data, err := db.QueryUserMail("uid123")
|
||||
_data, err := db.Mail_QueryUserMail("uid123")
|
||||
|
||||
for _, v := range _data {
|
||||
log.Printf("userid = %s", v.UserId)
|
||||
@ -29,7 +29,7 @@ func TestCreateEmail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadEmail(t *testing.T) {
|
||||
data, err := db.ReadOneMail("62a078c0726ea54890c34937")
|
||||
data, err := db.Mail_ReadOneMail("62a078c0726ea54890c34937")
|
||||
if err != nil {
|
||||
log.Printf("%v", data.Reward)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user