This commit is contained in:
yangduo 2024-07-31 16:56:10 +08:00
parent 50eac95422
commit 15bc87fc5d
8 changed files with 180 additions and 135 deletions

View File

@ -9,6 +9,7 @@ import (
"main/api/v1/ingame" "main/api/v1/ingame"
"main/api/v1/market" "main/api/v1/market"
"main/api/v1/nft" "main/api/v1/nft"
"main/api/v1/recharge"
"main/api/v1/shopcart" "main/api/v1/shopcart"
"main/api/v1/user" "main/api/v1/user"
) )
@ -24,6 +25,7 @@ type ApiGroup struct {
UserApiGroup user.ApiGroup UserApiGroup user.ApiGroup
ActivityApiGroup activity.ApiGroup ActivityApiGroup activity.ApiGroup
EventApiGroup event.ApiGroup EventApiGroup event.ApiGroup
RechargeApiGroup recharge.ApiGroup
} }
var ApiGroupApp = new(ApiGroup) var ApiGroupApp = new(ApiGroup)

View File

@ -196,135 +196,3 @@ func (ea *EventApi) ActivityQuery(c *gin.Context) {
} }
c.JSON(200, rspObj) c.JSON(200, rspObj)
} }
func (ea *EventApi) RechargeList(c *gin.Context) {
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Rows []interface{} `json:"rows"`
}{}
mt.Table.Recharge.RawMetaTable.Traverse(func(tb *mt.Recharge) bool {
tmpmap := map[string]interface{}{}
tmpmap["id"] = tb.GetId()
tmpmap["recharge_cost_num"] = tb.GetRechargeCostNum()
tmpmap["recharge_icon"] = tb.GetRechargeIcon()
tmpmap["recharge_item"] = tb.GetRechargeItem()
tmpmap["recharge_type"] = tb.GetRechargeType()
tmpmap["recharge_item_num"] = tb.GetRechargeItemNum()
rspObj.Rows = append(rspObj.Rows, tmpmap)
return true
})
c.JSON(200, rspObj)
}
func (ea *EventApi) RechargeQuery(c *gin.Context) {
account := strings.ToLower(c.Param("account_address"))
reqJson := struct {
PageSize interface{} `json:"page_size"`
Cursor interface{} `json:"cursor"`
Search struct {
Name string `json:"name"`
} `json:"search"`
Filter struct {
ItemIds []interface{} `json:"item_ids"`
} `json:"filter"`
Sort struct {
Fields []struct {
Name string `json:"name"`
Type interface{} `json:"type"`
} `json:"fields"`
} `json:"sort"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
c.JSON(http.StatusOK, gin.H{
"errcode": 1,
"errmsg": err.Error(),
})
return
}
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
cursor := q5.SafeToInt64(reqJson.Cursor)
sql := fmt.Sprintf(`
SELECT * FROM t_recharge
WHERE idx > %d AND buyer = ?`,
cursor)
params := []string{account}
subFilters := []f5.DbQueryFilter{}
{
itemIds := map[int32]int32{}
if reqJson.Search.Name != "" {
mt.Table.Item.Search(reqJson.Search.Name, itemIds)
}
for _, val := range reqJson.Filter.ItemIds {
itemId := q5.SafeToInt32(val)
itemIds[itemId] = 1
}
if len(itemIds) > 0 {
inSub := `item_id IN (`
i := 0
for key, _ := range itemIds {
if i == 0 {
inSub += q5.ToString(key)
} else {
inSub += "," + q5.ToString(key)
}
i += 1
}
inSub += ")"
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
}
}
orderBy := " ORDER BY createtime DESC "
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Page common.StreamPagination `json:"page"`
Rows []struct {
TxHash string `json:"txhash"`
NetID int64 `json:"net_id"`
ContractAddress string `json:"contact_address"`
Passport string `json:"passport"`
OrderID string `json:"order_id"`
Currency string `json:"currency"`
Amount string `json:"amount"`
Status int32 `json:"status"`
Date int32 `json:"date"`
} `json:"rows"`
}{}
q5.NewSlice(&rspObj.Rows, 0, 10)
f5.GetGoStyleDb().StreamPageQuery(
constant.BCEVENT_DB,
pageSize,
cursor,
sql,
params,
f5.GetDbFilter().Comp(subFilters...),
orderBy,
func(err error, pagination *f5.StreamPagination) {
rspObj.Page.FillPage(pagination)
},
func(ds *f5.DataSet) {
p := q5.NewSliceElement(&rspObj.Rows)
p.TxHash = ds.GetByName("txhash")
p.NetID = q5.SafeToInt64(ds.GetByName("net_id"))
p.ContractAddress = ds.GetByName("contact_address")
p.Passport = ds.GetByName("passport")
p.OrderID = ds.GetByName("order_id")
p.Currency = ds.GetByName("currency")
p.Amount = ds.GetByName("amount")
p.Status = q5.SafeToInt32(ds.GetByName("status"))
p.Date = q5.SafeToInt32(ds.GetByName("date"))
})
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,5 @@
package recharge
type ApiGroup struct {
RechargeApi
}

View File

@ -0,0 +1,150 @@
package recharge
import (
"f5"
"fmt"
"main/common"
"main/constant"
"mt"
"net/http"
"q5"
"strings"
"github.com/gin-gonic/gin"
)
type RechargeApi struct {
}
func (ea *RechargeApi) RechargeList(c *gin.Context) {
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Rows []interface{} `json:"rows"`
}{}
mt.Table.Recharge.RawMetaTable.Traverse(func(tb *mt.Recharge) bool {
tmpmap := map[string]interface{}{}
tmpmap["id"] = tb.GetId()
tmpmap["recharge_cost_num"] = tb.GetRechargeCostNum()
tmpmap["recharge_icon"] = tb.GetRechargeIcon()
tmpmap["recharge_item"] = tb.GetRechargeItem()
tmpmap["recharge_type"] = tb.GetRechargeType()
tmpmap["recharge_item_num"] = tb.GetRechargeItemNum()
rspObj.Rows = append(rspObj.Rows, tmpmap)
return true
})
c.JSON(200, rspObj)
}
func (ea *RechargeApi) RechargeQuery(c *gin.Context) {
account := strings.ToLower(c.Param("account_address"))
reqJson := struct {
PageSize interface{} `json:"page_size"`
Cursor interface{} `json:"cursor"`
Search struct {
Name string `json:"name"`
} `json:"search"`
Filter struct {
ItemIds []interface{} `json:"item_ids"`
} `json:"filter"`
Sort struct {
Fields []struct {
Name string `json:"name"`
Type interface{} `json:"type"`
} `json:"fields"`
} `json:"sort"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
c.JSON(http.StatusOK, gin.H{
"errcode": 1,
"errmsg": err.Error(),
})
return
}
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
cursor := q5.SafeToInt64(reqJson.Cursor)
sql := fmt.Sprintf(`
SELECT * FROM t_recharge
WHERE idx > %d AND buyer = ?`,
cursor)
params := []string{account}
subFilters := []f5.DbQueryFilter{}
{
itemIds := map[int32]int32{}
if reqJson.Search.Name != "" {
mt.Table.Item.Search(reqJson.Search.Name, itemIds)
}
for _, val := range reqJson.Filter.ItemIds {
itemId := q5.SafeToInt32(val)
itemIds[itemId] = 1
}
if len(itemIds) > 0 {
inSub := `item_id IN (`
i := 0
for key, _ := range itemIds {
if i == 0 {
inSub += q5.ToString(key)
} else {
inSub += "," + q5.ToString(key)
}
i += 1
}
inSub += ")"
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
}
}
orderBy := " ORDER BY createtime DESC "
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Page common.StreamPagination `json:"page"`
Rows []struct {
TxHash string `json:"txhash"`
NetID int64 `json:"net_id"`
ContractAddress string `json:"contact_address"`
Passport string `json:"passport"`
OrderID string `json:"order_id"`
Currency string `json:"currency"`
Amount string `json:"amount"`
Status int32 `json:"status"`
Date int32 `json:"date"`
} `json:"rows"`
}{}
q5.NewSlice(&rspObj.Rows, 0, 10)
f5.GetGoStyleDb().StreamPageQuery(
constant.BCEVENT_DB,
pageSize,
cursor,
sql,
params,
f5.GetDbFilter().Comp(subFilters...),
orderBy,
func(err error, pagination *f5.StreamPagination) {
rspObj.Page.FillPage(pagination)
},
func(ds *f5.DataSet) {
p := q5.NewSliceElement(&rspObj.Rows)
p.TxHash = ds.GetByName("txhash")
p.NetID = q5.SafeToInt64(ds.GetByName("net_id"))
p.ContractAddress = ds.GetByName("contact_address")
p.Passport = ds.GetByName("passport")
p.OrderID = ds.GetByName("order_id")
p.Currency = ds.GetByName("currency")
p.Amount = ds.GetByName("amount")
p.Status = q5.SafeToInt32(ds.GetByName("status"))
p.Date = q5.SafeToInt32(ds.GetByName("date"))
})
c.JSON(200, rspObj)
}

