giftcode
This commit is contained in:
parent
735c0b90e2
commit
dd6ac9c8bb
@ -1,9 +1,21 @@
|
||||
{
|
||||
"host": "mysql-test.kingsome.cn",
|
||||
"port": 3306,
|
||||
"user": "root",
|
||||
"passwd": "keji178",
|
||||
"database": "maildb_dev_1",
|
||||
"max_open_conns": 1,
|
||||
"max_idle_conns": 1
|
||||
}
|
||||
[
|
||||
{
|
||||
"host": "mysql-test.kingsome.cn",
|
||||
"port": 3306,
|
||||
"user": "root",
|
||||
"passwd": "keji178",
|
||||
"database": "gamedb2004_1",
|
||||
"max_open_conns": 1,
|
||||
"max_idle_conns": 1,
|
||||
"gameid": 2004
|
||||
},{
|
||||
"host": "mysql-test.kingsome.cn",
|
||||
"port": 3306,
|
||||
"user": "root",
|
||||
"passwd": "keji178",
|
||||
"database": "maildb_dev_1",
|
||||
"max_open_conns": 1,
|
||||
"max_idle_conns": 1,
|
||||
"gameid": 2006
|
||||
}
|
||||
]
|
||||
|
@ -26,4 +26,31 @@ CREATE TABLE `t_audit` (
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `model` (`model`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
CREATE TABLE `t_gift_type` (
|
||||
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`gameid` int(11) NOT NULL DEFAULT '0' COMMENT '游戏id',
|
||||
`gift_type` int(11) NOT NULL DEFAULT '0' COMMENT 'typeid',
|
||||
`content` varchar(255) CHARACTER SET utf8 NOT NULL COMMENT 'itemid:itemnum|itemid:itemnum',
|
||||
`limit` int(11) NOT NULL DEFAULT '0' COMMENT '0:单兑换码可多次使用;1:只能使用1次',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `idx_game_type` (`gameid`,`gift_type`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
||||
CREATE TABLE `t_gift_code` (
|
||||
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`gameid` int(11) NOT NULL DEFAULT '0' COMMENT '游戏id',
|
||||
`gift_code` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'gift_code',
|
||||
`batch_id` int(11) NOT NULL DEFAULT '0' COMMENT '批次号',
|
||||
`gift_type` int(11) NOT NULL DEFAULT '0' COMMENT 'typeid',
|
||||
`limit` int(11) NOT NULL DEFAULT '0' COMMENT '0:单兑换码可多次使用;1:只能使用1次',
|
||||
`count` int(11) NOT NULL DEFAULT '0' COMMENT '已用次数',
|
||||
`content` varchar(255) CHARACTER SET utf8 NOT NULL COMMENT 'itemid:itemnum|itemid:itemnum',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `idx_game_code` (`gameid`,`gift_code`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
@ -7,9 +7,6 @@ import (
|
||||
"main/model/system"
|
||||
"net/http"
|
||||
"q5"
|
||||
"strings"
|
||||
|
||||
"math/rand"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -60,7 +57,7 @@ func (aca *ActiveCodeApi) GenCode(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
code := aca.genCode(7) + postfix
|
||||
code := genCode(7) + postfix
|
||||
_, exist := codelist[code]
|
||||
if exist {
|
||||
tryCount++
|
||||
@ -90,20 +87,6 @@ func (aca *ActiveCodeApi) GenCode(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
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"`
|
||||
|
@ -1,5 +1,10 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ApiGroup struct {
|
||||
UserApi
|
||||
AnncApi
|
||||
@ -15,4 +20,19 @@ type ApiGroup struct {
|
||||
WhiteListApi
|
||||
ActiveCodeApi
|
||||
WorkerToolApi
|
||||
GiftCodeApi
|
||||
}
|
||||
|
||||
const strpol = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz"
|
||||
|
||||
func 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()
|
||||
}
|
||||
|
277
server/adminserver/api/v1/system/giftcode.go
Normal file
277
server/adminserver/api/v1/system/giftcode.go
Normal file
@ -0,0 +1,277 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"net/http"
|
||||
"q5"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type GiftCodeApi struct {
|
||||
}
|
||||
|
||||
func (aca *GiftCodeApi) GenCode(c *gin.Context) {
|
||||
var maxbatchid int32 = 0
|
||||
gameid := q5.SafeToInt32(c.DefaultQuery("gameid", "1"))
|
||||
typeid := q5.SafeToInt32(c.DefaultQuery("type", ""))
|
||||
gifttype := new(system.GiftType)
|
||||
db := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_gift_type").Take(gifttype, "gameid = ? AND gift_type = ?", gameid, typeid)
|
||||
if db.Error != nil {
|
||||
if !f5.IsOrmErrRecordNotFound(db.Error) {
|
||||
f5.RspErr2(c, 1, db.Error.Error())
|
||||
} else {
|
||||
f5.RspErr2(c, 1, "type error")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
db = f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_gift_code").Where("gameid = ?", gameid).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.GiftCode{}
|
||||
for i := 0; i < int(count); {
|
||||
if tryCount > 10000*10 {
|
||||
f5.RspErr2(c, 1, "internal error")
|
||||
return
|
||||
}
|
||||
|
||||
code := genCode(7) + postfix
|
||||
_, exist := codelist[code]
|
||||
if exist {
|
||||
tryCount++
|
||||
continue
|
||||
}
|
||||
|
||||
codelist[code] = 1
|
||||
i++
|
||||
p := new(system.GiftCode)
|
||||
p.GameId = gameid
|
||||
p.GiftCode = code
|
||||
p.Batch_id = batchid
|
||||
p.GiftType = typeid
|
||||
p.Limit = gifttype.Limit
|
||||
p.Count = 0
|
||||
p.Content = gifttype.Content
|
||||
p.CreateTime = nowsecs
|
||||
p.ModifyTime = nowsecs
|
||||
batchcodeinfo = append(batchcodeinfo, p)
|
||||
}
|
||||
|
||||
err = f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_gift_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,
|
||||
})
|
||||
}
|
||||
|
||||
func (this *GiftCodeApi) List(c *gin.Context) {
|
||||
req := struct {
|
||||
GameId int32 `json:"gameid"`
|
||||
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_gift_code WHERE 1=1 AND gameid = %d AND batch_id = %d", req.GameId, req.BatchId)
|
||||
params := []string{}
|
||||
result := []*system.GiftCode{}
|
||||
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 *GiftCodeApi) 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,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (this *GiftCodeApi) ListType(c *gin.Context) {
|
||||
req := struct {
|
||||
GameId int32 `json:"gameid"`
|
||||
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_gift_type WHERE 1=1 AND gameid = %d", req.GameId)
|
||||
params := []string{}
|
||||
result := []*system.GiftType{}
|
||||
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 *GiftCodeApi) AddType(c *gin.Context) {
|
||||
req := struct {
|
||||
GameId int32 `json:"gameid"`
|
||||
Limit int32 `json:"limit"`
|
||||
Content string `json:"content"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
f5.RspErr2(c, 1, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var maxtype int32 = 0
|
||||
db := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_gift_type").Where("gameid = ?", req.GameId).Select("max(gift_type)")
|
||||
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(&maxtype)
|
||||
}
|
||||
}
|
||||
|
||||
if maxtype >= 0xFFFF {
|
||||
f5.RspErr2(c, 1, "type overflow")
|
||||
return
|
||||
}
|
||||
|
||||
nowsecs := int32(f5.GetApp().GetRealSeconds())
|
||||
|
||||
p := new(system.GiftType)
|
||||
p.GiftType = maxtype + 1
|
||||
p.GameId = req.GameId
|
||||
p.Content = req.Content
|
||||
p.Limit = req.Limit
|
||||
if p.Limit > 1 {
|
||||
p.Limit = 1
|
||||
}
|
||||
p.CreateTime = nowsecs
|
||||
p.ModifyTime = nowsecs
|
||||
|
||||
err = f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table(p.TableName()).Create(p).Error
|
||||
if err != nil {
|
||||
f5.RspErr2(c, 1, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "成功生成",
|
||||
})
|
||||
}
|
@ -7,7 +7,6 @@ import (
|
||||
"main/common"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"main/mt"
|
||||
"net/http"
|
||||
"q5"
|
||||
"strings"
|
||||
@ -23,6 +22,11 @@ type MailApi struct {
|
||||
func (this *MailApi) ListMail(c *gin.Context) {
|
||||
var pageSize = q5.SafeToInt32(c.DefaultQuery("pagesize", ""))
|
||||
var cursor = q5.SafeToInt32(c.DefaultQuery("cursor", ""))
|
||||
var gameidstr = c.DefaultQuery("gameid", "")
|
||||
if len(gameidstr) == 0 {
|
||||
f5.RspErr2(c, 1, "gameid error")
|
||||
return
|
||||
}
|
||||
reqObj := struct {
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
@ -87,7 +91,7 @@ func (this *MailApi) ListMail(c *gin.Context) {
|
||||
Data []*system.Mail `json:"data"`
|
||||
}{}
|
||||
f5.GetGoStyleDb().PageQuery(
|
||||
constant.MAIL_DB,
|
||||
constant.MAIL_DB + gameidstr,
|
||||
pageSize,
|
||||
cursor,
|
||||
sql,
|
||||
@ -103,7 +107,12 @@ func (this *MailApi) ListMail(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, rspObj)
|
||||
}
|
||||
|
||||
func (this *MailApi) AddMail(c *gin.Context) {
|
||||
func (this *MailApi) AddMail(c *gin.Context) {
|
||||
var gameidstr = c.DefaultQuery("gameid", "")
|
||||
if len(gameidstr) == 0 {
|
||||
f5.RspErr2(c, 1, "gameid error")
|
||||
return
|
||||
}
|
||||
reqJson := struct {
|
||||
UniKey string `json:"unikey"`
|
||||
MailType int32 `binding:"required" json:"mailtype"`
|
||||
@ -148,7 +157,7 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
||||
}
|
||||
|
||||
var count int64 = 0
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Table("t_mail").Where("unikey = ?", reqJson.UniKey).Count(&count); count > 0 {
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Table("t_mail").Where("unikey = ?", reqJson.UniKey).Count(&count); count > 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 2,
|
||||
"message": "unikey 重复",
|
||||
@ -178,7 +187,7 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
||||
mail.ModifyTime = nowDaySeconds
|
||||
mail.CreateAddress = acc
|
||||
mail.UpdateAddress = acc
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(mail).Error != nil {
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Create(mail).Error != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"message": "",
|
||||
@ -191,7 +200,7 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
||||
e.Param1 = q5.ToString(mail.MailId)
|
||||
e.CreateTime = nowDaySeconds
|
||||
e.ModifyTime = nowDaySeconds
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Create(e)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
@ -200,6 +209,11 @@ func (this *MailApi) AddMail(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (this *MailApi) EditMail(c *gin.Context) {
|
||||
var gameidstr = c.DefaultQuery("gameid", "")
|
||||
if len(gameidstr) == 0 {
|
||||
f5.RspErr2(c, 1, "gameid error")
|
||||
return
|
||||
}
|
||||
reqJson := struct {
|
||||
MailId int64 `binding:"required" json:"mail_id,string"`
|
||||
MailType int32 `binding:"required" json:"mail_type"`
|
||||
@ -233,7 +247,7 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
||||
|
||||
var count int64 = 0
|
||||
mail := new(system.Mail)
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB).Table(mail.TableName()).Take(mail, "mail_id = ?", reqJson.MailId).Count(&count); count < 1 {
|
||||
if f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Table(mail.TableName()).Take(mail, "mail_id = ?", reqJson.MailId).Count(&count); count < 1 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 2,
|
||||
"message": "mailid不存在",
|
||||
@ -265,14 +279,14 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
||||
s := c.MustGet("session").(common.Session)
|
||||
acc := s.GetAccountAddress()
|
||||
mail.UpdateAddress = acc
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Save(mail)
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Save(mail)
|
||||
{
|
||||
e := new(jccommon.MailEvent)
|
||||
e.EventName = jccommon.EVENT_MAIL_UPDATE
|
||||
e.Param1 = q5.ToString(mail.MailId)
|
||||
e.CreateTime = nowDaySeconds
|
||||
e.ModifyTime = nowDaySeconds
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Create(e)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
@ -281,10 +295,15 @@ func (this *MailApi) EditMail(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (this *MailApi) DelMail(c *gin.Context) {
|
||||
var gameidstr = c.DefaultQuery("gameid", "")
|
||||
if len(gameidstr) == 0 {
|
||||
f5.RspErr2(c, 1, "gameid error")
|
||||
return
|
||||
}
|
||||
mailid := q5.ToInt64(c.Param("mailid"))
|
||||
|
||||
var count int64 = 0
|
||||
db := f5.GetApp().GetOrmDb(constant.MAIL_DB).Table("t_mail").Where("mail_id = ?", mailid)
|
||||
db := f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Table("t_mail").Where("mail_id = ?", mailid)
|
||||
if db.Count(&count); count < 1 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 2,
|
||||
@ -309,7 +328,7 @@ func (this *MailApi) DelMail(c *gin.Context) {
|
||||
e.Param1 = q5.ToString(mailid)
|
||||
e.CreateTime = nowDaySeconds
|
||||
e.ModifyTime = nowDaySeconds
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB).Create(e)
|
||||
f5.GetApp().GetOrmDb(constant.MAIL_DB + gameidstr).Create(e)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
@ -336,13 +355,13 @@ func (this *MailApi) CheckAttachment(list []common.Attachment, c *gin.Context) b
|
||||
return false
|
||||
}
|
||||
|
||||
if !mt.Table.Item.Search(item.ItemId) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 2,
|
||||
"message": "item id error:" + q5.SafeToString(item.ItemId),
|
||||
})
|
||||
return false
|
||||
}
|
||||
// if !mt.Table.Item.Search(item.ItemId) {
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 2,
|
||||
// "message": "item id error:" + q5.SafeToString(item.ItemId),
|
||||
// })
|
||||
// return false
|
||||
// }
|
||||
|
||||
if item.ItemNum > 1000*10000 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
//"crypto/md5"
|
||||
//"encoding/hex"
|
||||
"f5"
|
||||
"q5"
|
||||
|
||||
//"fmt"
|
||||
"main/constant"
|
||||
"main/mt"
|
||||
@ -63,14 +65,29 @@ func (this *app) registerDataSources() {
|
||||
mt.Table.AccountDb.GetById(0).GetPasswd(),
|
||||
mt.Table.AccountDb.GetById(0).GetDatabase(),
|
||||
)
|
||||
f5.GetApp().RegisterOrmDb(
|
||||
constant.MAIL_DB,
|
||||
mt.Table.MailDb.GetById(0).GetHost(),
|
||||
mt.Table.MailDb.GetById(0).GetPort(),
|
||||
mt.Table.MailDb.GetById(0).GetUser(),
|
||||
mt.Table.MailDb.GetById(0).GetPasswd(),
|
||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||
)
|
||||
mt.Table.MailDb.Traverse(func(md *mt.MailDb) bool {
|
||||
namestr := constant.MAIL_DB + q5.SafeToString(md.GetGameid())
|
||||
|
||||
f5.GetApp().RegisterOrmDb(
|
||||
namestr,
|
||||
md.GetHost(),
|
||||
md.GetPort(),
|
||||
md.GetUser(),
|
||||
md.GetPasswd(),
|
||||
md.GetDatabase(),
|
||||
)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
namestr,
|
||||
md.GetHost(),
|
||||
md.GetPort(),
|
||||
md.GetUser(),
|
||||
md.GetPasswd(),
|
||||
md.GetDatabase(),
|
||||
1,
|
||||
md.GetMaxOpenConns(),
|
||||
md.GetMaxIdleConns())
|
||||
return true
|
||||
})
|
||||
f5.GetApp().RegisterOrmDb(
|
||||
constant.CONF_DB,
|
||||
mt.Table.ConfDb.GetById(0).GetHost(),
|
||||
@ -79,16 +96,6 @@ func (this *app) registerDataSources() {
|
||||
mt.Table.ConfDb.GetById(0).GetPasswd(),
|
||||
mt.Table.ConfDb.GetById(0).GetDatabase(),
|
||||
)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
constant.MAIL_DB,
|
||||
mt.Table.MailDb.GetById(0).GetHost(),
|
||||
mt.Table.MailDb.GetById(0).GetPort(),
|
||||
mt.Table.MailDb.GetById(0).GetUser(),
|
||||
mt.Table.MailDb.GetById(0).GetPasswd(),
|
||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||
1,
|
||||
mt.Table.MailDb.GetById(0).GetMaxOpenConns(),
|
||||
mt.Table.MailDb.GetById(0).GetMaxIdleConns())
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
constant.GAME_DB,
|
||||
mt.Table.GameDb.GetById(0).GetHost(),
|
||||
|
30
server/adminserver/model/system/giftcode.go
Normal file
30
server/adminserver/model/system/giftcode.go
Normal file
@ -0,0 +1,30 @@
|
||||
package system
|
||||
|
||||
type GiftCode struct {
|
||||
GameId int32 `gorm:"column:gameid" json:"gameid"`
|
||||
GiftCode string `gorm:"column:gift_code" json:"gift_code"`
|
||||
Batch_id int32 `gorm:"column:batch_id" json:"batch_id"`
|
||||
GiftType int32 `gorm:"column:gift_type" json:"gift_type"`
|
||||
Limit int32 `gorm:"column:limit" json:"limit"`
|
||||
Count int32 `gorm:"column:count" json:"count"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
CreateTime int32 `gorm:"column:createtime" json:"-"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
|
||||
}
|
||||
|
||||
func (ac *GiftCode) TableName() string {
|
||||
return "t_gift_code"
|
||||
}
|
||||
|
||||
type GiftType struct {
|
||||
GameId int32 `gorm:"column:gameid" json:"gameid"`
|
||||
GiftType int32 `gorm:"column:gift_type" json:"gift_type"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
Limit int32 `gorm:"column:limit" json:"limit"`
|
||||
CreateTime int32 `gorm:"column:createtime" json:"-"`
|
||||
ModifyTime int32 `gorm:"column:modifytime" json:"-"`
|
||||
}
|
||||
|
||||
func (ac *GiftType) TableName() string {
|
||||
return "t_gift_type"
|
||||
}
|
@ -80,6 +80,7 @@ type MailDb struct {
|
||||
database string
|
||||
max_open_conns int32
|
||||
max_idle_conns int32
|
||||
gameid int32
|
||||
|
||||
_flags1_ uint64
|
||||
_flags2_ uint64
|
||||
@ -87,6 +88,7 @@ type MailDb struct {
|
||||
|
||||
type Config struct {
|
||||
gameapi_url string
|
||||
gamelist string
|
||||
|
||||
_flags1_ uint64
|
||||
_flags2_ uint64
|
||||
@ -451,6 +453,14 @@ func (this *MailDb) HasMaxIdleConns() bool {
|
||||
return (this._flags1_ & (uint64(1) << 7)) > 0
|
||||
}
|
||||
|
||||
func (this *MailDb) GetGameid() int32 {
|
||||
return this.gameid
|
||||
}
|
||||
|
||||
func (this *MailDb) HasGameid() bool {
|
||||
return (this._flags1_ & (uint64(1) << 8)) > 0
|
||||
}
|
||||
|
||||
func (this *Config) GetGameapiUrl() string {
|
||||
return this.gameapi_url
|
||||
}
|
||||
@ -459,6 +469,14 @@ func (this *Config) HasGameapiUrl() bool {
|
||||
return (this._flags1_ & (uint64(1) << 1)) > 0
|
||||
}
|
||||
|
||||
func (this *Config) GetGamelist() string {
|
||||
return this.gamelist
|
||||
}
|
||||
|
||||
func (this *Config) HasGamelist() bool {
|
||||
return (this._flags1_ & (uint64(1) << 2)) > 0
|
||||
}
|
||||
|
||||
func (this *NFTDb) GetHost() string {
|
||||
return this.host
|
||||
}
|
||||
@ -702,10 +720,12 @@ func (this *MailDb) LoadFromKv(kv map[string]interface{}) {
|
||||
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
|
||||
f5.ReadMetaTableField(&this.max_open_conns, "max_open_conns", &this._flags1_, 6, kv)
|
||||
f5.ReadMetaTableField(&this.max_idle_conns, "max_idle_conns", &this._flags1_, 7, kv)
|
||||
f5.ReadMetaTableField(&this.gameid, "gameid", &this._flags1_, 8, kv)
|
||||
}
|
||||
|
||||
func (this *Config) LoadFromKv(kv map[string]interface{}) {
|
||||
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
|
||||
f5.ReadMetaTableField(&this.gamelist, "gamelist", &this._flags1_, 2, kv)
|
||||
}
|
||||
|
||||
func (this *NFTDb) LoadFromKv(kv map[string]interface{}) {
|
||||
|
@ -67,11 +67,13 @@ message MailDb
|
||||
optional string database = 5;
|
||||
optional int32 max_open_conns = 6;
|
||||
optional int32 max_idle_conns = 7;
|
||||
optional int32 gameid = 8;
|
||||
}
|
||||
|
||||
message Config
|
||||
{
|
||||
optional string gameapi_url = 1;
|
||||
optional string gamelist = 2;
|
||||
}
|
||||
|
||||
message NFTDb
|
||||
|
@ -31,6 +31,7 @@ func (this *routerMgr) Init() {
|
||||
this.system.InitWhiteListRouter(priGroup)
|
||||
this.system.InitActiveCodeRouter(priGroup)
|
||||
this.system.InitWorkerToolRouter(priGroup)
|
||||
this.system.InitGiftCodeRouter(priGroup)
|
||||
|
||||
f5.GetSysLog().Info("routerMgr.init")
|
||||
}
|
||||
|
@ -15,4 +15,5 @@ type RouterGroup struct {
|
||||
WhiteListRoute
|
||||
ActiveCodeRoute
|
||||
WorkerToolRoute
|
||||
GiftCodeRoute
|
||||
}
|
||||
|
23
server/adminserver/router/system/giftcode.go
Normal file
23
server/adminserver/router/system/giftcode.go
Normal file
@ -0,0 +1,23 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
v1 "main/api/v1"
|
||||
"main/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type GiftCodeRoute struct {
|
||||
}
|
||||
|
||||
func (this *GiftCodeRoute) InitGiftCodeRouter(priRouter *gin.RouterGroup) {
|
||||
group := priRouter.Group("giftcode")
|
||||
api := v1.ApiGroupApp.SystemApiGroup.GiftCodeApi
|
||||
{
|
||||
group.GET("gen", middleware.Permission("api/v1/giftcode/gen", api.GenCode))
|
||||
group.POST("list", middleware.Permission("api/v1/giftcode/list", api.List))
|
||||
group.GET("download", middleware.Permission("api/v1/giftcode/download", api.DownloadFile))
|
||||
group.POST("typelist", middleware.Permission("api/v1/giftcode/typelist", api.ListType))
|
||||
group.POST("addtype", middleware.Permission("api/v1/giftcode/addtype", api.AddType))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user