package action import ( "github.com/golang/protobuf/proto" "go.mongodb.org/mongo-driver/bson" "pro2d/common" "pro2d/common/components" "pro2d/common/db/mongoproxy" "pro2d/common/logger" "pro2d/models" "pro2d/pb" ) /* EmailListRpc 邮件列表 */ func EmailListRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { // del err := role.DelExpireEmail() if err != nil { logger.Error(err.Error()) } // load emails := role.LoadEmails() return 0, &pb.EmailListRsp{Emails: emails} } func GetEmailPBAttachMents(email *pb.Email) string { if email.Status == 2 { return "" } return email.Attachments } /* EmailDrawRpc 打开所有邮件奖励 2 邮件不存在 */ func EmailDrawRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.EmailDrawReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { logger.Error("loginRpc err: %v", err) return 1, nil } var emails []*pb.Email if req.Id == "" { // 打开所有邮件 emails = role.LoadEmails() } else { // 打开一个邮件 email := models.NewEmailModel(req.Id) if err := email.Load(); err != nil { return 2, nil } emails = []*pb.Email{email.Data} } var ids []string reward := make(common.IMapStringNum) for _, e := range emails { attachments := GetEmailPBAttachMents(e) if attachments == "" { continue } email := models.NewEmailModelPB(e) email.SetProperty("status", int32(2)) email.Log(role, 2) email.Update() ids = append(ids, e.Id) for k, v := range common.StringToMapNum(email.Data.Attachments) { tmp, ok := reward[k] if !ok { reward[k] = v } else { reward[k] = tmp + v } } } role.Award(reward, &pb.LogConf{Desc: "draw_attach"}) return 0, &pb.EmailDrawRsp{Ids: ids, Reward: common.MapNumToString(reward)} } func EmailCheckRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.EmailCheckRar{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { logger.Error("loginRpc err: %v", err) return 1, nil } email := models.NewEmailModel(req.Id) if err := email.Load(); err != nil { return 2, nil } if email.Data.Status != 0 { return 3, nil } email.SetProperty("status", int32(1)) email.Log(role, 1) email.Update() return 0, nil } func EmailDelRpc(role *models.RoleModel, msg components.IMessage) (int32, interface{}) { req := pb.EmailDelReq{} if err := proto.Unmarshal(msg.GetData(), &req); err != nil { logger.Error("loginRpc err: %v", err) return 1, nil } var result []string emails := role.LoadEmails() for _, email := range emails { attachments := GetEmailPBAttachMents(email) if email.Status == 2 || (attachments == "" && email.Status == 1) { result = append(result, email.Id) models.NewEmailModelPB(email).Log(role, 3) role.MyLog("mail_action", &pb.LogConf{ Desc: "del_mail", Int1: email.Id, }) } } filter := bson.D{{"roleid", role.Data.Id}, {"id", bson.D{{"$in", result}}}} if err := mongoproxy.DelMany("email", filter); err != nil { return 2, nil } return 0, &pb.EmailDelRsp{Ids: result} }