This commit is contained in:
hujiabin 2023-10-25 15:56:43 +08:00
parent 38131b7858
commit 779c267eb9
6 changed files with 201 additions and 30 deletions

View File

@ -16,7 +16,7 @@ func (this *AnncApi) AnncList(c *gin.Context) {
var anncList []system.Annc
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Find(&anncList).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -30,17 +30,9 @@ func (this *AnncApi) AnncList(c *gin.Context) {
}
func (this *AnncApi) AddAnnc(c *gin.Context) {
//type form struct {
// Title string `binding:"required" json:"title"`
// Version string `binding:"required" json:"version"`
// Model uint `binding:"required" json:"model"`
// Type uint `json:"type"`
// Content string `binding:"required" json:"content"`
//}
//formReq := form{}
annc := system.Annc{}
if err := c.ShouldBindJSON(&annc); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -49,7 +41,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_announcement").Where("model = ?", annc.Model).Where("type = ?", annc.Type).Count(&count)
if count > 0 {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "无法再插入同类型的公告",
})
@ -58,7 +50,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Create(&annc).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -75,7 +67,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_announcement").Where("idx = ?", idx).Count(&count)
if count < 1 {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "不存在的数据",
})
@ -83,7 +75,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
}
annc := system.Annc{}
if err := c.ShouldBindJSON(&annc); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -91,7 +83,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&annc).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})

View File

@ -16,7 +16,7 @@ func (this *AuditApi) AuditList(c *gin.Context) {
var auditList []system.Audit
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Find(&auditList).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -32,7 +32,7 @@ func (this *AuditApi) AuditList(c *gin.Context) {
func (this *AuditApi) AddAudit(c *gin.Context) {
audit := system.Audit{}
if err := c.ShouldBindJSON(&audit); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -41,7 +41,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_audit").Where("model = ?", audit.Model).Count(&count)
if count > 0 {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "无法再插入",
})
@ -50,7 +50,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Create(&audit).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -67,7 +67,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_audit").Where("idx = ?", idx).Count(&count)
if count < 1 {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "不存在的数据",
})
@ -75,7 +75,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
}
audit := system.Audit{}
if err := c.ShouldBindJSON(&audit); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
@ -83,7 +83,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})

View File

