diff --git a/server/marketserver/api/v1/enter.go b/server/marketserver/api/v1/enter.go index 272c7207..97206f5e 100644 --- a/server/marketserver/api/v1/enter.go +++ b/server/marketserver/api/v1/enter.go @@ -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) diff --git a/server/marketserver/api/v1/vip/enter.go b/server/marketserver/api/v1/vip/enter.go new file mode 100644 index 00000000..e0a26293 --- /dev/null +++ b/server/marketserver/api/v1/vip/enter.go @@ -0,0 +1,5 @@ +package vip + +type ApiGroup struct { + VIPApi +} diff --git a/server/marketserver/api/v1/vip/vip.go b/server/marketserver/api/v1/vip/vip.go new file mode 100644 index 00000000..d5a5689c --- /dev/null +++ b/server/marketserver/api/v1/vip/vip.go @@ -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, "") +} diff --git a/server/marketserver/router/routermgr.go b/server/marketserver/router/routermgr.go index 61ee28cb..6f9fba28 100644 --- a/server/marketserver/router/routermgr.go +++ b/server/marketserver/router/routermgr.go @@ -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") diff --git a/server/marketserver/router/vip/enter.go b/server/marketserver/router/vip/enter.go new file mode 100644 index 00000000..022844dd --- /dev/null +++ b/server/marketserver/router/vip/enter.go @@ -0,0 +1,5 @@ +package vip + +type RouterGroup struct { + VIPRouter +} diff --git a/server/marketserver/router/vip/vip.go b/server/marketserver/router/vip/vip.go new file mode 100644 index 00000000..9024978e --- /dev/null +++ b/server/marketserver/router/vip/vip.go @@ -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) +}