Merge branch 'market' of git.kingsome.cn:server/game2006go into market
This commit is contained in:
commit
e77bee79f6
@ -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
|
||||
{
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
@ -144,8 +144,8 @@ func UserAddDiamond(accountId string, diamondNum int32, netId int32, tokenId str
|
||||
if ds.Next() {
|
||||
oldDiamond = q5.ToFloat64(ds.GetByName("diamond"))
|
||||
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() {
|
||||
newDiamond := q5.ToFloat64(ds.GetByName("diamond"))
|
||||
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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -4,9 +4,8 @@ import (
|
||||
"q5"
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/service"
|
||||
"fmt"
|
||||
//"main/mt"
|
||||
//"strings"
|
||||
"jccommon"
|
||||
)
|
||||
|
||||
@ -22,19 +21,20 @@ func (this *recharge) unInit() {
|
||||
|
||||
func (this *recharge) process() {
|
||||
f5.GetGoStyleDb().LoopLoadNew(
|
||||
constant.BCEVENT_DB,
|
||||
"recharge",
|
||||
"t_recharge",
|
||||
constant.BCNFT_DB,
|
||||
"recharge_order",
|
||||
"t_recharge_order",
|
||||
0,
|
||||
func (lastIdx int64, maxIdx int64) (string, []string) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT * FROM t_recharge
|
||||
WHERE idx > %d AND idx <= %d AND status = %d
|
||||
SELECT * FROM t_recharge_order
|
||||
WHERE idx > %d AND idx <= %d AND pay_status = %d AND delivery_status = %d
|
||||
ORDER BY idx LIMIT 1000
|
||||
`,
|
||||
lastIdx,
|
||||
maxIdx,
|
||||
jccommon.RECHARGE_STATUS_PENDING)
|
||||
jccommon.RECHARGE_ORDER_PAY_STATUS_OK,
|
||||
jccommon.RECHARGE_ORDER_DELIVERY_STATUS_PENDING)
|
||||
params := []string{
|
||||
}
|
||||
return sql, params
|
||||
@ -43,40 +43,34 @@ ORDER BY idx LIMIT 1000
|
||||
}
|
||||
|
||||
func (this *recharge) deliverGoods(ds *f5.DataSet) bool {
|
||||
var result = false
|
||||
idx := q5.ToInt64(ds.GetByName("idx"))
|
||||
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"))
|
||||
status := q5.ToInt32(ds.GetByName("stauts"))
|
||||
if status != 0 {
|
||||
result = this.markStatus(idx, jccommon.RECHARGE_STATUS_SENT) == nil
|
||||
return
|
||||
}
|
||||
result = this.markStatus(idx, jccommon.RECHARGE_STATUS_SENT) == nil
|
||||
})
|
||||
return result
|
||||
passportAddress := ds.GetByName("passport_address")
|
||||
diamond := q5.ToInt64(ds.GetByName("diamond"))
|
||||
netId := q5.ToInt32(ds.GetByName("net_id"))
|
||||
accountId := service.GetAccountIdByAddress(passportAddress)
|
||||
if accountId == "" {
|
||||
return true
|
||||
}
|
||||
if this.markOk(idx, accountId) != nil {
|
||||
return true
|
||||
}
|
||||
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
|
||||
f5.GetGoStyleDb().Update(
|
||||
constant.BCEVENT_DB,
|
||||
"t_recharge",
|
||||
constant.BCNFT_DB,
|
||||
"t_recharge_order",
|
||||
[][]string{
|
||||
{"idx", q5.ToString(idx)},
|
||||
},
|
||||
[][]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) {
|
||||
resultErr = err
|
||||
|
@ -105,13 +105,16 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
RECHARGE_ORDER_STATUS_PENDING = 0
|
||||
RECHARGE_ORDER_STATUS_SENT =1
|
||||
RECHARGE_ORDER_PAY_STATUS_PENDING = 0
|
||||
RECHARGE_ORDER_PAY_STATUS_OK = 1
|
||||
|
||||
RECHARGE_ORDER_DELIVERY_STATUS_PENDING =0
|
||||
RECHARGE_ORDER_DELIVERY_STATUS_OK = 1
|
||||
)
|
||||
|
||||
const (
|
||||
RECHARGE_STATUS_PENDING = 0
|
||||
RECHARGE_STATUS_SENT =1
|
||||
RECHARGE_STATUS_SENT = 1
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -84,6 +84,14 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
|
||||
p := new(itemSoldOut)
|
||||
if q5.DecodeJson(returnValues, p) == nil {
|
||||
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
|
||||
f5.GetGoStyleDb().Upsert(
|
||||
constant.BCEVENT_DB,
|
||||
@ -106,6 +114,7 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
|
||||
{"order_id", p.OrderId},
|
||||
{"currency", p.Currency},
|
||||
{"amount", p.Amount},
|
||||
{"status", q5.ToString(status)},
|
||||
{"createtime", createTime},
|
||||
{"modifytime", modifyTime},
|
||||
},
|
||||
@ -128,3 +137,38 @@ func (this *recharge) saveToDb(ds *f5.DataSet) bool {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (this *RechargeApi) Buy(c *gin.Context) {
|
||||
accountId := c.MustGet("open_id").(string)
|
||||
passportAddress := c.MustGet("account_address").(string)
|
||||
reqJson := struct {
|
||||
NetId int32 `json:"net_id"`
|
||||
GoodsId int32 `json:"goods_id"`
|
||||
Num int32 `json:"num"`
|
||||
AccountAddress string `json:"account_address"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
||||
@ -104,6 +104,8 @@ func (this *RechargeApi) Buy(c *gin.Context) {
|
||||
ErrMsg string `json:"errmsg"`
|
||||
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())
|
||||
f5.GetHttpCliMgr().SendGoStyleRequest(
|
||||
url,
|
||||
@ -122,16 +124,17 @@ func (this *RechargeApi) Buy(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if !service.AddRechargeOrder(
|
||||
accountId,
|
||||
orderId,
|
||||
q5.ToString(shortOrderId),
|
||||
reqJson.NetId,
|
||||
reqJson.AccountAddress,
|
||||
passportAddress,
|
||||
currencyMeta.GetName(),
|
||||
currencyMeta.GetAddress(),
|
||||
goodsMeta.GetId(),
|
||||
1,
|
||||
price) {
|
||||
itemNum,
|
||||
price,
|
||||
diamond) {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"main/constant"
|
||||
)
|
||||
|
||||
func AddRechargeOrder(accountId string, orderId string, shortOrderId string,
|
||||
accountAddress string, passportAddress string,
|
||||
currencyAddress string, currencyName string, itemId int32, itemNum int64,
|
||||
price string) bool {
|
||||
func AddRechargeOrder(orderId string, shortOrderId string,
|
||||
netId int32, accountAddress string, passportAddress string,
|
||||
currencyAddress string, currencyName string, itemId int32, itemNum int32,
|
||||
price string, diamond int64) bool {
|
||||
ok := false
|
||||
nowTime := f5.GetApp().GetRealSeconds()
|
||||
f5.GetGoStyleDb().UpsertEx(
|
||||
@ -21,9 +21,9 @@ func AddRechargeOrder(accountId string, orderId string, shortOrderId string,
|
||||
[][]string{
|
||||
},
|
||||
[][]string{
|
||||
{"account_id", accountId},
|
||||
{"order_id", orderId},
|
||||
{"short_order_id", shortOrderId},
|
||||
{"net_id", q5.ToString(netId)},
|
||||
{"account_address", accountAddress},
|
||||
{"passport_address", passportAddress},
|
||||
{"currency_name", currencyName},
|
||||
@ -31,6 +31,7 @@ func AddRechargeOrder(accountId string, orderId string, shortOrderId string,
|
||||
{"item_id", q5.ToString(itemId)},
|
||||
{"item_num", q5.ToString(itemNum)},
|
||||
{"price", price},
|
||||
{"diamond", q5.ToString(diamond)},
|
||||
{"createtime", q5.ToString(nowTime)},
|
||||
{"modifytime", q5.ToString(nowTime)},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user