Commit 9e52d17a authored by shajiaiming's avatar shajiaiming

修改返回数据内容

parent 034fabaa
...@@ -7,38 +7,29 @@ import ( ...@@ -7,38 +7,29 @@ import (
type Coin struct { type Coin struct {
Model Model
//Id int `gorm:"primary_key"` Id int `json:"primary_key,omitempty"`
Sid string `json:"sid"` Sid string `json:"sid,omitempty"`
Name string `json:"name"` Name string `json:"name,omitempty"`
OptionalName string `json:"optional_name"` OptionalName string `json:"optional_name,omitempty"`
Nickname string `json:"nickname"` Nickname string `json:"nickname,omitempty"`
Icon string `json:"icon"` Icon string `json:"icon,omitempty"`
Introduce string `json:"introduce"` Introduce string `json:"introduce,omitempty"`
Official string `json:"official"` Official string `json:"official,omitempty"`
Paper string `json:"paper"` Paper string `json:"paper,omitempty"`
Exchange int `json:"exchange"` Exchange int `json:"exchange,omitempty"`
Platform string `json:"platform"` Platform string `json:"platform,omitempty"`
Chain string `json:"chain"` Chain string `json:"chain,omitempty"`
Release string `json:"release"` Release string `json:"release,omitempty"`
Price float64 `json:"price"` Price float64 `json:"price,omitempty"`
AreaSearch string `json:"area_search"` AreaSearch string `json:"area_search,omitempty"`
PublishCount float64 `json:"publish_count"` PublishCount float64 `json:"publish_count,omitempty"`
CirculateCount float64 `json:"circulate_count"` CirculateCount float64 `json:"circulate_count,omitempty"`
Decimals int `json:"decimals"` Decimals int `json:"decimals,omitempty"`
Address string `json:"address"` Address string `json:"address,omitempty"`
PlatformId string `json:"platform_id"` PlatformId string `json:"platform_id,omitempty"`
Treaty int `json:"treaty"` Treaty int `json:"treaty,omitempty"`
//Quotation Quotation `json:"quotation,omitempty"`
} }
//type Quotation struct {
// Price float64 `json:"price"`
// Dollar float64 `json:"dollar"`
// Publish_Count float64 `json:"publish_count"`
// Circulate_Count float64 `json:"circulate_count"`
//}
func ExistCoinById(id int) (bool, error) { func ExistCoinById(id int) (bool, error) {
var coin Coin var coin Coin
err := db.Select("id").Where("id = ?", id).First(&coin).Error err := db.Select("id").Where("id = ?", id).First(&coin).Error
......
...@@ -7,16 +7,15 @@ import ( ...@@ -7,16 +7,15 @@ import (
type CoinRecommend struct { type CoinRecommend struct {
Model Model
Id int `json:"id"` Id int `json:"primary_key,omitempty"`
Cid int `json:"cid"`
Recommend int `json:"recommend"` Recommend int `json:"recommend"`
PlatformId int `json:"platform_id"` PlatformId int `json:"platform_id"`
Sort int `json:"sort"` Sort int `json:"sort"`
Type int `json:"type"` Type int `json:"type"`
Chain string `json:"chain"` Chain string `json:"chain"`
//Coin Coin `gorm:"foreignkey:Cid"` Coin Coin `gorm:"foreignkey:Cid"`
Cid int `json:"cid" gorm:"index"` //用于声明这个字段为索引,如果你使用了自动迁移功能则会有所影响,在不使用则无影响
Coin Coin `json:"coin"` //字段,实际是一个嵌套的struct,它利用TagID与Tag模型相互关联,在执行查询的时候,能够达到Article、Tag关联查询的功能
} }
func (c CoinRecommend) TableName() string { func (c CoinRecommend) TableName() string {
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bwallet/pkg/util" "bwallet/pkg/util"
"bwallet/pkg/setting" "bwallet/pkg/setting"
"bwallet/service/coinRecommend_service" "bwallet/service/coinRecommend_service"
"bwallet/service/coin_service"
) )
type AddCoinRecommendForm struct { type AddCoinRecommendForm struct {
...@@ -32,18 +33,30 @@ type EditCoinRecommendForm struct { ...@@ -32,18 +33,30 @@ type EditCoinRecommendForm struct {
} }
func (cr *AddCoinRecommendForm) Valid(v *validation.Validation) { func (cr *AddCoinRecommendForm) Valid(v *validation.Validation) {
coinService := coin_service.Coin{Id: cr.Cid}
exists, _ := coinService.ExistById()
if (!exists) {
v.SetError("Cid", "所推荐币种不存在")
}
coinRecommendService := coinRecommend_service.CoinRecommend{ coinRecommendService := coinRecommend_service.CoinRecommend{
Cid: cr.Cid, Cid: cr.Cid,
PlatformId: cr.PlatformId, PlatformId: cr.PlatformId,
Type: cr.Type, Type: cr.Type,
Chain: cr.Chain, Chain: cr.Chain,
} }
total, _ := coinRecommendService.Count() total, _ := coinRecommendService.Count()
if total > 0 { if total > 0 {
v.SetError("Cid", "推荐币种已经存在") v.SetError("Cid", "推荐币种已经存在")
} }
}
func (cr *EditCoinRecommendForm) Valid(v *validation.Validation) {
coinService := coin_service.Coin{Id: cr.Cid}
exists, _ := coinService.ExistById()
if (!exists) {
v.SetError("Cid", "所推荐币种不存在")
}
} }
func GetCoinRecommend(c *gin.Context) { func GetCoinRecommend(c *gin.Context) {
......
...@@ -97,6 +97,5 @@ func (c *CoinRecommend) getMaps() (map[string]interface{}) { ...@@ -97,6 +97,5 @@ func (c *CoinRecommend) getMaps() (map[string]interface{}) {
maps["chain"] = c.Chain maps["chain"] = c.Chain
} }
return maps 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