Commit a4da67e5 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !35
parents 10e0876e 5346bc7c
...@@ -2,6 +2,7 @@ package models ...@@ -2,6 +2,7 @@ package models
import ( import (
"bwallet/pkg/setting" "bwallet/pkg/setting"
"fmt"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
) )
...@@ -16,6 +17,7 @@ type Chain struct { ...@@ -16,6 +17,7 @@ type Chain struct {
Token string `json:"token"` //基础代币 Token string `json:"token"` //基础代币
Fee float32 `json:"fee"` //手续费(基础代币) Fee float32 `json:"fee"` //手续费(基础代币)
BrowerUrl string `json:"brower_url"` //浏览器链接 BrowerUrl string `json:"brower_url"` //浏览器链接
Icon string `json:"icon"` //图标
Lock int `json:"lock"` //是否允许转币 Lock int `json:"lock"` //是否允许转币
} }
...@@ -26,6 +28,11 @@ type UserChain struct { ...@@ -26,6 +28,11 @@ type UserChain struct {
Platform string `json:"platform"` //平行链名称 Platform string `json:"platform"` //平行链名称
} }
type Explore struct {
BrowerUrl string `json:"brower_url"` //浏览器链接
Icon string `json:"icon"` //图标
}
func (c Chain) TableName() string { func (c Chain) TableName() string {
return setting.DatabaseSetting.Name_Sources + ".coin_platform_withhold" return setting.DatabaseSetting.Name_Sources + ".coin_platform_withhold"
} }
...@@ -94,6 +101,21 @@ func GetUserChains(maps interface{}) ([]*UserChain, error) { ...@@ -94,6 +101,21 @@ func GetUserChains(maps interface{}) ([]*UserChain, error) {
return chains, nil return chains, nil
} }
func GetExplore(platform string) (*Chain, error) {
var explore Chain
err := db.Where("platform = ?", platform).First(&explore).Error
if err != nil {
return nil, err
}
err = db.Model(&explore).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return &explore, nil
}
/** /**
* 通过id获取指定链信息 * 通过id获取指定链信息
* @param id * @param id
...@@ -120,6 +142,7 @@ func GetChain(id int) (*Chain, error) { ...@@ -120,6 +142,7 @@ func GetChain(id int) (*Chain, error) {
* @return * @return
*/ */
func AddChain(data map[string]interface{}) (error) { func AddChain(data map[string]interface{}) (error) {
fmt.Println(data)
chain := Chain{ chain := Chain{
Platform: data["platform"].(string), Platform: data["platform"].(string),
Address: data["address"].(string), Address: data["address"].(string),
...@@ -128,6 +151,7 @@ func AddChain(data map[string]interface{}) (error) { ...@@ -128,6 +151,7 @@ func AddChain(data map[string]interface{}) (error) {
Token: data["token"].(string), Token: data["token"].(string),
Fee: data["fee"].(float32), Fee: data["fee"].(float32),
BrowerUrl: data["brower_url"].(string), BrowerUrl: data["brower_url"].(string),
Icon: data["icon"].(string),
Lock: data["lock"].(int), Lock: data["lock"].(int),
} }
if err := db.Create(&chain).Error; err != nil { if err := db.Create(&chain).Error; err != nil {
......
package app
import (
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/service/chain_service"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
)
func Explore(c *gin.Context) {
valid := validation.Validation{}
platform := c.DefaultQuery("platform", "")
valid.Required(platform, "platform").Message("平台名不能为空")
if valid.HasErrors() {
handler.SendResponse(c, valid.Errors[0], nil)
return
}
chainService := chain_service.Chain{Platform: platform}
explore, err := chainService.Explore()
if err != nil {
handler.SendResponse(c, errno.ErrCoinNotFound, nil)
return
}
handler.SendResponse(c, nil, explore)
return
}
...@@ -117,7 +117,7 @@ func GetUserChains(c *gin.Context) { ...@@ -117,7 +117,7 @@ func GetUserChains(c *gin.Context) {
wallet, err := walletService.Get() wallet, err := walletService.Get()
userChainService = chain_service.Chain{ userChainService = chain_service.Chain{
ID:wallet.ChainId, ID: wallet.ChainId,
} }
} }
...@@ -163,6 +163,7 @@ func AddChain(c *gin.Context) { ...@@ -163,6 +163,7 @@ func AddChain(c *gin.Context) {
Token: chain.Token, Token: chain.Token,
Fee: chain.Fee, Fee: chain.Fee,
BrowerUrl: chain.BrowerUrl, BrowerUrl: chain.BrowerUrl,
Icon: chain.Icon,
Lock: chain.Lock, Lock: chain.Lock,
} }
...@@ -209,6 +210,7 @@ func EditChain(c *gin.Context) { ...@@ -209,6 +210,7 @@ func EditChain(c *gin.Context) {
Token: chain.Token, Token: chain.Token,
Fee: chain.Fee, Fee: chain.Fee,
BrowerUrl: chain.BrowerUrl, BrowerUrl: chain.BrowerUrl,
Icon: chain.Icon,
Lock: chain.Lock, Lock: chain.Lock,
} }
......
...@@ -48,6 +48,7 @@ func InitRouter() *gin.Engine { ...@@ -48,6 +48,7 @@ func InitRouter() *gin.Engine {
client.GET("/live-banners",app.GetLiveBanners) client.GET("/live-banners",app.GetLiveBanners)
client.GET("/fees/recommended",app.GetTransactionGas) client.GET("/fees/recommended",app.GetTransactionGas)
client.GET("/tokenview/explore",app.Explore)
api := r.Group("/api") api := r.Group("/api")
......
package chain_service package chain_service
import "bwallet/models" import (
"bwallet/models"
)
type Chain struct { type Chain struct {
ID int ID int
...@@ -11,12 +13,18 @@ type Chain struct { ...@@ -11,12 +13,18 @@ type Chain struct {
Token string Token string
Fee float32 Fee float32
BrowerUrl string BrowerUrl string
Icon string
Lock int Lock int
PageNum int PageNum int
PageSize int PageSize int
} }
type Explore struct {
BrowerUrl string `json:"brower_url,omitempty"` //浏览器链接
Icon string `json:"icon,omitempty"` //图标
}
func (c *Chain) Get() (*models.Chain, error) { func (c *Chain) Get() (*models.Chain, error) {
chain, err := models.GetChain(c.ID) chain, err := models.GetChain(c.ID)
if err != nil { if err != nil {
...@@ -37,6 +45,19 @@ func (c *Chain) GetAll() ([]*models.Chain, error) { ...@@ -37,6 +45,19 @@ func (c *Chain) GetAll() ([]*models.Chain, error) {
return chains, nil return chains, nil
} }
func (c *Chain) Explore() (*models.Explore, error) {
tmp, err := models.GetExplore(c.Platform)
if err != nil {
return nil, err
}
var explore models.Explore
explore.BrowerUrl = tmp.BrowerUrl
explore.Icon = tmp.Icon
return &explore, nil
}
func (c *Chain) GetUserChain() ([]*models.UserChain, error) { func (c *Chain) GetUserChain() ([]*models.UserChain, error) {
var chains []*models.UserChain var chains []*models.UserChain
...@@ -56,6 +77,7 @@ func (c *Chain) Add() error { ...@@ -56,6 +77,7 @@ func (c *Chain) Add() error {
"exer": c.Exer, "exer": c.Exer,
"token": c.Token, "token": c.Token,
"brower_url": c.BrowerUrl, "brower_url": c.BrowerUrl,
"icon": c.Icon,
"fee": c.Fee, "fee": c.Fee,
"lock": c.Lock, "lock": c.Lock,
} }
...@@ -75,6 +97,7 @@ func (c *Chain) Edit() error { ...@@ -75,6 +97,7 @@ func (c *Chain) Edit() error {
"exer": c.Exer, "exer": c.Exer,
"token": c.Token, "token": c.Token,
"brower_url": c.BrowerUrl, "brower_url": c.BrowerUrl,
"icon": c.Icon,
"fee": c.Fee, "fee": c.Fee,
"lock": c.Lock, "lock": c.Lock,
}) })
......
...@@ -8,6 +8,7 @@ type Chain struct { ...@@ -8,6 +8,7 @@ type Chain struct {
Token string `json:"token" validate:"omitempty"` Token string `json:"token" validate:"omitempty"`
Fee float32 `json:"fee" validate:"omitempty"` Fee float32 `json:"fee" validate:"omitempty"`
BrowerUrl string `json:"brower_url" validate:"omitempty,url"` BrowerUrl string `json:"brower_url" validate:"omitempty,url"`
Icon string `json:"icon" validate:"omitempty,url"`
Lock int `json:"lock" validate:"min=1,max=2"` Lock int `json:"lock" validate:"min=1,max=2"`
} }
......
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