Merge branch 'market' of git.kingsome.cn:server/game2006go into market

This commit is contained in:
yangduo 2024-08-05 14:21:48 +08:00
commit e77bee79f6
6 changed files with 95 additions and 50 deletions

View File

@ -128,7 +128,7 @@ func AddGameLog(accountId string, logType string, subType string,
}) })
} }
func UserAddDiamond(accountId string, diamondNum int32, netId int32, tokenId string, reason int32) bool { func UserAddDiamond(accountId string, diamondNum int64, netId int32, orderId string) bool {
var oldDiamond float64 var oldDiamond float64
{ {
f5.GetGoStyleDb().OrmSelectOne( f5.GetGoStyleDb().OrmSelectOne(
@ -144,8 +144,8 @@ func UserAddDiamond(accountId string, diamondNum int32, netId int32, tokenId str
if ds.Next() { if ds.Next() {
oldDiamond = q5.ToFloat64(ds.GetByName("diamond")) oldDiamond = q5.ToFloat64(ds.GetByName("diamond"))
AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_DIAMOND_START, AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_DIAMOND_START,
q5.ToString(reason), "",
q5.ToString(netId), tokenId, q5.ToString(oldDiamond), q5.ToString(diamondNum)) q5.ToString(netId), orderId, q5.ToString(oldDiamond), q5.ToString(diamondNum))
} }
}) })
} }
@ -181,8 +181,8 @@ func UserAddDiamond(accountId string, diamondNum int32, netId int32, tokenId str
if ds.Next() { if ds.Next() {
newDiamond := q5.ToFloat64(ds.GetByName("diamond")) newDiamond := q5.ToFloat64(ds.GetByName("diamond"))
AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_DIAMOND_END, AddGameLog(accountId, jccommon.GAME_LOG_TYPE_BACKTASK_USER_ADD_DIAMOND_END,
q5.ToString(reason), "",
q5.ToString(netId), tokenId, q5.ToString(oldDiamond), q5.ToString(newDiamond)) q5.ToString(netId), orderId, q5.ToString(oldDiamond), q5.ToString(newDiamond))
} }
}) })
} }

View File

