vip
This commit is contained in:
parent
43bd0ac3dd
commit
0112ea1ca5
@ -13,6 +13,7 @@ import (
|
||||
"main/api/v1/recharge"
|
||||
"main/api/v1/shopcart"
|
||||
"main/api/v1/user"
|
||||
"main/api/v1/vip"
|
||||
)
|
||||
|
||||
type ApiGroup struct {
|
||||
@ -28,6 +29,7 @@ type ApiGroup struct {
|
||||
EventApiGroup event.ApiGroup
|
||||
RechargeApiGroup recharge.ApiGroup
|
||||
SwitchApiGroup game_switch.ApiGroup
|
||||
VIPApiGroup vip.ApiGroup
|
||||
}
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
5
server/marketserver/api/v1/vip/enter.go
Normal file
5
server/marketserver/api/v1/vip/enter.go
Normal file
@ -0,0 +1,5 @@
|
||||
package vip
|
||||
|
||||
type ApiGroup struct {
|
||||
VIPApi
|
||||
}
|
137
server/marketserver/api/v1/vip/vip.go
Normal file
137
server/marketserver/api/v1/vip/vip.go
Normal file
@ -0,0 +1,137 @@
|
||||
package vip
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/middleware"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type VIPApi struct {
|
||||
}
|
||||
|
||||
func (this *VIPApi) Info(c *gin.Context) {
|
||||
accountAddress := c.MustGet("account_address").(string)
|
||||
rspObj := struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
ContributionPoint string `json:"contribution_point"`
|
||||
Info struct {
|
||||
BindPassport string `json:"bind_passport_address"`
|
||||
} `json:"info"`
|
||||
}{}
|
||||
|
||||
{
|
||||
var dbErr error
|
||||
sql := "SELECT passport_address FROM t_vip_bind WHERE account_address = ?;"
|
||||
params := []string{
|
||||
accountAddress,
|
||||
}
|
||||
f5.GetGoStyleDb().RawQuery(
|
||||
constant.BCNFT_DB,
|
||||
sql,
|
||||
params,
|
||||
func(err error, ds *f5.DataSet) {
|
||||
dbErr = err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if ds.Next() {
|
||||
rspObj.Info.BindPassport = ds.GetByIndex(0)
|
||||
}
|
||||
})
|
||||
|
||||
if dbErr != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *VIPApi) Bind(c *gin.Context) {
|
||||
accountAddress := c.GetString("account_address")
|
||||
if accountAddress == "" {
|
||||
f5.RspErr(c, 1, "bad request")
|
||||
return
|
||||
}
|
||||
reqObj := struct {
|
||||
Passport_jwt string `json:"passport_jwt"`
|
||||
}{}
|
||||
|
||||
if err := c.ShouldBindJSON(reqObj); err != nil {
|
||||
f5.RspErr(c, 1, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
passportContext := new(gin.Context)
|
||||
passportContext.Request = new(http.Request)
|
||||
passportContext.Request.Header.Set("Authorization", reqObj.Passport_jwt)
|
||||
middleware.JwtAuth(passportContext)
|
||||
passport_addr := passportContext.GetString("account_address")
|
||||
if passport_addr == "" {
|
||||
f5.RspErr(c, 1, "bad request passport")
|
||||
return
|
||||
}
|
||||
|
||||
bound := false
|
||||
{
|
||||
var dbErr error
|
||||
sql := "SELECT idx FROM t_vip_bind WHERE account_address = ? OR passport_address = ?;"
|
||||
params := []string{
|
||||
accountAddress,
|
||||
passport_addr,
|
||||
}
|
||||
f5.GetGoStyleDb().RawQuery(
|
||||
constant.BCNFT_DB,
|
||||
sql,
|
||||
params,
|
||||
func(err error, ds *f5.DataSet) {
|
||||
dbErr = err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if ds.Next() {
|
||||
bound = true
|
||||
}
|
||||
})
|
||||
|
||||
if dbErr != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if bound {
|
||||
f5.RspErr(c, 1, "account or passport bound")
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
var dbErr error
|
||||
f5.GetGoStyleDb().Insert(
|
||||
constant.BCNFT_DB,
|
||||
"t_vip_bind",
|
||||
[][]string{
|
||||
{"account_address", accountAddress},
|
||||
{"passport_address", passport_addr},
|
||||
},
|
||||
func(err error, lastInsertId int64, rowsAffected int64) {
|
||||
if err != nil {
|
||||
dbErr = err
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
if dbErr != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
f5.RspErr(c, 0, "")
|
||||
}
|
@ -15,6 +15,7 @@ import (
|
||||
"main/router/recharge"
|
||||
"main/router/shopcart"
|
||||
"main/router/user"
|
||||
"main/router/vip"
|
||||
)
|
||||
|
||||
type routerMgr struct {
|
||||
@ -30,6 +31,7 @@ type routerMgr struct {
|
||||
event event.RouterGroup
|
||||
recharge recharge.RouterGroup
|
||||
gameswitch game_switch.RouterGroup
|
||||
vip vip.RouterGroup
|
||||
}
|
||||
|
||||
func (this *routerMgr) Init() {
|
||||
@ -48,6 +50,7 @@ func (this *routerMgr) Init() {
|
||||
this.event.EventRouter.InitRouter()
|
||||
this.recharge.RechargeRouter.InitRouter()
|
||||
this.gameswitch.GameSwitchRouter.InitRouter()
|
||||
this.vip.InitRouter()
|
||||
|
||||
f5.GetSysLog().Info("routerMgr.init")
|
||||
|
||||
|
5
server/marketserver/router/vip/enter.go
Normal file
5
server/marketserver/router/vip/enter.go
Normal file
@ -0,0 +1,5 @@
|
||||
package vip
|
||||
|
||||
type RouterGroup struct {
|
||||
VIPRouter
|
||||
}
|
19
server/marketserver/router/vip/vip.go
Normal file
19
server/marketserver/router/vip/vip.go
Normal file
@ -0,0 +1,19 @@
|
||||
package vip
|
||||
|
||||
import (
|
||||
"f5"
|
||||
v1 "main/api/v1"
|
||||
"main/middleware"
|
||||
)
|
||||
|
||||
type VIPRouter struct{}
|
||||
|
||||
func (this *VIPRouter) InitRouter() {
|
||||
api := v1.ApiGroupApp.VIPApiGroup
|
||||
f5.GetApp().GetGinEngine().GET("/api/vip/info",
|
||||
middleware.JwtAuth,
|
||||
api.VIPApi.Info)
|
||||
f5.GetApp().GetGinEngine().POST("/api/vip/bind",
|
||||
middleware.JwtAuth,
|
||||
api.VIPApi.Bind)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user