Commit b0650fac authored by shajiaiming's avatar shajiaiming

关系搜索

parent 62790096
......@@ -40,11 +40,21 @@ func GetWalletCoinRelationTotal(maps interface{}) (int, error) {
func GetWalletCoinRelations(pageNum, pageSize int, maps interface{}) ([]*WalletCoinRelation, error) {
var coins []*WalletCoinRelation
conditions := make(map[string]interface{})
conditions["name"] = "ETH"
conditions["sid"] = "ethereum"
conditions["platform"] = "ethereum"
err := db.Preload("Coin", conditions).Debug().Where(maps).Offset(pageNum).Limit(pageSize).Find(&coins).Error
relation_map := make(map[string]interface{})
coin_map := make(map[string]interface{})
for key, value := range maps.(map[string]interface{}) {
if ("platform_id" == key || "coin_id" == key) {
relation_map[key] = value
}
if ("condition" == key) {
for k, v := range value.(map[string]interface{}) {
coin_map[k] = v
}
}
}
err := db.Preload("Coin", coin_map).Where(relation_map).Offset(pageNum).Limit(pageSize).Find(&coins).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
......
......@@ -25,19 +25,38 @@ func GetWalletCoinRelationCoinRelations(c *gin.Context) {
} else {
platform_id = auth.PlatformId
}
name := ""
if arg := c.Query("name"); arg != "" {
name = c.Query("name")
}
platform := ""
if arg := c.Query("platform"); arg != "" {
platform = c.Query("platform")
}
chain := ""
if arg := c.Query("chain"); arg != "" {
chain = c.Query("chain")
}
walletCoinRelateionService := wallet_coin_relation_service.WalletCoinRelation{
PlatformId: platform_id,
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
CoinCondition: struct {
Name string
Chain string
Platform string
}{Name: name, Chain: chain, Platform: platform},
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
}
/*
_, err := walletCoinRelateionService.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil)
return
}
_, err := walletCoinRelateionService.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil)
return
}
*/
coins, err := walletCoinRelateionService.GetAll()
......
......@@ -7,12 +7,18 @@ import (
type WalletCoinRelation struct {
PlatformId int
CoinId int
CoinInfo models.Coin
CoinCondition CoinCondition
PageNum int
PageSize int
}
type CoinCondition struct {
Name string
Chain string
Platform string
}
func (w *WalletCoinRelation) GetAll() ([]*models.Coin, error) {
var wallet_coin_relations []*models.WalletCoinRelation
......@@ -61,6 +67,9 @@ func (c *WalletCoinRelation) Delete() error {
return models.DeleteWalletCoinRelation(c.PlatformId, c.CoinId)
}
type Condition struct {
}
func (c *WalletCoinRelation) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{})
......@@ -72,5 +81,18 @@ func (c *WalletCoinRelation) getMaps() (map[string]interface{}) {
maps["coin_id"] = c.CoinId
}
var condition = make(map[string]interface{})
if c.CoinCondition.Name != "" {
condition["name"] = c.CoinCondition.Name
}
if c.CoinCondition.Chain != "" {
condition["chain"] = c.CoinCondition.Chain
}
if c.CoinCondition.Platform != "" {
condition["platform"] = c.CoinCondition.Platform
}
maps["condition"] = condition
return maps
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment