This commit is contained in:
aozhiwei 2024-08-13 09:57:08 +08:00
parent 4710749f3a
commit 63a087da8d

View File

@ -49,18 +49,25 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
} }
func (this *RechargeApi) Buy(c *gin.Context) { func (this *RechargeApi) Buy(c *gin.Context) {
// reqJson := struct {
// NetId int32 `json:"net_id"`
// GoodsId int32 `json:"goods_id"`
// Num int32 `json:"goods_num"`
// AccountAddress string `json:"account_address"`
// }{}
// if err := c.ShouldBindJSON(&reqJson); err != nil {
// f5.RspErr(c, 1, err.Error())
// return
// }
}
func (this *RechargeApi) BuyWithEmail(c *gin.Context) {
}
func (this *RechargeApi) internalBuy(c *gin.Context,
netId int32, goodsId int32, goodsNum int32, accountAddress string) {
passportAddress := c.MustGet("account_address").(string) passportAddress := c.MustGet("account_address").(string)
reqJson := struct { currencyMeta := mt.Table.Currency.Get(netId)
NetId int32 `json:"net_id"`
GoodsId int32 `json:"goods_id"`
Num int32 `json:"goods_num"`
AccountAddress string `json:"account_address"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
f5.RspErr(c, 1, err.Error())
return
}
currencyMeta := mt.Table.Currency.Get(reqJson.NetId)
if currencyMeta == nil { if currencyMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
@ -75,12 +82,12 @@ func (this *RechargeApi) Buy(c *gin.Context) {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
} }
currencyContractMeta := mt.Table.Contract.GetByNetIdName(reqJson.NetId, currencyMeta.GetCurrencyName()) currencyContractMeta := mt.Table.Contract.GetByNetIdName(netId, currencyMeta.GetCurrencyName())
if currencyContractMeta == nil { if currencyContractMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
} }
goodsMeta := mt.Table.Recharge.GetById(q5.ToInt64(reqJson.GoodsId)) goodsMeta := mt.Table.Recharge.GetById(q5.ToInt64(goodsId))
if goodsMeta == nil { if goodsMeta == nil {
f5.RspErr(c, 2, "goods id param error") f5.RspErr(c, 2, "goods id param error")
return return
@ -89,7 +96,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
f5.RspErr(c, 2, "goods id param error") f5.RspErr(c, 2, "goods id param error")
return return
} }
if reqJson.Num <= 0 || reqJson.Num > goodsMeta.GetMaxBuyTimes() { if goodsNum <= 0 || goodsNum > goodsMeta.GetMaxBuyTimes() {
f5.RspErr(c, 2, "num param error") f5.RspErr(c, 2, "num param error")
return return
} }
@ -103,7 +110,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
nowTime, nowTime,
0, 0,
[3]int64{ [3]int64{
q5.ToInt64(reqJson.Num), q5.ToInt64(goodsNum),
q5.ToInt64(goodsMeta.GetId()), q5.ToInt64(goodsMeta.GetId()),
shortOrderId, shortOrderId,
}) })
@ -115,7 +122,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
} }
} }
price := q5.PowInt64(10, currencyMeta.GetCurrencyDecimal()) * q5.ToInt64(goodsMeta.GetPrice()) * price := q5.PowInt64(10, currencyMeta.GetCurrencyDecimal()) * q5.ToInt64(goodsMeta.GetPrice()) *
q5.ToInt64(reqJson.Num) q5.ToInt64(goodsNum)
if price <= 0 || price < q5.ToInt64(goodsMeta.GetPrice()) { if price <= 0 || price < q5.ToInt64(goodsMeta.GetPrice()) {
f5.RspErr(c, 3, "server internal error") f5.RspErr(c, 3, "server internal error")
return return
@ -123,9 +130,9 @@ func (this *RechargeApi) Buy(c *gin.Context) {
params := map[string]string{ params := map[string]string{
"c": "BcService", "c": "BcService",
"a": "recharge", "a": "recharge",
"net_id": q5.ToString(reqJson.NetId), "net_id": q5.ToString(netId),
"order_id": orderId, "order_id": orderId,
"account_address": reqJson.AccountAddress, "account_address": accountAddress,
"passport_address": passportAddress, "passport_address": passportAddress,
"amount": q5.ToString(price), "amount": q5.ToString(price),
"currency_name": currencyContractMeta.GetName(), "currency_name": currencyContractMeta.GetName(),
@ -136,7 +143,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`
Calls []jccommon.ContractCall `json:"calls"` Calls []jccommon.ContractCall `json:"calls"`
}{} }{}
var itemNum int32 = reqJson.Num var itemNum int32 = goodsNum
var diamond int64 = q5.ToInt64(goodsMeta.GetDiamond()) * int64(itemNum) var diamond int64 = q5.ToInt64(goodsMeta.GetDiamond()) * int64(itemNum)
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3SignCluster.RandElement().GetUrl()) url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3SignCluster.RandElement().GetUrl())
f5.GetHttpCliMgr().SendGoStyleRequest( f5.GetHttpCliMgr().SendGoStyleRequest(
@ -158,8 +165,8 @@ func (this *RechargeApi) Buy(c *gin.Context) {
if !service.AddRechargeOrder( if !service.AddRechargeOrder(
orderId, orderId,
q5.ToString(shortOrderId), q5.ToString(shortOrderId),
reqJson.NetId, netId,
reqJson.AccountAddress, accountAddress,
passportAddress, passportAddress,
currencyContractMeta.GetName(), currencyContractMeta.GetName(),
currencyContractMeta.GetAddress(), currencyContractMeta.GetAddress(),
@ -174,9 +181,6 @@ func (this *RechargeApi) Buy(c *gin.Context) {
}) })
} }
func (this *RechargeApi) BuyWithEmail(c *gin.Context) {
}
func (ea *RechargeApi) RechargeQuery(c *gin.Context) { func (ea *RechargeApi) RechargeQuery(c *gin.Context) {
account := strings.ToLower(c.Param("account_address")) account := strings.ToLower(c.Param("account_address"))
netId := q5.ToInt64(c.Param("net_id")) netId := q5.ToInt64(c.Param("net_id"))