View File

@ -11,6 +11,4 @@ func (er *EventRouter) InitRouter() {
api := v1.ApiGroupApp.EventApiGroup api := v1.ApiGroupApp.EventApiGroup
f5.GetApp().GetGinEngine().GET("/api/chain/txhash/:net_id/:txhash", api.EventApi.TxQuery) f5.GetApp().GetGinEngine().GET("/api/chain/txhash/:net_id/:txhash", api.EventApi.TxQuery)
f5.GetApp().GetGinEngine().POST("/api/chain/event/activity/:account_address", api.EventApi.ActivityQuery) f5.GetApp().GetGinEngine().POST("/api/chain/event/activity/:account_address", api.EventApi.ActivityQuery)
f5.GetApp().GetGinEngine().GET("/api/chain/event/recharge/:account_address", api.EventApi.RechargeQuery)
f5.GetApp().GetGinEngine().GET("/api/chain/event/rechargelist", api.EventApi.RechargeList)
} }

View File

@ -0,0 +1,5 @@
package recharge
type RouterGroup struct {
RechargeRouter
}

View File

@ -0,0 +1,14 @@
package recharge
import (
"f5"
v1 "main/api/v1"
)
type RechargeRouter struct{}
func (er *RechargeRouter) InitRouter() {
api := v1.ApiGroupApp.RechargeApiGroup
f5.GetApp().GetGinEngine().GET("/api/recharge/history/:account_address", api.RechargeApi.RechargeQuery)
f5.GetApp().GetGinEngine().GET("/api/recharge/list", api.RechargeApi.RechargeList)
}

