92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
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"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type CrateMailReq struct {
|
|
Uid string `json:"uid"` // uid
|
|
Title string `json:"title"` // 邮件标题
|
|
Contex string `json:"contex"` // 邮件内容 支持自定义
|
|
Items []*pb.UserAssets `json:"items"` // 附件
|
|
Cid string `json:"cid"` // 多语言表id
|
|
Param []string `json:"param"` // 自定义参数
|
|
Sign string `json:"sign"`
|
|
}
|
|
|
|
//创建邮件
|
|
func (this *Api_Comp) CreateMail(c *engine.Context) {
|
|
|
|
req := &CrateMailReq{}
|
|
err := c.BindJSON(&req)
|
|
this.module.Debugf("CrateMail:%+v err:%v", req, err)
|
|
var (
|
|
errdata *pb.ErrorData
|
|
data interface{}
|
|
)
|
|
if db.IsCross() { // 跨服服务器不能发邮件
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
defer c.JSON(http.StatusOK, &Respond{Code: errdata.Code, Message: errdata.Message, Data: data})
|
|
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{
|
|
"uid": req.Uid,
|
|
"title": req.Title,
|
|
"contex": req.Contex,
|
|
"cid": req.Cid,
|
|
}); sign != req.Sign {
|
|
this.module.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SignError,
|
|
Title: pb.ErrorCode_SignError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
mail := &pb.DBMailData{
|
|
ObjId: primitive.NewObjectID().Hex(),
|
|
Uid: req.Uid,
|
|
Title: req.Title,
|
|
Contex: req.Contex,
|
|
CreateTime: uint64(time.Now().Unix()),
|
|
DueTime: uint64(time.Now().Unix() + 30*24*3600),
|
|
Check: false,
|
|
Reward: false,
|
|
Items: req.Items,
|
|
Cid: req.Cid,
|
|
Param: req.Param,
|
|
}
|
|
if len(req.Items) > 0 {
|
|
mail.Reward = true
|
|
}
|
|
|
|
if _, err = this.module.service.RpcGo(
|
|
context.Background(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_Mail),
|
|
mail, nil); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_RpcFuncExecutionError,
|
|
Title: pb.ErrorCode_RpcFuncExecutionError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_Success,
|
|
Title: pb.ErrorCode_Success.ToString(),
|
|
}
|
|
}
|