This commit is contained in:
aozhiwei 2024-08-30 15:25:17 +08:00
commit 1622ca5f09
26 changed files with 1015 additions and 215 deletions

View File

@ -99,6 +99,10 @@
"switch_name": "ui.contribution.show",
"switch_desc": "25-贡献点是否显示"
},
{
"switch_name": "ui.activationCode",
"switch_desc": "26-激活码是否显示"
},
{
"switch_name": "only.allowed.superWhiteList",
"switch_desc": "100-只允许至尊白名单用户登录登录"

1
bin/adminserver/config/nets Symbolic link
View File

@ -0,0 +1 @@
../../backtask/config/nets/

View File

@ -0,0 +1 @@
../../backtask/config/nets.json

View File

@ -135,6 +135,80 @@ CREATE TABLE `t_super_whitelist` (
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_whitelist`
--
DROP TABLE IF EXISTS `t_whitelist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_whitelist` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`user_identity` varchar(60) NOT NULL COMMENT 'account_id or account_address or email',
`enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `user_identity` (`user_identity`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_blacklist`
--
DROP TABLE IF EXISTS `t_blacklist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_blacklist` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`user_identity` varchar(60) NOT NULL COMMENT 'account_id or account_address or email',
`enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `user_identity` (`user_identity`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_internal_gameapi_host`
--
DROP TABLE IF EXISTS `t_internal_gameapi_host`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_internal_gameapi_host` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`gameapi_host` varchar(60) NOT NULL COMMENT 'gameapi_host(ip)',
`gameapi_port` int(11) NOT NULL DEFAULT '0' COMMENT 'gameapi_port',
`enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `gameapi_host` (`gameapi_host`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_apigate_host`
--
DROP TABLE IF EXISTS `t_apigate_host`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_apigate_host` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`apigate_host` varchar(60) NOT NULL COMMENT 'apigate_host(ip)',
`apigate_port` int(11) NOT NULL DEFAULT '0' COMMENT 'apigate_port',
`enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `apigate_host` (`apigate_host`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

View File

@ -0,0 +1,180 @@
package system
import (
"f5"
"fmt"
"main/constant"
"main/model/system"
"net/http"
"q5"
"strings"
"math/rand"
"github.com/gin-gonic/gin"
)
type ActiveCodeApi struct {
}
func (aca *ActiveCodeApi) GenCode(c *gin.Context) {
var batchid int32 = 0
var maxbatchid int32 = 0
db := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_activation_code").Select("max(batch_id)")
err := db.Error
if err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
f5.RspErr2(c, 1, err.Error())
return
}
} else {
var count int64 = 0
if db.Count(&count); count > 0 {
db.Scan(&maxbatchid)
}
}
if maxbatchid >= 0xFFF {
f5.RspErr2(c, 1, "batchid overflow")
return
}
batchid = maxbatchid + 1
count := q5.SafeToInt32(c.DefaultQuery("count", "1"))
if count < 1 {
count = 1
}
if count > 5000 {
count = 5000
}
tryCount := 0
postfix := fmt.Sprintf("%03x", batchid)
codelist := map[string]int{}
nowsecs := int32(f5.GetApp().GetRealSeconds())
batchcodeinfo := []*system.ActiveCode{}
for i := 0; i < int(count); {
if tryCount > 10000*10 {
f5.RspErr2(c, 1, "internal error")
return
}
code := aca.genCode(7) + postfix
_, exist := codelist[code]
if exist {
tryCount++
continue
}
codelist[code] = 1
i++
p := new(system.ActiveCode)
p.Batch_id = batchid
p.Code = code
p.CreateTime = nowsecs
p.ModifyTime = nowsecs
batchcodeinfo = append(batchcodeinfo, p)
}
err = f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_activation_code").Create(batchcodeinfo).Error
if err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "成功生成",
"batchid": batchid,
})
}
const strpol = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz"
func (this *ActiveCodeApi) genCode(n int) string {
var sb strings.Builder
k := len(strpol)
for i := 0; i < n; i++ {
c := strpol[rand.Intn(k)]
sb.WriteByte(c)
}
return sb.String()
}
func (this *ActiveCodeApi) List(c *gin.Context) {
req := struct {
BatchId int32 `json:"batch_id"`
PageDto system.PageDto `json:"page_dto"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
sql := fmt.Sprintf("SELECT * FROM t_activation_code WHERE 1=1 AND batch_id = %d", req.BatchId)
params := []string{}
result := []*system.ActiveCode{}
f5.GetGoStyleDb().PageQuery(
constant.ACCOUNT_DB,
q5.ToInt32(req.PageDto.PageSize),
q5.ToInt32(req.PageDto.Page),
sql,
params,
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
"",
func(err error, pg *f5.Pagination) {
if err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
f5.UnmarshalModelList(pg.Rows, &result)
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "获取成功",
"data": result,
"total": pg.Total,
"total_page": pg.TotalPages,
"cur_page": pg.CurrentPage,
})
})
}
func (this *ActiveCodeApi) DownloadFile(c *gin.Context) {
batchid := q5.SafeToInt32(c.DefaultQuery("batchid", ""))
if batchid < 1 {
f5.RspErr2(c, 1, "batchid error")
return
}
sql := fmt.Sprintf("SELECT * FROM t_activation_code WHERE 1=1 AND batch_id = %d", batchid)
f5.GetGoStyleDb().RawQuery(
constant.ACCOUNT_DB,
sql,
[]string{},
func(err error, ds *f5.DataSet) {
if err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
data := []struct {
BatchId int32 `json:"batch_id"`
Code string `json:"activation_code"`
}{}
for ds.Next() {
p := q5.NewSliceElement(&data)
p.BatchId = q5.SafeToInt32(ds.GetByName("batch_id"))
p.Code = ds.GetByName("activation_code")
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "",
"data": data,
})
})
}

View File

@ -30,10 +30,10 @@ 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 AND deleted = 0",
"SELECT * FROM t_blacklist WHERE 1=1",
[]string{},
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
" ORDER BY account_id ",
" ORDER BY user_identity ",
func(err error, pg *f5.Pagination) {
if err != nil {
c.JSON(http.StatusOK, gin.H{
@ -45,8 +45,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) {
for pg.Rows.Next() {
p := new(system.BlockPlayer)
p.Blocked = q5.SafeToInt32(pg.Rows.GetByName("blocked"))
p.Account = pg.Rows.GetByName("account_id")
p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable"))
p.Identity = pg.Rows.GetByName("user_identity")
p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime"))
p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime"))
q5.AppendSlice(&result, p)
@ -64,7 +64,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) {
func (bpa *BlockPlayerApi) Add(c *gin.Context) {
req := struct {
Account string `binding:"required" json:"account_id"`
Identity string `binding:"required" json:"user_identity"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
@ -74,34 +75,20 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) {
return
}
info := new(system.BlockPlayer)
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
var count int64 = 0
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blockplayer").Where("account_id =?", req.Account)
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blacklist").Where("user_identity =?", req.Identity)
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": "添加成功",
})
}
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "数据存在",
})
return
}
info.Account = req.Account
info.Blocked = 1
info := new(system.BlockPlayer)
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
info.Identity = req.Identity
info.Enable = req.Enable
info.CreateTime = nowDaySeconds
info.ModifyTime = nowDaySeconds
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
@ -119,8 +106,8 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) {
func (bpa *BlockPlayerApi) Edit(c *gin.Context) {
req := struct {
Account string `binding:"required" json:"account_id"`
Blocked int32 `json:"blocked"`
Identity string `binding:"required" json:"user_identity"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
@ -132,7 +119,7 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) {
blockplayer := new(system.BlockPlayer)
db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", req.Account).Error; err != nil {
if err := db.Take(blockplayer, "user_identity = ?", req.Identity).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
c.JSON(http.StatusOK, gin.H{
"code": 500,
@ -148,15 +135,16 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) {
}
}
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
blockplayer.Blocked = req.Blocked
blockplayer.ModifyTime = nowDaySeconds
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(),
})
return
if blockplayer.Enable != req.Enable {
blockplayer.Enable = req.Enable
blockplayer.ModifyTime = int32(f5.GetApp().GetRealSeconds())
if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).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,
@ -165,49 +153,49 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) {
}
func (bpa *BlockPlayerApi) Del(c *gin.Context) {
req := struct {
Account string `binding:"required" json:"account_id"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": err.Error(),
})
return
}
// req := struct {
// Identity string `binding:"required" json:"user_identity"`
// }{}
// if err := c.ShouldBindJSON(&req); err != nil {
// c.JSON(http.StatusOK, gin.H{
// "code": 1,
// "message": err.Error(),
// })
// return
// }
blockplayer := new(system.BlockPlayer)
db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", 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
}
} else {
}
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
blockplayer.Deleted = 1
blockplayer.ModifyTime = nowDaySeconds
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(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "",
})
// blockplayer := new(system.BlockPlayer)
// db := f5.GetApp().GetOrmDb(constant.CONF_DB)
// if err := db.Take(blockplayer, "user_identity = ?", req.Identity).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 {
// }
// nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
// blockplayer.Deleted = 1
// blockplayer.ModifyTime = nowDaySeconds
// if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).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 *BlockPlayerApi) UploadExcel(c *gin.Context) {
@ -242,8 +230,8 @@ func (bpa *BlockPlayerApi) UploadExcel(c *gin.Context) {
continue
}
member := new(system.BlockPlayer)
member.Account = row[0]
member.Blocked = 1
member.Identity = row[0]
member.Enable = 1
member.CreateTime = nowDaySeconds
member.ModifyTime = nowDaySeconds
blockplayers = append(blockplayers, member)

