1
This commit is contained in:
parent
8bef024538
commit
4a39e83922
@ -4,6 +4,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"net/http"
|
||||
"database/sql"
|
||||
"q5"
|
||||
"f5"
|
||||
)
|
||||
@ -134,8 +135,7 @@ func (this *OrderMgr) SetDBIdx(instanceId int32, idx int64) {
|
||||
func (this *OrderMgr) FetchEventOneDB(conf *MtwMysqlConf, conn *q5.Mysql) bool {
|
||||
lastIdx := this.GetDBIdx(conf.GetInstanceId())
|
||||
for true {
|
||||
rows, err := conn.Query("SELECT idx, account_id, orderid, roleid, server_id, " +
|
||||
" channel, poly_sdk_channel, unified_channel, try_count, price, createtime " +
|
||||
rows, err := conn.Query(this.GenSelect() +
|
||||
"FROM `orderinfo` " +
|
||||
"WHERE idx > ? AND sp_pay_result = 1 AND status = 0 " +
|
||||
"LIMIT 0, 1000;",
|
||||
@ -150,35 +150,12 @@ func (this *OrderMgr) FetchEventOneDB(conf *MtwMysqlConf, conn *q5.Mysql) bool {
|
||||
defer rows.Close()
|
||||
hasData := false
|
||||
for rows.Next() {
|
||||
var idx int64
|
||||
var accountId string
|
||||
var orderId string
|
||||
var roleId string
|
||||
var serverId int32
|
||||
var channel int32
|
||||
var polySdkChannel int32
|
||||
var unifiedChannel int32
|
||||
var tryCount int32
|
||||
var price int32
|
||||
var createTime int64
|
||||
hasData = true
|
||||
rows.Scan(&idx, &accountId, &orderId, &roleId, &serverId, &channel,
|
||||
&polySdkChannel, &unifiedChannel, &tryCount, &price, createTime)
|
||||
this.AddOrder(
|
||||
conf.GetInstanceId(),
|
||||
idx,
|
||||
accountId,
|
||||
orderId,
|
||||
roleId,
|
||||
serverId,
|
||||
channel,
|
||||
polySdkChannel,
|
||||
unifiedChannel,
|
||||
tryCount,
|
||||
price,
|
||||
createTime)
|
||||
if idx > lastIdx {
|
||||
lastIdx = idx
|
||||
orderInfo := new(OrderInfo)
|
||||
orderInfo.ScanFromRows(rows)
|
||||
this.AddOrder(conf.GetInstanceId(), orderInfo)
|
||||
if orderInfo.idx > lastIdx {
|
||||
lastIdx = orderInfo.idx
|
||||
}
|
||||
}
|
||||
if !hasData {
|
||||
@ -218,24 +195,12 @@ func (this *OrderMgr) reissueOrder(w* http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
{
|
||||
row := conn.QueryRow("SELECT idx, account_id, orderid, roleid, server_id, " +
|
||||
" channel, poly_sdk_channel, unified_channel, try_count, price, createtime " +
|
||||
row := conn.QueryRow(this.GenSelect() +
|
||||
"FROM `orderinfo` " +
|
||||
"WHERE orderid = '?';",
|
||||
orderId)
|
||||
var idx int64
|
||||
var accountId string
|
||||
var orderId string
|
||||
var roleId string
|
||||
var serverId int32
|
||||
var channel int32
|
||||
var polySdkChannel int32
|
||||
var unifiedChannel int32
|
||||
var tryCount int32
|
||||
var price int32
|
||||
var createTime int64
|
||||
if err := row.Scan(&idx, &accountId, &orderId, &roleId, &serverId, &channel,
|
||||
&polySdkChannel, &unifiedChannel, &tryCount, &price, createTime); err != nil {
|
||||
orderInfo := new(OrderInfo)
|
||||
if err := orderInfo.ScanFromRow(row); err != nil {
|
||||
q5.ResponseErr(w, 3, "订单不存在")
|
||||
return
|
||||
}
|
||||
@ -244,53 +209,58 @@ func (this *OrderMgr) reissueOrder(w* http.ResponseWriter, r *http.Request) {
|
||||
q5.ResponseErr(w, 4, "更新订单状态失败")
|
||||
return
|
||||
}
|
||||
this.AddOrder(
|
||||
dbConf.GetInstanceId(),
|
||||
idx,
|
||||
accountId,
|
||||
orderId,
|
||||
roleId,
|
||||
serverId,
|
||||
channel,
|
||||
polySdkChannel,
|
||||
unifiedChannel,
|
||||
tryCount,
|
||||
price,
|
||||
createTime)
|
||||
this.AddOrder(dbConf.GetInstanceId(), orderInfo)
|
||||
q5.ResponseOk(w)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *OrderMgr) AddOrder(
|
||||
dbInstanceId int32,
|
||||
idx int64,
|
||||
accountId string,
|
||||
orderId string,
|
||||
roleId string,
|
||||
serverId int32,
|
||||
channel int32,
|
||||
polySdkChannel int32,
|
||||
unifiedChannel int32,
|
||||
tryCount int32,
|
||||
price int32,
|
||||
createTime int64) {
|
||||
orderInfo *OrderInfo) {
|
||||
this.orderMutex.Lock()
|
||||
defer this.orderMutex.Unlock()
|
||||
if _, ok := this.orderHash[orderId]; ok {
|
||||
panic("orderId已经存在" + orderId)
|
||||
if _, ok := this.orderHash[orderInfo.orderId]; ok {
|
||||
panic("orderId已经存在" + orderInfo.orderId)
|
||||
}
|
||||
orderInfo := new(OrderInfo)
|
||||
orderInfo.dbInstanceId = dbInstanceId
|
||||
orderInfo.idx = idx
|
||||
orderInfo.accountId = accountId
|
||||
orderInfo.roleId = roleId
|
||||
orderInfo.serverId = serverId
|
||||
orderInfo.channel = channel
|
||||
orderInfo.polySdkChannel = polySdkChannel
|
||||
orderInfo.unifiedChannel = unifiedChannel
|
||||
orderInfo.tryCount = tryCount
|
||||
orderInfo.price = price
|
||||
orderInfo.createTime = createTime
|
||||
this.orderList = append(this.orderList, orderInfo)
|
||||
this.orderHash[orderId] = orderInfo
|
||||
this.orderHash[orderInfo.orderId] = orderInfo
|
||||
}
|
||||
|
||||
func (this *OrderMgr) GenSelect() string {
|
||||
selectSql := "SELECT idx, account_id, orderid, roleid, server_id, " +
|
||||
"channel, poly_sdk_channel, unified_channel, try_count, price, createtime "
|
||||
return selectSql
|
||||
}
|
||||
|
||||
func (this *OrderInfo) ScanFromRows(rows *sql.Rows) (error) {
|
||||
err := rows.Scan(
|
||||
&this.idx,
|
||||
&this.accountId,
|
||||
&this.orderId,
|
||||
&this.roleId,
|
||||
&this.serverId,
|
||||
&this.channel,
|
||||
&this.polySdkChannel,
|
||||
&this.unifiedChannel,
|
||||
&this.tryCount,
|
||||
&this.price,
|
||||
&this.createTime)
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *OrderInfo) ScanFromRow(row *sql.Row) (error) {
|
||||
err := row.Scan(
|
||||
&this.idx,
|
||||
&this.accountId,
|
||||
&this.orderId,
|
||||
&this.roleId,
|
||||
&this.serverId,
|
||||
&this.channel,
|
||||
&this.polySdkChannel,
|
||||
&this.unifiedChannel,
|
||||
&this.tryCount,
|
||||
&this.price,
|
||||
&this.createTime)
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user