@ -2,8 +2,8 @@ package system
import (
"adminsever/constant"
"encoding/json"
"f5"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"q5"
@ -11,6 +11,11 @@ import (
type EmailApi struct {
}
var (
url = "https://" + constant.EMAIL_URL_DEV + "/webapp/index.php"
)
type emailReq struct {
Mailtype int `binding:"required" json:"mailtype"`
Usertype int `json:"usertype"`
@ -28,13 +33,15 @@ type emailReq struct {
func (this *EmailApi) SendEmail(c *gin.Context) {
emailMgr := emailReq{}
if err := c.ShouldBindJSON(&emailMgr); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
params := map[string]string{
"c": "MailMgr",
"a": "sendMail",
"gameid": constant.GAMEID,
"to": emailMgr.To,
"from": emailMgr.From,
@ -50,18 +57,187 @@ func (this *EmailApi) SendEmail(c *gin.Context) {
"key": constant.EMAIL_KEY,
}
url := "https://" + constant.EMAIL_URL_DEV + "/webapp/index.php"
f5.GetHttpCliMgr().SyncSendGoStyleRequest(url, params, func(response f5.HttpCliResponse) {
err := response.GetErr()
data := response.GetRawData()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
fmt.Println(data)
var resData struct {
errcode int
errmsg string
}
_ = json.Unmarshal([]byte(data), &resData)
if resData.errcode != 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": resData.errmsg,
})
return
}
})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
})
}
func (this *EmailApi) EmailList(c *gin.Context) {
params := map[string]string{
"c": "MailMgr",
"a": "getMailList",
"key": constant.EMAIL_KEY,
"gameid": constant.GAMEID,
}
f5.GetHttpCliMgr().SyncSendGoStyleRequest(url, params, func(response f5.HttpCliResponse) {
err := response.GetErr()
data := response.GetRawData()
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
rspObj := struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Maillist []struct {
Subject string `json:"subject"`
Gameid int `json:"gameid"`
Mailid string `json:"mailid"`
To string `json:"to"`
From string `json:"from"`
Sendtime int `json:"sendtime"`
Expiretime int `json:"expiretime"`
Mailtype int `json:"mailtype"`
Mailsubtype int `json:"mailsubtype"`
Content string `json:"content"`
Ext string `json:"ext"`
Attachments []struct {
Itemid int `json:"itemid"`
Itemnum int `json:"itemnum"`
} `json:"attachments"`
} `json:"maillist"`
}{}
_ = json.Unmarshal([]byte(data), &rspObj)
if rspObj.Errcode != 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": rspObj.Errmsg,
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
"data": rspObj.Maillist,
})
return
})
}
func (this *EmailApi) UpdateEmail(c *gin.Context) {
mailMgr := struct {
Mailid string `binding:"required" json:"mailid"`
Subject string `binding:"required" json:"subject"`
Content string `binding:"required" json:"content"`
Sendtime int `binding:"required" json:"sendtime"`
Expiretime int `binding:"required" json:"expiretime"`
Ext string `json:"ext"`
Attachments string `json:"attachments"`
}{}
if err := c.ShouldBindJSON(&mailMgr); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
params := map[string]string{
"c": "MailMgr",
"a": "updateMail",
"gameid": constant.GAMEID,
"mailid": mailMgr.Mailid,
"content": mailMgr.Content,
"subject": mailMgr.Subject,
"sendtime": q5.ToString(mailMgr.Sendtime),
"expiretime": q5.ToString(mailMgr.Expiretime),
"attachments": mailMgr.Attachments,
"ext": "",
"key": constant.EMAIL_KEY,
}
f5.GetHttpCliMgr().SyncSendGoStyleRequest(url, params, func(response f5.HttpCliResponse) {
err := response.GetErr()
data := response.GetRawData()
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
var resData struct {
errcode int
errmsg string
}
_ = json.Unmarshal([]byte(data), &resData)
if resData.errcode != 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": resData.errmsg,
})
return
}
})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
})
}
func (this *EmailApi) DelEmail(c *gin.Context) {
mailid := c.Param("mailid")
params := map[string]string{
"c": "MailMgr",
"a": "deleteMail",
"gameid": constant.GAMEID,
"mailid": mailid,
"key": constant.EMAIL_KEY,
}
f5.GetHttpCliMgr().SyncSendGoStyleRequest(url, params, func(response f5.HttpCliResponse) {
err := response.GetErr()
data := response.GetRawData()
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
var resData struct {
errcode int
errmsg string
}
_ = json.Unmarshal([]byte(data), &resData)
if resData.errcode != 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": resData.errmsg,
})
return
}
})
c.JSON(http.StatusOK, gin.H{
"code": 0,

View File

@ -29,7 +29,7 @@ func (this *UserApi) Login(c *gin.Context) {
}
reqJson := loginForm{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})

View File

@ -13,8 +13,8 @@ func Auth() gin.HandlerFunc {
strArr := strings.Split(token, "|")
authToken := GetApp().GetSessionAccountId(strArr[0])
if token == "" || token != authToken {
c.JSON(http.StatusUnauthorized, gin.H{
"code": 1,
c.JSON(http.StatusOK, gin.H{
"code": 50014,
"message": "未登录或非法访问",
})
/*

View File

@ -12,5 +12,8 @@ func (this *AnncRouter) InitEmailRouter(priRouter *gin.RouterGroup) {
emailApi := v1.ApiGroupApp.SystemApiGroup.EmailApi
{
priUserRouter.POST("send", emailApi.SendEmail)
priUserRouter.GET("list", emailApi.EmailList)
priUserRouter.PUT("update", emailApi.UpdateEmail)
priUserRouter.DELETE("delete/:mailid", emailApi.DelEmail)
}
}