230 lines
5.6 KiB
Go
230 lines
5.6 KiB
Go
package ingame
|
|
|
|
import (
|
|
"f5"
|
|
"main/common"
|
|
"main/constant"
|
|
. "main/global"
|
|
"main/mt"
|
|
"marketserver/service"
|
|
"q5"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type InGameApi struct {
|
|
}
|
|
|
|
func (this *InGameApi) HeroList(c *gin.Context) {
|
|
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"`
|
|
HeroRanks []interface{} `json:"hero_ranks"`
|
|
} `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 {
|
|
f5.RspErr(c, 401, "params parse error")
|
|
return
|
|
}
|
|
openId := c.MustGet("open_id").(string)
|
|
accountId := openId
|
|
err, heroList := GetCacheMgr().GetIngameHero(accountId)
|
|
if err != nil {
|
|
f5.RspErr(c, 500, "server internal error")
|
|
return
|
|
}
|
|
|
|
rspObj := struct {
|
|
ErrCode int32 `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
Page common.StreamPagination `json:"page"`
|
|
Rows []interface{} `json:"rows"`
|
|
}{}
|
|
q5.NewSlice(&rspObj.Rows, 0, 10)
|
|
|
|
f5.DataSetStreamPageQuery(
|
|
heroList,
|
|
q5.SafeToInt32(reqJson.PageSize),
|
|
q5.SafeToInt64(reqJson.Cursor),
|
|
func(kv interface{}) bool {
|
|
return true
|
|
},
|
|
func(a interface{}, b interface{}) bool {
|
|
return true
|
|
},
|
|
func(p *f5.StreamPagination) {
|
|
rspObj.Page.FillPage(p)
|
|
},
|
|
func(kv interface{}) {
|
|
q5.AppendSlice(&rspObj.Rows, kv)
|
|
})
|
|
c.JSON(200, rspObj)
|
|
}
|
|
|
|
func (this *InGameApi) HeroMint(c *gin.Context) {
|
|
if service.GameSwitches.CheckSwitch(constant.GAME_SWITCH_HERO_MINT) == 0 {
|
|
f5.RspErr(c, 404, "unavailable request")
|
|
return
|
|
}
|
|
|
|
reqJson := struct {
|
|
NetId interface{} `json:"net_id"`
|
|
To string `json:"to"`
|
|
HeroUniIds []string `json:"hero_uniids"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
f5.RspErr(c, 401, "params parse error")
|
|
return
|
|
}
|
|
if reqJson.To == "" {
|
|
f5.RspErr(c, 1, "to params error")
|
|
return
|
|
}
|
|
if len(reqJson.HeroUniIds) != 1 {
|
|
f5.RspErr(c, 1, "tokens params error")
|
|
return
|
|
}
|
|
uniid := reqJson.HeroUniIds[0]
|
|
accountId := c.MustGet("open_id").(string)
|
|
accountAddress := c.MustGet("account_address").(string)
|
|
f5.GetGoStyleDb().OrmSelectOne(
|
|
constant.GAME_DB,
|
|
"t_hero",
|
|
[][]string{
|
|
{"account_id", accountId},
|
|
{"idx", uniid},
|
|
},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
f5.RspErr(c, 500, "server internal error")
|
|
return
|
|
}
|
|
if ds.Next() {
|
|
params := map[string]string{
|
|
"c": "OutAppMint",
|
|
"a": "mintHero",
|
|
"account_id": accountId,
|
|
"account_address": accountAddress,
|
|
"to_address": reqJson.To,
|
|
"uniid": uniid,
|
|
}
|
|
rspObj := &struct {
|
|
ErrCode interface{} `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
TransId string `json:"trans_id"`
|
|
TransReq interface{} `json:"trans_req"`
|
|
}{}
|
|
f5.GetHttpCliMgr().SendGoStyleRequest(
|
|
mt.Table.Config.GetGameApiUrl()+"/webapp/index.php",
|
|
params,
|
|
func(rsp f5.HttpCliResponse) {
|
|
if rsp.GetErr() != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error1"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
if q5.DecodeJson(rsp.GetRawData(), &rspObj) != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error2"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
c.JSON(200, rspObj)
|
|
})
|
|
} else {
|
|
f5.RspErr(c, 500, "hero not found")
|
|
return
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *InGameApi) newHeroMint(c *gin.Context) {
|
|
if service.GameSwitches.CheckSwitch(constant.GAME_SWITCH_HERO_MINT) == 0 {
|
|
f5.RspErr(c, 404, "unavailable request")
|
|
return
|
|
}
|
|
|
|
reqJson := struct {
|
|
NetId interface{} `json:"net_id"`
|
|
To string `json:"to"`
|
|
HeroUniIds []string `json:"hero_uniids"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
f5.RspErr(c, 401, "params parse error")
|
|
return
|
|
}
|
|
if reqJson.To == "" {
|
|
f5.RspErr(c, 1, "to params error")
|
|
return
|
|
}
|
|
if len(reqJson.HeroUniIds) != 1 {
|
|
f5.RspErr(c, 1, "tokens params error")
|
|
return
|
|
}
|
|
uniid := reqJson.HeroUniIds[0]
|
|
accountId := c.MustGet("open_id").(string)
|
|
accountAddress := c.MustGet("account_address").(string)
|
|
f5.GetGoStyleDb().OrmSelectOne(
|
|
constant.GAME_DB,
|
|
"t_hero",
|
|
[][]string{
|
|
{"account_id", accountId},
|
|
{"idx", uniid},
|
|
},
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
f5.RspErr(c, 500, "server internal error")
|
|
return
|
|
}
|
|
if ds.Next() {
|
|
params := map[string]string{
|
|
"c": "OutAppMint",
|
|
"a": "mintHero",
|
|
"account_id": accountId,
|
|
"account_address": accountAddress,
|
|
"to_address": reqJson.To,
|
|
"uniid": uniid,
|
|
}
|
|
rspObj := &struct {
|
|
ErrCode interface{} `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
TransId string `json:"trans_id"`
|
|
TransReq interface{} `json:"trans_req"`
|
|
}{}
|
|
f5.GetHttpCliMgr().SendGoStyleRequest(
|
|
mt.Table.Config.GetGameApiUrl()+"/webapp/index.php",
|
|
params,
|
|
func(rsp f5.HttpCliResponse) {
|
|
if rsp.GetErr() != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error1"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
if q5.DecodeJson(rsp.GetRawData(), &rspObj) != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error2"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
c.JSON(200, rspObj)
|
|
})
|
|
} else {
|
|
f5.RspErr(c, 500, "hero not found")
|
|
return
|
|
}
|
|
})
|
|
}
|