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.
294 lines
6.8 KiB
294 lines
6.8 KiB
package handler |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
"server/modules/backend/values" |
|
"server/pb" |
|
"time" |
|
|
|
utils "server/modules/backend/util" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/gogo/protobuf/proto" |
|
"github.com/liangdas/mqant/log" |
|
mqrpc "github.com/liangdas/mqant/rpc" |
|
"github.com/olivere/elastic/v7" |
|
) |
|
|
|
func QueryOrder(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.BlockOrderReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "queryOrder", mqrpc.Param(&pb.BlockPayQueryOrderReq{ |
|
OrderID: req.OrderID, |
|
TxID: req.TxID, |
|
})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.CommonResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if retData.Code != 0 { |
|
a.Code = values.CodeRetry |
|
a.Msg = retData.Msg |
|
return |
|
} |
|
} |
|
|
|
func LocalAddrs(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "queryAddr", mqrpc.Param(&pb.CommonMsg{})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.BlockPayQueryLocalAddrResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
resp := &values.BlockAddrsResp{Addrs: retData.Addrs} |
|
a.Data = resp |
|
} |
|
|
|
func AddAddrs(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddBlockAddrsReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "addAddr", mqrpc.Param(&pb.BlockPayAddLocalAddrReq{ |
|
Address: req.Address, |
|
Private: req.Private, |
|
})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.CommonResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if retData.Code != 0 { |
|
a.Code = int(retData.Code) |
|
a.Msg = retData.Msg |
|
return |
|
} |
|
} |
|
|
|
func RemoveAddrs(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.AddBlockAddrsReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "removeAddr", mqrpc.Param(&pb.BlockPayAddLocalAddrReq{ |
|
Address: req.Address, |
|
})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.CommonResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if retData.Code != 0 { |
|
a.Code = values.CodeRetry |
|
a.Msg = retData.Msg |
|
return |
|
} |
|
} |
|
|
|
func Transfer(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.BlockTransferReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "transfer", mqrpc.Param(&pb.BlockPayTransferReq{ |
|
FromAddr: req.FromAddr, |
|
ToAddr: req.ToAddr, |
|
Type: req.Type, |
|
Amount: req.Amount, |
|
})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.CommonResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if retData.Code != 0 { |
|
a.Code = values.CodeRetry |
|
a.Msg = retData.Msg |
|
return |
|
} |
|
} |
|
|
|
func TransferList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.BlockTransferListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
resp := &values.BlockTransferListResp{List: []common.ESTron{}} |
|
a.Data = resp |
|
su, eu := utils.GetQueryUnix(req.Start, req.End) |
|
if req.Num > 500 { |
|
req.Num = 500 |
|
} |
|
q := elastic.NewBoolQuery() |
|
q.Filter(elastic.NewRangeQuery("Time").Gte(su)) |
|
q.Filter(elastic.NewRangeQuery("Time").Lt(eu)) |
|
if req.Type > 0 { |
|
q.Filter(elastic.NewTermQuery("Type", req.Type)) |
|
} |
|
if req.Status > 0 { |
|
q.Filter(elastic.NewTermQuery("Status", req.Status)) |
|
} |
|
if req.Success != nil { |
|
q.Filter(elastic.NewTermQuery("Success", *req.Success)) |
|
} |
|
db.ES().QueryList(common.ESIndexTron, req.Page-1, req.Num, q, &resp.List, "Time", false) |
|
resp.Count = db.ES().Count(common.ESIndexTron, q) |
|
} |
|
|
|
// 获取玩家钱包的usdt总和,且返回预估回收所需要的trx |
|
func GetPlayerUsdts(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.PlayerWalletScanReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
fee := GetFee(a) |
|
if a.Code != values.CodeOK { |
|
return |
|
} |
|
sql := "" |
|
if req.Down > 0 { |
|
sql = fmt.Sprintf("usdt >= %v", req.Down) |
|
} else { |
|
sql = "usdt > 0" |
|
} |
|
if req.Up > 0 { |
|
sql += fmt.Sprintf(" and usdt <= %v", req.Up) |
|
} |
|
count := db.Mysql().Count(&common.TronData{}, sql) |
|
a.Data = values.PlayerWalletUsdtsResp{Fee: fee * count, TotalAmount: db.Mysql().Sum(&common.TronData{}, sql, "usdt"), Count: count} |
|
} |
|
|
|
// 扫描符合条件的所有玩家的 |
|
func ScanPlayerWallet(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.PlayerWalletScanReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
|
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "scanPlayerWallet", mqrpc.Param(&pb.BlockPayScanPlayerWalletReq{ |
|
Down: req.Down, |
|
Up: req.Up, |
|
})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
retData := new(pb.BlockPayScanPlayerWalletResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if retData.Code != 0 { |
|
a.Code = values.CodeRetry |
|
a.Msg = retData.Msg |
|
return |
|
} |
|
a.Data = values.PlayerWalletScanResp{Success: retData.Success, Fail: retData.Fail} |
|
} |
|
|
|
func GetFee(a *app.Gin) int64 { |
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
ret, err := call.GetCaller().GetApp().Call(to, "blockpay", "getFee", mqrpc.Param(&pb.CommonMsg{})) |
|
if err != "" { |
|
log.Error("err:%e", err) |
|
a.Code = values.CodeParam |
|
return 0 |
|
} |
|
retData := new(pb.BlockPayGetFeeResp) |
|
if err := proto.Unmarshal(ret.([]byte), retData); err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeParam |
|
return 0 |
|
} |
|
if retData.Code != 0 { |
|
a.Code = values.CodeParam |
|
a.Msg = retData.Msg |
|
return 0 |
|
} |
|
return retData.Fee |
|
}
|
|
|