From e86c8bacedd6a4df0fd9d31fe2f1daa336830536 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 8 Dec 2022 18:19:29 +0800 Subject: [PATCH] =?UTF-8?q?web=20=E5=8F=91=E9=82=AE=E4=BB=B6=20worker=20?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=8E=A9=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 2 ++ modules/gm/api_cmd.go | 4 ++-- modules/mail/module.go | 32 ++++++++++++++++++++++++++++++++ modules/web/api_creatmail.go | 21 +++++++++++++++++++-- modules/web/api_paydelivery.go | 2 +- 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/comm/const.go b/comm/const.go index df91ddb2f..b0107f494 100644 --- a/comm/const.go +++ b/comm/const.go @@ -242,6 +242,8 @@ const ( //Rpc Rpc_ModuleSeasonPagodaReward core.Rpc_Key = "Rpc_ModuleSeasonPagodaReward" // 公会信息 Rpc_ModuleSociaty core.Rpc_Key = "Rpc_ModuleSociaty" + // RPC 通知来了邮件 + Rpc_Mail core.Rpc_Key = "Rpc_Mail" ) //事件类型定义处 diff --git a/modules/gm/api_cmd.go b/modules/gm/api_cmd.go index 9cc9f94dd..e6b0c875c 100644 --- a/modules/gm/api_cmd.go +++ b/modules/gm/api_cmd.go @@ -29,7 +29,7 @@ import ( 14、bingo:arena,100 // 设置竞技场用户积分 15、bingo:sociatyexp,100 // 设置工会经验 15、bingo:sociatyactivity,100 // 设置工会活跃 -15、bingo:alltask // bingo所有任务 +16、bingo:alltask // bingo所有任务 */ //参数校验 func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) { @@ -47,6 +47,6 @@ func (this *apiComp) Cmd(session comm.IUserSession, req *pb.GMCmdReq) (code pb.E this.module.CreateCmd(session, req.Cmod) //this.module.ModuleHero.GetSpecifiedHero(session.GetUserId(), heroid, star, lv) - session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: false}) + session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true}) return } diff --git a/modules/mail/module.go b/modules/mail/module.go index 266c15430..4414b5276 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -1,6 +1,7 @@ package mail import ( + "context" "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -9,6 +10,7 @@ import ( "go_dreamfactory/utils" "time" + "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" @@ -30,6 +32,7 @@ type Mail struct { api *apiComp modelMail *modelMail configure_comp *Configure_Comp + service base.IRPCXService } func (this *Mail) GetType() core.M_Modules { @@ -78,6 +81,16 @@ func (this *Mail) CreateNewMail(session comm.IUserSession, mail *pb.DBMailData) return true } +func (this *Mail) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + this.service = service.(base.IRPCXService) + return +} +func (this *Mail) Start() (err error) { + err = this.ModuleBase.Start() + this.service.RegisterFunctionName(string(comm.Rpc_Mail), this.Rpc_Mail) + return +} // 获得新邮件 推送给玩家 func (this *Mail) AddNewMailPush(session comm.IUserSession, mail *pb.DBMailData) { @@ -141,3 +154,22 @@ func (this *Mail) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red } return } + +func (this *Mail) Rpc_Mail(ctx context.Context, args *pb.DBMailData) (err error) { + this.Debug("Rpc_Mail", log.Fields{"args": args.String()}) + var ( + session comm.IUserSession + online bool + ) + tag, _, b := utils.UIdSplit(args.Uid) + if b { + if conn, err := db.ServerDBConn(tag); err == nil { + dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + _, err = dbModel.DB.InsertOne(comm.TableMail, args) + } + } + if session, online = this.GetUserSession(args.Uid); online { + session.SendMsg(string(this.GetType()), "getnewmail", &pb.MailGetNewMailPush{Mail: args}) + } + return +} diff --git a/modules/web/api_creatmail.go b/modules/web/api_creatmail.go index aa7e94cd5..c3e9653da 100644 --- a/modules/web/api_creatmail.go +++ b/modules/web/api_creatmail.go @@ -1,9 +1,12 @@ package web import ( + "context" + "go_dreamfactory/comm" "go_dreamfactory/lego/sys/gin" "go_dreamfactory/lego/sys/gin/engine" "go_dreamfactory/pb" + "go_dreamfactory/sys/db" "net/http" "time" @@ -22,6 +25,7 @@ type CrateMailReq struct { //创建邮件 func (this *Api_Comp) CreateMail(c *engine.Context) { + req := &CrateMailReq{} err := c.BindJSON(&req) this.module.Debugf("CrateMail:%+v err:%v", req, err) @@ -30,14 +34,17 @@ func (this *Api_Comp) CreateMail(c *engine.Context) { msg string data interface{} ) + if db.IsCross() { // 跨服服务器不能发邮件 + code = pb.ErrorCode_ReqParameterError + msg = pb.GetErrorCodeMsg(code) + return + } defer c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data}) if sign := gin.ParamSign(this.options.Key, map[string]interface{}{ "Uid": req.Uid, "Title": req.Title, "Contex": req.Contex, - "Items": req.Items, "Cid": req.Cid, - "Param": req.Param, }); sign != req.Sign { this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign) code = pb.ErrorCode_SignError @@ -65,6 +72,7 @@ func (this *Api_Comp) CreateMail(c *engine.Context) { if len(req.Items) > 0 { mail.Reward = true } + if err = this.module.modelMail.CreateGMMail(mail); err != nil { this.module.Errorf("LoginByCaptchaReq CreateMail err:%v", err) code = pb.ErrorCode_DBError @@ -72,4 +80,13 @@ func (this *Api_Comp) CreateMail(c *engine.Context) { return } msg = pb.GetErrorCodeMsg(code) + + if _, err = this.module.service.RpcGo( + context.Background(), + comm.Service_Worker, + string(comm.Rpc_Mail), + mail, nil); err != nil { + this.module.Errorln(err) + code = pb.ErrorCode_RpcFuncExecutionError + } } diff --git a/modules/web/api_paydelivery.go b/modules/web/api_paydelivery.go index ceb3f7a71..07fd1af51 100644 --- a/modules/web/api_paydelivery.go +++ b/modules/web/api_paydelivery.go @@ -27,7 +27,7 @@ func (this *Api_Comp) PayDelivery(c *engine.Context) { payresp *pb.PayDeliveryResp = &pb.PayDeliveryResp{} ) defer c.JSON(http.StatusOK, &Respond{Code: payresp.Code, Message: payresp.Msg, Data: nil}) - if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"orderid": req.Order, "productid": req.ProductID, "uid": req.Uid}); sign != req.Sign { + if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"orderid": req.Order, "productid": req.ProductID, "uid": req.Uid}); sign != req.Sign { this.module.Errorf("PayDelivery SignError sgin:%s", sign) payresp.Code = pb.ErrorCode_SignError return