@ -4,9 +4,8 @@ import (
"q5" "q5"
"f5" "f5"
"main/constant" "main/constant"
"main/service"
"fmt" "fmt"
//"main/mt"
//"strings"
"jccommon" "jccommon"
) )
@ -22,19 +21,20 @@ func (this *recharge) unInit() {
func (this *recharge) process() { func (this *recharge) process() {
f5.GetGoStyleDb().LoopLoadNew( f5.GetGoStyleDb().LoopLoadNew(
constant.BCEVENT_DB, constant.BCNFT_DB,
"recharge", "recharge_order",
"t_recharge", "t_recharge_order",
0, 0,
func (lastIdx int64, maxIdx int64) (string, []string) { func (lastIdx int64, maxIdx int64) (string, []string) {
sql := fmt.Sprintf(` sql := fmt.Sprintf(`
SELECT * FROM t_recharge SELECT * FROM t_recharge_order
WHERE idx > %d AND idx <= %d AND status = %d WHERE idx > %d AND idx <= %d AND pay_status = %d AND delivery_status = %d
ORDER BY idx LIMIT 1000 ORDER BY idx LIMIT 1000
`, `,
lastIdx, lastIdx,
maxIdx, maxIdx,
jccommon.RECHARGE_STATUS_PENDING) jccommon.RECHARGE_ORDER_PAY_STATUS_OK,
jccommon.RECHARGE_ORDER_DELIVERY_STATUS_PENDING)
params := []string{ params := []string{
} }
return sql, params return sql, params
@ -43,40 +43,34 @@ ORDER BY idx LIMIT 1000
} }
func (this *recharge) deliverGoods(ds *f5.DataSet) bool { func (this *recharge) deliverGoods(ds *f5.DataSet) bool {
var result = false
orderId := ds.GetByName("order_id")
f5.GetGoStyleDb().OrmSelectOne(
constant.GAME_DB,
"t_recharge_order",
[][]string{
{"order_id", orderId},
},
func (err error, ds *f5.DataSet) {
if err != nil {
result = false
return
}
idx := q5.ToInt64(ds.GetByName("idx")) idx := q5.ToInt64(ds.GetByName("idx"))
status := q5.ToInt32(ds.GetByName("stauts")) orderId := ds.GetByName("order_id")
if status != 0 { passportAddress := ds.GetByName("passport_address")
result = this.markStatus(idx, jccommon.RECHARGE_STATUS_SENT) == nil diamond := q5.ToInt64(ds.GetByName("diamond"))
return netId := q5.ToInt32(ds.GetByName("net_id"))
accountId := service.GetAccountIdByAddress(passportAddress)
if accountId == "" {
return true
} }
result = this.markStatus(idx, jccommon.RECHARGE_STATUS_SENT) == nil if this.markOk(idx, accountId) != nil {
}) return true
return result }
service.UserAddDiamond(accountId, diamond, netId, orderId)
return true
} }
func (this *recharge) markStatus(idx int64, status int32) error { func (this *recharge) markOk(idx int64, deliveryAccountId string) error {
var resultErr error var resultErr error
f5.GetGoStyleDb().Update( f5.GetGoStyleDb().Update(
constant.BCEVENT_DB, constant.BCNFT_DB,
"t_recharge", "t_recharge_order",
[][]string{ [][]string{
{"idx", q5.ToString(idx)}, {"idx", q5.ToString(idx)},
}, },
[][]string{ [][]string{
{"status", q5.ToString(status)}, {"delivery_status", q5.ToString(jccommon.RECHARGE_ORDER_DELIVERY_STATUS_OK)},
{"delivery_time", q5.ToString(f5.GetApp().GetRealSeconds())},
{"receiver_account_id", deliveryAccountId},
}, },
func (err error, lastInsertId int64, rowsAffected int64) { func (err error, lastInsertId int64, rowsAffected int64) {
resultErr = err resultErr = err

View File

@ -105,8 +105,11 @@ const (
) )
const ( const (
RECHARGE_ORDER_STATUS_PENDING = 0 RECHARGE_ORDER_PAY_STATUS_PENDING = 0
RECHARGE_ORDER_STATUS_SENT =1 RECHARGE_ORDER_PAY_STATUS_OK = 1
RECHARGE_ORDER_DELIVERY_STATUS_PENDING =0
RECHARGE_ORDER_DELIVERY_STATUS_OK = 1
) )
const ( const (

View File

@ -84,6 +84,14 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
p := new(itemSoldOut) p := new(itemSoldOut)
if q5.DecodeJson(returnValues, p) == nil { if q5.DecodeJson(returnValues, p) == nil {
decodeJsonOk = true decodeJsonOk = true
orderExists := false
if this.updateOrderStatus(txhash, p.OrderId, q5.ToInt32(createTime), &orderExists) != nil {
return false
}
status := 0
if orderExists {
status = 1
}
var dbErr error var dbErr error
f5.GetGoStyleDb().Upsert( f5.GetGoStyleDb().Upsert(
constant.BCEVENT_DB, constant.BCEVENT_DB,
@ -106,6 +114,7 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
{"order_id", p.OrderId}, {"order_id", p.OrderId},
{"currency", p.Currency}, {"currency", p.Currency},
{"amount", p.Amount}, {"amount", p.Amount},
{"status", q5.ToString(status)},
{"createtime", createTime}, {"createtime", createTime},
{"modifytime", modifyTime}, {"modifytime", modifyTime},
}, },
@ -128,3 +137,38 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
} }
return true return true
} }
func (this *recharge) updateOrderStatus(txhash string, orderId string, payTime int32, orderExists *bool) error {
*orderExists = false
var resultErr error
f5.GetGoStyleDb().OrmSelectOne(
constant.BCNFT_DB,
"t_recharge_order",
[][]string{
{"order_id", orderId},
},
func (err error, ds *f5.DataSet) {
resultErr = err
if err != nil {
return
}
*orderExists = ds.Next()
})
if resultErr == nil && *orderExists {
f5.GetGoStyleDb().Update(
constant.BCNFT_DB,
"t_recharge_order",
[][]string{
{"order_id", orderId},
},
[][]string{
{"txhash", txhash},
{"pay_status", q5.ToString(1)},
{"pay_time", q5.ToString(payTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
resultErr = err
})
}
return resultErr
}

View File

@ -42,11 +42,11 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
} }
func (this *RechargeApi) Buy(c *gin.Context) { func (this *RechargeApi) Buy(c *gin.Context) {
accountId := c.MustGet("open_id").(string)
passportAddress := c.MustGet("account_address").(string) passportAddress := c.MustGet("account_address").(string)
reqJson := struct { reqJson := struct {
NetId int32 `json:"net_id"` NetId int32 `json:"net_id"`
GoodsId int32 `json:"goods_id"` GoodsId int32 `json:"goods_id"`
Num int32 `json:"num"`
AccountAddress string `json:"account_address"` AccountAddress string `json:"account_address"`
}{} }{}
if err := c.ShouldBindJSON(&reqJson); err != nil { if err := c.ShouldBindJSON(&reqJson); err != nil {
@ -104,6 +104,8 @@ 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 = 1
var diamond int64 = 1
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(
url, url,
@ -122,16 +124,17 @@ func (this *RechargeApi) Buy(c *gin.Context) {
return return
} }
if !service.AddRechargeOrder( if !service.AddRechargeOrder(
accountId,
orderId, orderId,
q5.ToString(shortOrderId), q5.ToString(shortOrderId),
reqJson.NetId,
reqJson.AccountAddress, reqJson.AccountAddress,
passportAddress, passportAddress,
currencyMeta.GetName(), currencyMeta.GetName(),
currencyMeta.GetAddress(), currencyMeta.GetAddress(),
goodsMeta.GetId(), goodsMeta.GetId(),
1, itemNum,
price) { price,
diamond) {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error")
return return
} }

View File

@ -6,10 +6,10 @@ import (
"main/constant" "main/constant"
) )
func AddRechargeOrder(accountId string, orderId string, shortOrderId string, func AddRechargeOrder(orderId string, shortOrderId string,
accountAddress string, passportAddress string, netId int32, accountAddress string, passportAddress string,
currencyAddress string, currencyName string, itemId int32, itemNum int64, currencyAddress string, currencyName string, itemId int32, itemNum int32,
price string) bool { price string, diamond int64) bool {
ok := false ok := false
nowTime := f5.GetApp().GetRealSeconds() nowTime := f5.GetApp().GetRealSeconds()
f5.GetGoStyleDb().UpsertEx( f5.GetGoStyleDb().UpsertEx(
@ -21,9 +21,9 @@ func AddRechargeOrder(accountId string, orderId string, shortOrderId string,
[][]string{ [][]string{
}, },
[][]string{ [][]string{
{"account_id", accountId},
{"order_id", orderId}, {"order_id", orderId},
{"short_order_id", shortOrderId}, {"short_order_id", shortOrderId},
{"net_id", q5.ToString(netId)},
{"account_address", accountAddress}, {"account_address", accountAddress},
{"passport_address", passportAddress}, {"passport_address", passportAddress},
{"currency_name", currencyName}, {"currency_name", currencyName},
@ -31,6 +31,7 @@ func AddRechargeOrder(accountId string, orderId string, shortOrderId string,
{"item_id", q5.ToString(itemId)}, {"item_id", q5.ToString(itemId)},
{"item_num", q5.ToString(itemNum)}, {"item_num", q5.ToString(itemNum)},
{"price", price}, {"price", price},
{"diamond", q5.ToString(diamond)},
{"createtime", q5.ToString(nowTime)}, {"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)}, {"modifytime", q5.ToString(nowTime)},
}, },