2024-08-20 17:48:57 +08:00

204 lines
4.7 KiB
Go

package activity
import (
"f5"
"fmt"
"jccommon"
"main/constant"
"main/mt"
"q5"
"strings"
"github.com/gin-gonic/gin"
)
type StackingApi struct {
}
func (this *StackingApi) ExpectedDaily(c *gin.Context) {
accountAddress := strings.ToLower(c.Param("account_address"))
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
ContributionPoint string `json:"contribution_point"`
}{}
nowTime := f5.GetApp().GetRealSeconds()
{
sql := `
SELECT * FROM t_nft WHERE
token_type <> ? AND last_lock_address = ? AND last_lock_time <= ? AND owner_address IN (
`
params := []string{
q5.ToString(jccommon.NFT_TYPE_GOLD_BULLION),
accountAddress,
q5.ToString(nowTime),
}
{
lockMetas := []*mt.Contract{}
mt.Table.Contract.Traverse(func(ele *mt.Contract) bool {
if ele.GetName() == jccommon.CONTRACT_NAME_NFTLock {
q5.AppendSlice(&lockMetas, ele)
}
return true
})
if len(lockMetas) <= 0 {
c.JSON(200, rspObj)
return
}
inited := false
for _, lockMeta := range lockMetas {
if !inited {
inited = true
sql += "?"
} else {
sql += ",?"
}
q5.AppendSlice(&params, lockMeta.GetAddress())
}
sql += ")"
}
f5.GetGoStyleDb().RawQuery(
constant.BCNFT_DB,
sql,
params,
func(err error, ds *f5.DataSet) {
if err != nil {
c.JSON(200, rspObj)
return
}
nfts := []*jccommon.NftStacking{}
for ds.Next() {
p := new(jccommon.NftStacking)
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
p.ContractAddress = ds.GetByName("contract_address")
p.TokenType = q5.ToInt32(ds.GetByName("token_type"))
p.TokenId = ds.GetByName("token_id")
p.ItemId = q5.ToInt32(ds.GetByName("item_id"))
p.Quality = q5.ToInt32(ds.GetByName("quality"))
q5.AppendSlice(&nfts, p)
}
rspObj.ContributionPoint = fmt.Sprintf("%.2f", (jccommon.CalcContributionScore(nfts)))
c.JSON(200, rspObj)
})
}
}
func (sa *StackingApi) ContributionQuery(c *gin.Context) {
accountAddress := strings.ToLower(c.Param("account_address"))
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Rows []struct {
Date int32 `json:"date"`
ContributionPoint string `json:"contribution_point"`
}
}{}
{
sql := `SELECT * FROM t_staking_daily_settlement WHERE account_address = ? ORDER BY settle_date DESC`
params := []string{
accountAddress,
}
f5.GetGoStyleDb().RawQuery(
constant.BCNFT_DB,
sql,
params,
func(err error, ds *f5.DataSet) {
if err != nil {
c.JSON(200, rspObj)
return
}
obj := struct {
Date int32 `json:"date"`
ContributionPoint string `json:"contribution_point"`
}{}
for ds.Next() {
contributionPoint := q5.ToFloat64(ds.GetByName("contribution"))
if contributionPoint > 0.00001 {
obj.Date = q5.SafeToInt32(ds.GetByName("settle_date"))
obj.ContributionPoint = ds.GetByName("contribution")
rspObj.Rows = append(rspObj.Rows, obj)
}
}
})
}
c.JSON(200, rspObj)
}
func (sa *StackingApi) DiamondRecordQuery(c *gin.Context) {
accountAddress := strings.ToLower(c.Param("account_address"))
type Record struct {
Date int32 `json:"date"`
Amount string `json:"amount"`
Type int32 `json:"type"`
From string `json:"from"`
}
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Rows []*Record `json:"rows"`
}{}
{
sql := `SELECT * FROM t_diamond_consume_product WHERE idx > 0 AND (account_id = ? OR passport_address = ?)`
params := []string{
accountAddress,
accountAddress,
}
f5.GetGoStyleDb().RawQuery(
constant.GAME_DB,
sql,
params,
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
for ds.Next() {
obj := new(Record)
obj.Date = q5.SafeToInt32(ds.GetByName("createtime"))
obj.Amount = ds.GetByName("amount")
obj.Type = 1
obj.From = accountAddress
rspObj.Rows = append(rspObj.Rows, obj)
}
})
}
{
sql := `SELECT pay_time, diamond + present_diamond, account_address FROM t_recharge_order WHERE idx > 0 AND passport_address = ? AND pay_status = 1`
params := []string{
accountAddress,
}
f5.GetGoStyleDb().RawQuery(
constant.BCNFT_DB,
sql,
params,
func(err error, ds *f5.DataSet) {
if err != nil {
return
}
for ds.Next() {
obj := new(Record)
obj.Date = q5.SafeToInt32(ds.GetByName("pay_time"))
obj.Amount = ds.GetByIndex(1)
obj.From = ds.GetByIndex(2)
obj.Type = 0
rspObj.Rows = append(rspObj.Rows, obj)
}
})
}
q5.Sort(rspObj.Rows, func(a *Record, b *Record) bool {
return a.Date > b.Date
})
c.JSON(200, rspObj)
}