136 lines
4.1 KiB
Go
136 lines
4.1 KiB
Go
package system
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"github.com/gin-gonic/gin"
|
|
"main/common"
|
|
"main/constant"
|
|
"main/model/system"
|
|
"net/http"
|
|
)
|
|
|
|
type MailApi struct {
|
|
}
|
|
|
|
func (this *MailApi) ListMail(c *gin.Context) {
|
|
mails := []system.Mail{}
|
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Find(&mails)
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "",
|
|
"data": mails,
|
|
})
|
|
}
|
|
|
|
func (this *MailApi) AddMail(c *gin.Context) {
|
|
reqJson := struct {
|
|
MailType int32 `binding:"required" json:"mailtype"`
|
|
SendTime int32 `json:"sendtime"`
|
|
ExpireTime int32 `json:"expiretime"`
|
|
UserRegStartTime int32 `json:"user_reg_start_time"`
|
|
UserRegEndTime int32 `json:"user_reg_end_time"`
|
|
Subject string `json:"subject"`
|
|
Content string `json:"content"`
|
|
Attachments []common.Attachment `json:"attachments"`
|
|
Recipients []string `json:"recipients"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
if reqJson.MailType <= constant.MAIL_TYPE_BEGIN || reqJson.MailType >= constant.MAIL_TYPE_END {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 2,
|
|
"message": "mail_type参数错误",
|
|
})
|
|
return
|
|
}
|
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
|
mail := new(system.Mail)
|
|
mail.MailId = f5.GetApp().NewLockNodeUuid()
|
|
mail.MailType = reqJson.MailType
|
|
mail.SendTime = reqJson.SendTime
|
|
mail.ExpireTime = reqJson.ExpireTime
|
|
mail.UserRegStartTime = reqJson.UserRegStartTime
|
|
mail.UserRegEndTime = reqJson.UserRegEndTime
|
|
mail.Subject = reqJson.Subject
|
|
mail.Content = reqJson.Content
|
|
mail.Attachments = reqJson.Attachments
|
|
mail.Recipients = reqJson.Recipients
|
|
mail.CreateTime = nowDaySeconds
|
|
mail.ModifyTime = nowDaySeconds
|
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail)
|
|
{
|
|
e := new(system.MailEvent)
|
|
e.EventName = constant.EVENT_MAIL_UPDATE
|
|
e.Param1 = q5.ToString(mail.MailId)
|
|
e.CreateTime = nowDaySeconds
|
|
e.ModifyTime = nowDaySeconds
|
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "",
|
|
})
|
|
}
|
|
|
|
func (this *MailApi) EditMail(c *gin.Context) {
|
|
reqJson := struct {
|
|
MailId int64 `binding:"required" json:"mail_id,string"`
|
|
MailType int32 `binding:"required" json:"mail_type"`
|
|
SendTime int32 `json:"sendtime"`
|
|
ExpireTime int32 `json:"expiretime"`
|
|
UserRegStartTime int32 `json:"user_reg_start_time"`
|
|
UserRegEndTime int32 `json:"user_reg_end_time"`
|
|
Subject string `json:"subject"`
|
|
Content string `json:"content"`
|
|
Attachments []common.Attachment `json:"attachments"`
|
|
Recipients []string `json:"recipients"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
if reqJson.MailType <= constant.MAIL_TYPE_BEGIN || reqJson.MailType >= constant.MAIL_TYPE_END {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 2,
|
|
"message": "mail_type参数错误",
|
|
})
|
|
return
|
|
}
|
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
|
mail := new(system.Mail)
|
|
mail.MailId = reqJson.MailId
|
|
mail.MailType = reqJson.MailType
|
|
mail.SendTime = reqJson.SendTime
|
|
mail.ExpireTime = reqJson.ExpireTime
|
|
mail.UserRegStartTime = reqJson.UserRegStartTime
|
|
mail.UserRegEndTime = reqJson.UserRegEndTime
|
|
mail.Subject = reqJson.Subject
|
|
mail.Content = reqJson.Content
|
|
mail.Attachments = reqJson.Attachments
|
|
mail.Recipients = reqJson.Recipients
|
|
mail.CreateTime = nowDaySeconds
|
|
mail.ModifyTime = nowDaySeconds
|
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
|
{
|
|
e := new(system.MailEvent)
|
|
e.EventName = constant.EVENT_MAIL_UPDATE
|
|
e.Param1 = q5.ToString(mail.MailId)
|
|
e.CreateTime = nowDaySeconds
|
|
e.ModifyTime = nowDaySeconds
|
|
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 0,
|
|
"message": "",
|
|
})
|
|
}
|