View File

@ -13,4 +13,6 @@ type ApiGroup struct {
GameSwitchApi
BlockPlayerApi
WhiteListApi
ActiveCodeApi
WorkerToolApi
}

View File

@ -3,8 +3,10 @@ package system
import (
"f5"
"fmt"
"jccommon"
"main/constant"
"main/model/system"
"main/mt"
"net/http"
"q5"
"strings"
@ -161,7 +163,7 @@ func (pai *PlayerApi) HeroesQuery(c *gin.Context) {
}
reqJson := HeroesQueryForm{}
if !checkparam(&reqJson, c) {
if !checkparam(&reqJson, c) || reqJson.Account_id == "" {
return
}
@ -174,8 +176,72 @@ func (pai *PlayerApi) HeroesQuery(c *gin.Context) {
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
filterstr := " account_id = '" + reqJson.Account_id + "' "
sql := fmt.Sprintf(`SELECT * FROM t_hero WHERE idx > %d AND %s `, cursor, filterstr)
filterstr := "account_id = '" + reqJson.Account_id + "' "
{
sql := fmt.Sprintf(`SELECT address FROM t_immutable_account WHERE idx > 1 AND account_id = '%s'`, reqJson.Account_id)
address := ""
f5.GetGoStyleDb().RawQuery(
constant.ACCOUNT_DB,
sql,
[]string{},
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
if ds.Next() {
address = ds.GetByIndex(0)
}
})
if address != "" {
lockaddrlist := []string{}
mt.Table.Contract.Traverse(func(mtc *mt.Contract) bool {
if mtc.GetName() == jccommon.CONTRACT_NAME_NFTLock {
lockaddrlist = append(lockaddrlist, strings.ToLower(mtc.GetAddress()))
}
return true
})
sql = fmt.Sprintf(`SELECT token_id FROM t_nft WHERE idx > 1 AND token_type IN (1, 12) AND (owner_address = '%s'`, address)
if len(lockaddrlist) > 0 {
sql += fmt.Sprintf(" OR (last_lock_address = '%s' AND owner_address IN (", address)
for _, addr := range lockaddrlist {
sql += "'" + addr + "',"
}
sql = sql[:len(sql)-1]
sql+="))"
}
sql += ")"
f5.GetSysLog().Debug("tokenid sql:%s", sql)
tokenidlist := []string{}
f5.GetGoStyleDb().RawQuery(
constant.BCNFT_DB,
sql,
[]string{},
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
for ds.Next() {
tokenidlist = append(tokenidlist, ds.GetByIndex(0))
}
})
if len(tokenidlist) > 0 {
tokenfilterstr := "OR token_id IN ("
for _, v := range tokenidlist {
tokenfilterstr += v + ","
}
tokenfilterstr = tokenfilterstr[:len(tokenfilterstr)-1]
tokenfilterstr += ")"
filterstr += tokenfilterstr
}
}
}
sql := fmt.Sprintf(`SELECT * FROM t_hero WHERE idx > %d AND (%s)`, cursor, filterstr)
f5.GetSysLog().Debug("hero sql:%s", sql)
query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {
p := new(system.Hero)
@ -300,11 +366,11 @@ func (pai *PlayerApi) RechargeQuery(c *gin.Context) {
}
cursor := q5.ToInt64(c.DefaultQuery("cursor", ""))
filterstr :=
" (receiver_account_id = '" + reqJson.Identity +
"' OR account_address = '" + reqJson.Identity +
"' OR passport_address = '" + reqJson.Identity +
"' OR lower_case_email = '" + reqJson.Identity + "')"
filterstr :=
" (receiver_account_id = '" + reqJson.Identity +
"' OR account_address = '" + reqJson.Identity +
"' OR passport_address = '" + reqJson.Identity +
"' OR lower_case_email = '" + reqJson.Identity + "')"
sql := fmt.Sprintf(`SELECT * FROM t_recharge_order WHERE idx > %d AND %s `, cursor, filterstr)
query(constant.BCNFT_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} {

View File

@ -16,7 +16,6 @@ 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 {
@ -26,12 +25,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) {
})
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)
}
sql := "SELECT * FROM t_whitelist WHERE 1=1"
params := []string{}
result := []*system.WhiteListItem{}
f5.GetGoStyleDb().PageQuery(
constant.CONF_DB,
@ -40,7 +35,7 @@ func (bpa *WhiteListApi) List(c *gin.Context) {
sql,
params,
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
" ORDER BY account_id ",
" ORDER BY user_identity ",
func(err error, pg *f5.Pagination) {
if err != nil {
c.JSON(http.StatusOK, gin.H{
@ -52,8 +47,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) {
for pg.Rows.Next() {
p := new(system.WhiteListItem)
p.Type = pg.Rows.GetByName("type")
p.Account = pg.Rows.GetByName("account_id")
p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable"))
p.Identity = pg.Rows.GetByName("user_identity")
p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime"))
p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime"))
q5.AppendSlice(&result, p)
@ -71,8 +66,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) {
func (bpa *WhiteListApi) Add(c *gin.Context) {
req := struct {
Account string `binding:"required" json:"account_id"`
Type string `binding:"required" json:"type"`
Identity string `binding:"required" json:"user_identity"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
@ -86,29 +81,17 @@ func (bpa *WhiteListApi) Add(c *gin.Context) {
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)
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("user_identity = ?", req.Identity)
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": "添加成功",
})
}
c.JSON(http.StatusOK, gin.H{
"code": 1,
"message": "数据存在",
})
return
}
info.Account = req.Account
info.Type = req.Type
info.Identity = req.Identity
info.Enable = req.Enable
info.CreateTime = nowDaySeconds
info.ModifyTime = nowDaySeconds
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
@ -125,56 +108,9 @@ func (bpa *WhiteListApi) Add(c *gin.Context) {
}
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"`
Identity string `binding:"required" json:"user_identity"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
@ -185,12 +121,8 @@ func (bpa *WhiteListApi) Del(c *gin.Context) {
}
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 {
db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(whiteListItem, "user_identity =?", req.Identity).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
c.JSON(http.StatusOK, gin.H{
"code": 500,
@ -204,33 +136,86 @@ func (bpa *WhiteListApi) Del(c *gin.Context) {
})
return
}
} else {
if whiteListItem.Deleted == 1 {
c.JSON(http.StatusOK, gin.H{
"code": 2,
"message": "无法查到记录",
})
}
if whiteListItem.Enable != req.Enable {
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
whiteListItem.Enable = req.Enable
whiteListItem.ModifyTime = nowDaySeconds
if err := db.Where("user_identity = ?", req.Identity).Save(whiteListItem).Error; err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"message": "sever internal error:" + err.Error(),
})
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) Del(c *gin.Context) {
// req := struct {
// Account string `binding:"required" json:"user_identity"`
// 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("user_identity = ?", 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": 2,
// "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 {
@ -263,9 +248,8 @@ func (bpa *WhiteListApi) UploadExcel(c *gin.Context) {
continue
}
member := new(system.WhiteListItem)
member.Account = row[0]
member.Type = row[1]
member.Deleted = 0
member.Identity = row[0]
member.Enable = 1
member.CreateTime = nowDaySeconds
member.ModifyTime = nowDaySeconds
whitelist = append(whitelist, member)

View File

@ -0,0 +1,263 @@
package system
import (
"f5"
"fmt"
"main/constant"
"main/model/system"
"net"
"net/http"
"q5"
"time"
"github.com/gin-gonic/gin"
)
type WorkerToolApi struct {
}
func (bpa *WorkerToolApi) ListGameApi(c *gin.Context) {
req := struct {
PageDto system.PageDto `json:"page_dto"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
sql := "SELECT * FROM t_internal_gameapi_host WHERE 1=1"
params := []string{}
result := []*system.GameApiHostItem{}
f5.GetGoStyleDb().PageQuery(
constant.CONF_DB,
q5.ToInt32(req.PageDto.PageSize),
q5.ToInt32(req.PageDto.Page),
sql,
params,
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
"",
func(err error, pg *f5.Pagination) {
if err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
for pg.Rows.Next() {
p := new(system.GameApiHostItem)
f5.UnmarshalModel(pg.Rows, p)
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 *WorkerToolApi) AddGameApi(c *gin.Context) {
req := struct {
Host string `binding:"required" json:"gameapi_host"`
Port int32 `binding:"required" json:"gameapi_port"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
if !bpa.testHostport(c, req.Host, req.Port) {
return
}
info := new(system.GameApiHostItem)
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
var count int64 = 0
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port)
if err := db.Count(&count).Error; err == nil && count > 0 {
f5.RspErr2(c, 1, "数据存在")
return
}
info.Host = req.Host
info.Port = req.Port
info.Enable = req.Enable
info.CreateTime = nowDaySeconds
info.ModifyTime = nowDaySeconds
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
f5.RspErr2(c, 0, "添加成功")
}
func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) {
req := struct {
Host string `binding:"required" json:"gameapi_host"`
Port int32 `binding:"required" json:"gameapi_port"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
if !bpa.testHostport(c, req.Host, req.Port) {
return
}
item := new(system.GameApiHostItem)
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
if err := db.Take(item, "gameapi_host = ? AND gameapi_port = ?", req.Host, req.Port).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
return
} else {
f5.RspErr2(c, 2, "无法查到记录")
return
}
}
if item.Enable != req.Enable {
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
item.Enable = req.Enable
item.ModifyTime = nowDaySeconds
if err := db.Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port).Save(item).Error; err != nil {
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
return
}
}
f5.RspErr2(c, 0, "")
}
func (bpa *WorkerToolApi) ListApiGate(c *gin.Context) {
req := struct {
PageDto system.PageDto `json:"page_dto"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
sql := "SELECT * FROM t_apigate_host WHERE 1=1"
params := []string{}
result := []*system.ApiGateHostItem{}
f5.GetGoStyleDb().PageQuery(
constant.CONF_DB,
q5.ToInt32(req.PageDto.PageSize),
q5.ToInt32(req.PageDto.Page),
sql,
params,
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
"",
func(err error, pg *f5.Pagination) {
if err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
for pg.Rows.Next() {
p := new(system.ApiGateHostItem)
f5.UnmarshalModel(pg.Rows, p)
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 *WorkerToolApi) AddApiGate(c *gin.Context) {
req := struct {
Host string `binding:"required" json:"apigate_host"`
Port int32 `binding:"required" json:"apigate_port"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
if !bpa.testHostport(c, req.Host, req.Port) {
return
}
info := new(system.ApiGateHostItem)
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
var count int64 = 0
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port)
if err := db.Count(&count).Error; err == nil && count > 0 {
f5.RspErr2(c, 1, "数据存在")
return
}
info.Host = req.Host
info.Port = req.Port
info.Enable = req.Enable
info.CreateTime = nowDaySeconds
info.ModifyTime = nowDaySeconds
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
f5.RspErr2(c, 0, "添加成功")
}
func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) {
req := struct {
Host string `binding:"required" json:"apigate_host"`
Port int32 `binding:"required" json:"apigate_port"`
Enable int32 `json:"enable"`
}{}
if err := c.ShouldBindJSON(&req); err != nil {
f5.RspErr2(c, 1, err.Error())
return
}
if !bpa.testHostport(c, req.Host, req.Port) {
return
}
item := new(system.ApiGateHostItem)
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
if err := db.Take(item, "apigate_host = ? AND apigate_port = ?", req.Host, req.Port).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) {
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
return
} else {
f5.RspErr2(c, 2, "无法查到记录")
return
}
}
if item.Enable != req.Enable {
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
item.Enable = req.Enable
item.ModifyTime = nowDaySeconds
if err := db.Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port).Save(item).Error; err != nil {
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
return
}
}
f5.RspErr2(c, 0, "")
}
func (bpa *WorkerToolApi) testHostport(c *gin.Context, host string, port int32) bool {
addrAndPort := fmt.Sprintf("%s:%d", host, port)
conn, err := net.DialTimeout("tcp", addrAndPort, time.Second)
if err != nil {
f5.RspErr2(c, 2, "host port 连不上")
return false
} else {
conn.Close()
return true
}
}

View File

@ -0,0 +1,12 @@
package system
type ActiveCode struct {
Code string `gorm:"column:activation_code" json:"activation_code"`
Batch_id int32 `gorm:"column:batch_id" json:"batch_id"`
CreateTime int32 `gorm:"column:createtime" json:"-"`
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
}
func (ac *ActiveCode) TableName() string {
return "t_activation_code"
}

View File

@ -1,13 +1,12 @@
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"`
Identity string `gorm:"column:user_identity" json:"user_identity"`
Enable int32 `gorm:"column:enable" json:"enable"`
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
}
func (BlockPlayer) TableName() string {
return "t_blockplayer"
return "t_blacklist"
}

View File

@ -1,9 +1,8 @@
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"`
Identity string `gorm:"column:user_identity" json:"user_identity"`
Enable int32 `gorm:"column:enable" json:"enable"`
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
}
@ -13,10 +12,7 @@ func (WhiteListItem) TableName() string {
}
type SuperWhiteListItem struct {
Identity string `gorm:"column:user_identity" json:"user_identity"`
Enable int32 `gorm:"column:enable" json:"enable"`
CreateTime int32 `gorm:"column:createtime" json:"createtime"`
ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"`
WhiteListItem
}
func (SuperWhiteListItem) TableName() string {

View File

@ -0,0 +1,25 @@
package system
type GameApiHostItem struct {
Host string `gorm:"column:gameapi_host" json:"gameapi_host"`
Port int32 `gorm:"column:gameapi_port" json:"gameapi_port"`
Enable int32 `gorm:"column:enable" json:"enable"`
CreateTime int32 `gorm:"column:createtime" json:"-"`
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
}
func (GameApiHostItem) TableName() string {
return "t_internal_gameapi_host"
}
type ApiGateHostItem struct {
Host string `gorm:"column:apigate_host" json:"apigate_host"`
Port int32 `gorm:"column:apigate_port" json:"apigate_port"`
Enable int32 `gorm:"column:enable" json:"enable"`
CreateTime int32 `gorm:"column:createtime" json:"-"`
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
}
func (ApiGateHostItem) TableName() string {
return "t_apigate_host"
}

View File

@ -0,0 +1,112 @@
package mt
import (
"encoding/json"
"f5"
"fmt"
"q5"
"strings"
)
type Contract struct {
name string
address string
}
type ContractTable struct {
netIdNameHash *q5.ConcurrentMap[string, *Contract]
netIdAddressHash *q5.ConcurrentMap[string, *Contract]
}
func (this *Contract) GetName() string {
return this.name
}
func (this *Contract) GetAddress() string {
return this.address
}
func (this *ContractTable) IsNoLoad() bool {
return false
}
func (this *ContractTable) Load() {
this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract])
this.netIdAddressHash = new(q5.ConcurrentMap[string, *Contract])
nets := []interface{}{}
{
if jsonStr, err := f5.ReadJsonFile("../config/nets.json"); err == nil {
if err := json.Unmarshal([]byte(jsonStr), &nets); err != nil {
panic(fmt.Sprintf("load metafile json decode error %s %s", "nets.json", err))
}
} else {
panic(fmt.Sprintf("load metafile error %s %s", "nets.json", err))
}
}
{
for _, val := range nets {
netId := q5.SafeToInt32(val)
fileName := fmt.Sprintf("../config/nets/%d/contract.json", netId)
if jsonStr, err := f5.ReadJsonFile(fileName); err == nil {
contracts := []struct {
Name string `json:"name"`
Address string `json:"address"`
}{}
if err := json.Unmarshal([]byte(jsonStr), &contracts); err != nil {
panic(fmt.Sprintf("load metafile json decode error %s %s", "contract.json", err))
}
for _, val2 := range contracts {
p := new(Contract)
p.name = q5.SafeToString(val2.Name)
p.address = strings.ToLower(q5.SafeToString(val2.Address))
{
key := fmt.Sprintf("%d_%s", netId, p.name)
this.netIdNameHash.Store(key, p)
}
{
key := fmt.Sprintf("%d_%s", netId, p.address)
this.netIdAddressHash.Store(key, p)
}
}
} else {
panic(fmt.Sprintf("load metafile error %s %s", "contract.json", err))
}
}
}
}
func (this *ContractTable) PreInit1() {
}
func (this *ContractTable) ElementsInit(int) {
}
func (this *ContractTable) PostInit1() {
}
func (this *ContractTable) GetByNetIdName(netId int32, name string) *Contract {
key := fmt.Sprintf("%d_%s", netId, name)
if v, ok := this.netIdNameHash.Load(key); ok {
return *v
} else {
return nil
}
}
func (this *ContractTable) GetByNetIdAddress(netId int32, address string) *Contract {
key := fmt.Sprintf("%d_%s", netId, address)
if v, ok := this.netIdAddressHash.Load(key); ok {
return *v
} else {
return nil
}
}
func (this *ContractTable) Traverse(cb func(*Contract) bool) {
this.netIdNameHash.Range(func(k string, v *Contract) bool {
return cb(v)
})
}

View File

@ -17,6 +17,7 @@ type table struct {
Permission *PermissionTable
ConfDb *ConfDbTable
Item *ItemTable
Contract *ContractTable
}
var Table = f5.New(func(this *table) {
@ -71,6 +72,8 @@ var Table = f5.New(func(this *table) {
this.Permission = new(PermissionTable)
this.Contract = new(ContractTable)
this.Item = f5.New(func(this *ItemTable) {
this.FileName = "../res/item@item.json"
this.PrimKey = "id"

View File

@ -29,6 +29,8 @@ func (this *routerMgr) Init() {
this.system.InitGameSwitchRouter(priGroup)
this.system.InitBlockPlayerRouter(priGroup)
this.system.InitWhiteListRouter(priGroup)
this.system.InitActiveCodeRouter(priGroup)
this.system.InitWorkerToolRouter(priGroup)
f5.GetSysLog().Info("routerMgr.init")
}

View File

@ -0,0 +1,21 @@
package system
import (
v1 "main/api/v1"
"main/middleware"
"github.com/gin-gonic/gin"
)
type ActiveCodeRoute struct {
}
func (this *ActiveCodeRoute) InitActiveCodeRouter(priRouter *gin.RouterGroup) {
group := priRouter.Group("active_code")
api := v1.ApiGroupApp.SystemApiGroup.ActiveCodeApi
{
group.GET("gen", middleware.Permission("api/v1/active_code/gen", api.GenCode))
group.POST("list", middleware.Permission("api/v1/active_code/list", api.List))
group.GET("download", middleware.Permission("api/v1/active_code/download", api.DownloadFile))
}
}

View File

@ -16,7 +16,7 @@ func (this *BlockPlayerRoute) InitBlockPlayerRouter(priRouter *gin.RouterGroup)
{
group.POST("add", middleware.Permission("api/v1/block_player/add", api.Add))
group.POST("edit", middleware.Permission("api/v1/block_player/edit", api.Edit))
group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del))
// group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del))
group.POST("list", middleware.Permission("api/v1/block_player/list", api.List))
group.POST("uploadExcel", middleware.Permission("api/v1/block_player/uploadExcel", api.UploadExcel))
}

View File

@ -13,4 +13,6 @@ type RouterGroup struct {
GameSwitchRoute
BlockPlayerRoute
WhiteListRoute
ActiveCodeRoute
WorkerToolRoute
}

View File

@ -15,8 +15,8 @@ func (this *WhiteListRoute) InitWhiteListRouter(priRouter *gin.RouterGroup) {
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("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))
}

View File

@ -0,0 +1,28 @@
package system
import (
v1 "main/api/v1"
"main/middleware"
"github.com/gin-gonic/gin"
)
type WorkerToolRoute struct {
}
func (this *WorkerToolRoute) InitWorkerToolRouter(priRouter *gin.RouterGroup) {
group := priRouter.Group("gameapihost")
api := v1.ApiGroupApp.SystemApiGroup.WorkerToolApi
{
group.POST("add", middleware.Permission("api/v1/gameapihost/add", api.AddGameApi))
group.POST("edit", middleware.Permission("api/v1/gameapihost/edit", api.EditGameApi))
group.POST("list", middleware.Permission("api/v1/gameapihost/list", api.ListGameApi))
}
{
supergroup := priRouter.Group("apigate")
supergroup.POST("add", middleware.Permission("api/v1/apigate/add", api.AddApiGate))
supergroup.POST("list", middleware.Permission("api/v1/apigate/list", api.ListApiGate))
supergroup.POST("edit", middleware.Permission("api/v1/apigate/edit", api.EditApiGate))
}
}

View File

@ -101,9 +101,13 @@ func (this *RechargeApi) BuyWithEmail(c *gin.Context) {
CurrencyAddress string `json:"currency_address"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
f5.GetSysLog().Info("BuyWithEmail passport_address:%s err:%s",
passportAddress, err)
f5.RspErr(c, 1, err.Error())
return
}
f5.GetSysLog().Info("BuyWithEmail passport_address:%s email:%s reqJson:%s",
passportAddress, email, q5.EncodeJson(&reqJson))
if email == "" {
f5.RspErr(c, 1, "email is empty")
return
@ -119,28 +123,34 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
passportAddress = strings.ToLower(passportAddress)
currencyMeta := mt.Table.Currency.GetByNetIdAddress(netId, currencyAddress)
if currencyMeta == nil {
f5.GetSysLog().Info("internalBuy error:1")
f5.RspErr(c, 2, "server internal error")
return
}
currencyContractMeta := currencyMeta.GetContract()
if currencyContractMeta == nil {
f5.GetSysLog().Info("internalBuy error:2")
f5.RspErr(c, 2, "server internal error")
return
}
goodsMeta := mt.Table.Recharge.GetById(q5.ToInt64(goodsId))
if goodsMeta == nil {
f5.GetSysLog().Info("internalBuy error:3")
f5.RspErr(c, 2, "goods id param error")
return
}
if goodsMeta.GetPrice() <= 0 {
f5.GetSysLog().Info("internalBuy error:4")
f5.RspErr(c, 2, "goods id param error")
return
}
if goodsNum <= 0 || goodsNum > goodsMeta.GetMaxBuyTimes() {
f5.GetSysLog().Info("internalBuy error:5")
f5.RspErr(c, 2, "num param error")
return
}
if email != "" && goodsMeta.GetCanEmailBuy() == 0 {
f5.GetSysLog().Info("internalBuy error:6")
f5.RspErr(c, 2, "cant email buy")
return
}
@ -161,6 +171,7 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
var err error
orderId, err = transId.ToString()
if err != nil {
f5.GetSysLog().Info("internalBuy error:6")
f5.RspErr(c, 2, "server internal error")
return
}
@ -175,13 +186,16 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
f5.GetSysLog().Info("recharge net_id:%d currency_name:%s decimal:%d srcPrice:%d bnPrice:%s",
netId, currencyMeta.GetCurrencyName(), currencyMeta.GetCurrencyDecimal(), srcPrice, bnPrice.String());
if bnPrice.Cmp(big.NewInt(0)) < 0 || bnPrice.Cmp(big.NewInt(srcPrice)) < 0 {
f5.GetSysLog().Info("internalBuy error:7")
f5.RspErr(c, 3, "server internal error")
return
}
if ok, err := service.User.InBlackList(accountAddress); err != nil {
f5.GetSysLog().Info("internalBuy error:8")
f5.RspErr(c, 500, "server internal error")
return
} else if ok {
f5.GetSysLog().Info("internalBuy error:9")
f5.RspErr(c, 501, "illegal user")
return
}
@ -210,10 +224,12 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
params,
func(rsp f5.HttpCliResponse) {
if rsp.GetErr() != nil {
f5.GetSysLog().Info("internalBuy error:a")
f5.RspErr(c, 500, "server internal error")
return
}
if q5.DecodeJson(rsp.GetRawData(), &jsonRspObj) != nil {
f5.GetSysLog().Info("internalBuy error:b")
f5.RspErr(c, 500, "server internal error")
return
}
@ -236,9 +252,18 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
diamond,
presentDiamond,
email) {
f5.GetSysLog().Info("internalBuy error:c")
f5.RspErr(c, 500, "server internal error")
return
}
f5.GetSysLog().Info("recharge net_id:%d currency_name:%s decimal:%d srcPrice:%d bnPrice:%s calls.len:%d jsonRsp:%s",
netId,
currencyMeta.GetCurrencyName(),
currencyMeta.GetCurrencyDecimal(),
srcPrice,
bnPrice.String(),
len(jsonRspObj.Calls),
q5.EncodeJson(&jsonRspObj));
c.JSON(200, jsonRspObj)
})
}

View File

@ -11,6 +11,13 @@ type gameSwitch struct {
time int64
}
func (this *gameSwitch) init() {
this.GetSwitchList()
}
func (this *gameSwitch) unInit() {
}
func (this *gameSwitch) GetSwitchList() map[string]int32 {
now := f5.GetApp().GetRealSeconds()
if now > this.time+30 {

View File

@ -6,9 +6,11 @@ type serviceMgr struct {
func (this *serviceMgr) Init() {
Contribution.init()
User.init()
GameSwitches.init()
}
func (this *serviceMgr) UnInit() {
Contribution.unInit()
User.unInit()
GameSwitches.unInit()
}

View File

@ -1,9 +1,9 @@
package service
import (
"f5"
"main/constant"
"q5"
//"f5"
//"main/constant"
//"q5"
)
//"strings"
@ -18,6 +18,8 @@ func (this *user) unInit() {
}
func (this *user) InBlackList(userIdentity string) (bool, error) {
return false, nil
/*
if userIdentity == "" {
return true, nil
}
@ -37,4 +39,5 @@ func (this *user) InBlackList(userIdentity string) (bool, error) {
blocked = ds.Next() && q5.SafeToInt32(ds.GetByName("blocked")) != 0 && q5.SafeToInt32(ds.GetByName("deleted")) == 0
})
return blocked, queryerr
*/
}