whitelist
This commit is contained in:
parent
a6fefc579d
commit
1fb6b66da9
@ -30,7 +30,7 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) {
|
||||
constant.CONF_DB,
|
||||
q5.ToInt32(req.PageDto.PageSize),
|
||||
q5.ToInt32(req.PageDto.Page),
|
||||
"SELECT * FROM t_blockplayer WHERE 1=1",
|
||||
"SELECT * FROM t_blockplayer WHERE 1=1 AND deleted = 0",
|
||||
[]string{},
|
||||
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
|
||||
" ORDER BY account_id ",
|
||||
@ -74,17 +74,32 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
info := new(system.BlockPlayer)
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
|
||||
var count int64 = 0
|
||||
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blockplayer").Where("account_id =?", req.Account).Count(&count).Error; err == nil && count > 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "数据存在",
|
||||
})
|
||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blockplayer").Where("account_id =?", req.Account)
|
||||
if err := db.Count(&count).Error; err == nil && count > 0 {
|
||||
db.Take(info)
|
||||
if info.Deleted == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "数据存在",
|
||||
})
|
||||
} else {
|
||||
info.Blocked = 1
|
||||
info.Deleted = 0
|
||||
info.ModifyTime = nowDaySeconds
|
||||
db.Save(info)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "添加成功",
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
info := new(system.BlockPlayer)
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
info.Account = req.Account
|
||||
info.Blocked = 1
|
||||
info.CreateTime = nowDaySeconds
|
||||
@ -180,9 +195,9 @@ func (bpa *BlockPlayerApi) Del(c *gin.Context) {
|
||||
} else {
|
||||
}
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
blockplayer.Blocked = -1
|
||||
blockplayer.Deleted = 1
|
||||
blockplayer.ModifyTime = nowDaySeconds
|
||||
if err := db.Where("account_id = ?", req.Account).Delete(blockplayer).Error; err != nil {
|
||||
if err := db.Where("account_id = ?", req.Account).Save(blockplayer).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"message": "sever internal error:" + err.Error(),
|
||||
|
@ -12,4 +12,5 @@ type ApiGroup struct {
|
||||
NFTApi
|
||||
GameSwitchApi
|
||||
BlockPlayerApi
|
||||
WhiteListApi
|
||||
}
|
||||
|
285
server/adminserver/api/v1/system/whitelist.go
Normal file
285
server/adminserver/api/v1/system/whitelist.go
Normal file
@ -0,0 +1,285 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"net/http"
|
||||
"q5"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
type WhiteListApi struct {
|
||||
}
|
||||
|
||||
func (bpa *WhiteListApi) List(c *gin.Context) {
|
||||
req := struct {
|
||||
Type string `json:"type"`
|
||||
PageDto system.PageDto `json:"page_dto"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
sql := "SELECT * FROM t_whitelist WHERE 1=1 AND deleted = 0"
|
||||
params := []string{}
|
||||
if req.Type != "" {
|
||||
sql += " AND type = ?"
|
||||
params = append(params, req.Type)
|
||||
}
|
||||
result := []*system.WhiteListItem{}
|
||||
f5.GetGoStyleDb().PageQuery(
|
||||
constant.CONF_DB,
|
||||
q5.ToInt32(req.PageDto.PageSize),
|
||||
q5.ToInt32(req.PageDto.Page),
|
||||
sql,
|
||||
params,
|
||||
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
|
||||
" ORDER BY account_id ",
|
||||
func(err error, pg *f5.Pagination) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
for pg.Rows.Next() {
|
||||
p := new(system.WhiteListItem)
|
||||
p.Type = pg.Rows.GetByName("type")
|
||||
p.Account = pg.Rows.GetByName("account_id")
|
||||
p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime"))
|
||||
p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime"))
|
||||
q5.AppendSlice(&result, p)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "获取成功",
|
||||
"data": result,
|
||||
"total": pg.Total,
|
||||
"total_page": pg.TotalPages,
|
||||
"cur_page": pg.CurrentPage,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (bpa *WhiteListApi) Add(c *gin.Context) {
|
||||
req := struct {
|
||||
Account string `binding:"required" json:"account_id"`
|
||||
Type string `binding:"required" json:"type"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
info := new(system.WhiteListItem)
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
|
||||
var count int64 = 0
|
||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("account_id = ? AND type = ?", req.Account, req.Type)
|
||||
if err := db.Count(&count).Error; err == nil && count > 0 {
|
||||
db.Take(info)
|
||||
if info.Deleted == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "数据存在",
|
||||
})
|
||||
} else {
|
||||
info.Deleted = 0
|
||||
info.ModifyTime = nowDaySeconds
|
||||
db.Save(info)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "添加成功",
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
info.Account = req.Account
|
||||
info.Type = req.Type
|
||||
info.CreateTime = nowDaySeconds
|
||||
info.ModifyTime = nowDaySeconds
|
||||
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (bpa *WhiteListApi) Edit(c *gin.Context) {
|
||||
// req := struct {
|
||||
// Account string `binding:"required" json:"account_id"`
|
||||
// Type string `json:"type"`
|
||||
// }{}
|
||||
// if err := c.ShouldBindJSON(&req); err != nil {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 1,
|
||||
// "message": err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
// whitelistitem := new(system.WhiteListItem)
|
||||
// db := f5.GetApp().GetOrmDb(constant.CONF_DB)
|
||||
// if err := db.Take(whitelistitem, "account_id =?", req.Account).Error; err != nil {
|
||||
// if !f5.IsOrmErrRecordNotFound(err) {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 500,
|
||||
// "message": "sever internal error:" + err.Error(),
|
||||
// })
|
||||
// return
|
||||
// } else {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 2,
|
||||
// "message": "无法查到记录",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
// nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
// whiteListItem.Blocked = req.Blocked
|
||||
// whiteListItem.ModifyTime = nowDaySeconds
|
||||
// if err := db.Where("account_id = ?", req.Account).Save(whiteListItem).Error; err != nil {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 500,
|
||||
// "message": "sever internal error:" + err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 0,
|
||||
// "message": "",
|
||||
// })
|
||||
}
|
||||
|
||||
func (bpa *WhiteListApi) Del(c *gin.Context) {
|
||||
req := struct {
|
||||
Account string `binding:"required" json:"account_id"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
whiteListItem := new(system.WhiteListItem)
|
||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("account_id = ?", req.Account)
|
||||
if req.Type != "" {
|
||||
db = db.Where("type = ?", req.Type)
|
||||
}
|
||||
|
||||
if err := db.Take(whiteListItem).Error; err != nil {
|
||||
if !f5.IsOrmErrRecordNotFound(err) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"message": "sever internal error:" + err.Error(),
|
||||
})
|
||||
return
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 2,
|
||||
"message": "无法查到记录",
|
||||
})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if whiteListItem.Deleted == 1 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "",
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
whiteListItem.Deleted = 1
|
||||
whiteListItem.ModifyTime = nowDaySeconds
|
||||
|
||||
if err := db.Save(whiteListItem).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"message": "sever internal error:" + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "",
|
||||
})
|
||||
}
|
||||
|
||||
func (bpa *WhiteListApi) UploadExcel(c *gin.Context) {
|
||||
file, _, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "上传文件失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
xlsx, err := excelize.OpenReader(file)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "解析文件失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
rows, err := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||
whitelist := []*system.WhiteListItem{}
|
||||
for i, row := range rows {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
member := new(system.WhiteListItem)
|
||||
member.Account = row[0]
|
||||
member.Type = row[1]
|
||||
member.Deleted = 0
|
||||
member.CreateTime = nowDaySeconds
|
||||
member.ModifyTime = nowDaySeconds
|
||||
whitelist = append(whitelist, member)
|
||||
}
|
||||
|
||||
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(whitelist).Error; err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
"message": "",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "添加成功",
|
||||
})
|
||||
}
|
@ -3,6 +3,7 @@ package system
|
||||
type BlockPlayer struct {
|
||||
Account string `gorm:"column:account_id" json:"account_id"`
|
||||
Blocked int32 `gorm:"column:blocked" json:"blocked"`
|
||||
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||
}
|
||||
|
13
server/adminserver/model/system/whitelist.go
Normal file
13
server/adminserver/model/system/whitelist.go
Normal file
@ -0,0 +1,13 @@
|
||||
package system
|
||||
|
||||
type WhiteListItem struct {
|
||||
Account string `gorm:"column:account_id" json:"account_id"`
|
||||
Type string `gorm:"column:type" json:"type"`
|
||||
Deleted int32 `gorm:"column:deleted" json:"deleted"`
|
||||
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
|
||||
}
|
||||
|
||||
func (WhiteListItem) TableName() string {
|
||||
return "t_whitelist"
|
||||
}
|
@ -28,6 +28,7 @@ func (this *routerMgr) Init() {
|
||||
this.system.InitNFTRouter(priGroup)
|
||||
this.system.InitGameSwitchRouter(priGroup)
|
||||
this.system.InitBlockPlayerRouter(priGroup)
|
||||
this.system.InitWhiteListRouter(priGroup)
|
||||
|
||||
f5.GetSysLog().Info("routerMgr.init")
|
||||
}
|
||||
|
@ -12,4 +12,5 @@ type RouterGroup struct {
|
||||
NFTRouter
|
||||
GameSwitchRoute
|
||||
BlockPlayerRoute
|
||||
WhiteListRoute
|
||||
}
|
||||
|
23
server/adminserver/router/system/whitelist.go
Normal file
23
server/adminserver/router/system/whitelist.go
Normal file
@ -0,0 +1,23 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
v1 "main/api/v1"
|
||||
"main/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type WhiteListRoute struct {
|
||||
}
|
||||
|
||||
func (this *WhiteListRoute) InitWhiteListRouter(priRouter *gin.RouterGroup) {
|
||||
group := priRouter.Group("white_list")
|
||||
api := v1.ApiGroupApp.SystemApiGroup.WhiteListApi
|
||||
{
|
||||
group.POST("add", middleware.Permission("api/v1/white_list/add", api.Add))
|
||||
//group.POST("edit", middleware.Permission("api/v1/white_list/edit", api.Edit))
|
||||
group.POST("del", middleware.Permission("api/v1/white_list/del", api.Del))
|
||||
group.POST("list", middleware.Permission("api/v1/white_list/list", api.List))
|
||||
group.POST("uploadExcel", middleware.Permission("api/v1/white_list/uploadExcel", api.UploadExcel))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user