View File

@ -5,14 +5,15 @@ import (
"main/middleware" "main/middleware"
"main/router/activity" "main/router/activity"
"main/router/asset" "main/router/asset"
"main/router/event"
"main/router/gold_bullion" "main/router/gold_bullion"
"main/router/hero" "main/router/hero"
"main/router/ingame" "main/router/ingame"
"main/router/market" "main/router/market"
"main/router/nft" "main/router/nft"
"main/router/recharge"
"main/router/shopcart" "main/router/shopcart"
"main/router/user" "main/router/user"
"marketserver/router/event"
) )
type routerMgr struct { type routerMgr struct {
@ -26,6 +27,7 @@ type routerMgr struct {
user user.RouterGroup user user.RouterGroup
activity activity.RouterGroup activity activity.RouterGroup
event event.RouterGroup event event.RouterGroup
recharge recharge.RouterGroup
} }
func (this *routerMgr) Init() { func (this *routerMgr) Init() {
@ -40,6 +42,7 @@ func (this *routerMgr) Init() {
this.user.UserRouter.InitRouter() this.user.UserRouter.InitRouter()
this.activity.StackingRouter.InitRouter() this.activity.StackingRouter.InitRouter()
this.event.EventRouter.InitRouter() this.event.EventRouter.InitRouter()
this.recharge.RechargeRouter.InitRouter()
f5.GetSysLog().Info("routerMgr.init") f5.GetSysLog().Info("routerMgr.init")