印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.6 KiB

package blockpay
import (
"fmt"
"server/call"
"server/common"
"server/config"
"server/db"
"server/util"
"sync"
"time"
"github.com/liangdas/mqant/log"
)
var (
withdrawGroup sync.WaitGroup
)
func WithdrawTimer() {
list := []*common.WithdrawOrder{}
// startData := time.Now().AddDate(0, 0, -1).Unix()
db.Mysql().QueryAll(fmt.Sprintf("status = %d and pay_source = %d",
common.StatusROrderWaitting, common.PaySourceBlockPay), "", &common.WithdrawOrder{}, &list)
l := len(list)
if l > 0 {
log.Debug("start scan orders:%v", l)
withdrawGroup.Add(l)
for _, v := range list {
// 提交订单
res, err := db.Mysql().UpdateRes(&common.WithdrawOrder{OrderID: v.OrderID, Status: common.StatusROrderWaitting,
PaySource: common.PaySourceBlockPay},
map[string]interface{}{"status": common.StatusROrderPay})
if err != nil {
log.Error("err:%v", err)
withdrawGroup.Done()
continue
}
if res == 0 {
withdrawGroup.Done()
continue
}
or := v
log.Debug("trying:%v", or.OrderID)
util.Go(func() {
if config.GetBase().Release {
or.APIPayID, err = transferUSDT("", or.PayAccount, or.OrderID, or.Amount/100, 1)
} else {
or.APIPayID, err = transferTRX("", or.PayAccount, or.OrderID, or.Amount/100, 1)
}
success := err == nil
if success {
or.Status = common.StatusROrderFinish
} else {
or.Status = common.StatusROrderFail
}
call.WithdrawCallback(or)
withdrawGroup.Done()
})
}
}
t := config.GetConfig().Pay.WithdrawScanTime
if t <= 0 {
t = 10
}
time.AfterFunc(time.Duration(t)*time.Second, WithdrawTimer)
}