Commit b4ab5e9e authored by shajiaiming's avatar shajiaiming

设备托管手续费优化

parent 646dc158
...@@ -15,6 +15,7 @@ type Fee struct { ...@@ -15,6 +15,7 @@ type Fee struct {
Fees float32 `json:"fees"` Fees float32 `json:"fees"`
TransactionFees float32 `json:"transaction_fees"` TransactionFees float32 `json:"transaction_fees"`
CoinName string `json:"coin_name"` CoinName string `json:"coin_name"`
TransferType uint8 `json:"transfer_type"`
CoinInfo *Coin `gorm:"foreignkey:Cid" json:"coin,omitempty"` CoinInfo *Coin `gorm:"foreignkey:Cid" json:"coin,omitempty"`
} }
...@@ -76,9 +77,10 @@ func GetFees(pageNum, pageSize int, maps interface{}) ([]*Fee, error) { ...@@ -76,9 +77,10 @@ func GetFees(pageNum, pageSize int, maps interface{}) ([]*Fee, error) {
func AddFee(data map[string]interface{}) (error) { func AddFee(data map[string]interface{}) (error) {
fee := Fee{ fee := Fee{
Cid: data["cid"].(int), Cid: data["cid"].(int),
PlatformId: data["platform_id"].(int), PlatformId: data["platform_id"].(int),
CoinName: data["coin_name"].(string), CoinName: data["coin_name"].(string),
TransferType: data["transfer_type"].(uint8),
} }
if err := db.Create(&fee).Error; err != nil { if err := db.Create(&fee).Error; err != nil {
return err return err
......
...@@ -18,24 +18,32 @@ func GetTransactionFee(c *gin.Context) { ...@@ -18,24 +18,32 @@ func GetTransactionFee(c *gin.Context) {
name := c.DefaultQuery("name", "") name := c.DefaultQuery("name", "")
valid.Required(name, "name").Message("币种不能为空") valid.Required(name, "name").Message("币种不能为空")
transfer_type := com.StrTo(c.DefaultQuery("transfer_type", "1")).MustUint8()
if valid.HasErrors() { if valid.HasErrors() {
handler.SendResponse(c, valid.Errors[0], nil) handler.SendResponse(c, valid.Errors[0], nil)
return return
} }
feeService := fee_service.Fee{ feeService := fee_service.Fee{
PlatformId: platform_id, PlatformId: platform_id,
CoinName: name, CoinName: name,
PageNum: util.GetPage(c), TransferType: transfer_type,
PageSize: util.GetLimit(c), PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
} }
total_fee, err_fee := feeService.Count() total_fee, err_fee := feeService.Count()
if err_fee != nil || 0 == total_fee { if err_fee != nil {
handler.SendResponse(c, errno.ErrCountCoin, nil) handler.SendResponse(c, errno.ErrCountCoin, nil)
return return
} }
if 0 == total_fee {
handler.SendResponse(c, errno.ErrCoinNotFound, nil)
return
}
fee, err := feeService.Search() fee, err := feeService.Search()
if err != nil { if err != nil {
handler.SendResponse(c, errno.ErrCountCoin, nil) handler.SendResponse(c, errno.ErrCountCoin, nil)
......
...@@ -37,7 +37,7 @@ func GetTransactionCoins(c *gin.Context) { ...@@ -37,7 +37,7 @@ func GetTransactionCoins(c *gin.Context) {
} }
vals := []string{} vals := []string{}
for _,value := range fees { for _, value := range fees {
if "" == value.CoinName { if "" == value.CoinName {
continue continue
} }
...@@ -61,10 +61,13 @@ func GetTransactionFees(c *gin.Context) { ...@@ -61,10 +61,13 @@ func GetTransactionFees(c *gin.Context) {
} }
} }
transfer_type := com.StrTo(c.DefaultQuery("transfer_type", "1")).MustUint8()
feeService := fee_service.Fee{ feeService := fee_service.Fee{
PlatformId: platform_id, PlatformId: platform_id,
PageNum: util.GetPage(c), TransferType: transfer_type,
PageSize: util.GetLimit(c), PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
} }
total, err := feeService.Count() total, err := feeService.Count()
......
...@@ -121,24 +121,28 @@ func AddRecommendCoin(c *gin.Context) { ...@@ -121,24 +121,28 @@ func AddRecommendCoin(c *gin.Context) {
recommendCoinService.Add() recommendCoinService.Add()
if 2 == recommend_coin.Type { if 2 == recommend_coin.Type {
feeValidate := fee_service.Fee{ for i := 1; i < 3; i++ {
PlatformId: platform_id, feeValidate := fee_service.Fee{
Cid: coin_id, PlatformId: platform_id,
Cid: coin_id,
TransferType: uint8(i),
}
total_fee, err := feeValidate.Count()
if err != nil || total_fee > 0 {
continue
}
coin, _ := coinService.Get()
feeService := fee_service.Fee{
Cid: coin_id,
PlatformId: platform_id,
CoinName: coin.Name,
TransferType: uint8(i),
}
feeService.Add()
} }
total_fee, err := feeValidate.Count()
if err != nil || total_fee > 0 {
continue
}
coin, _ := coinService.Get()
feeService := fee_service.Fee{
Cid: coin_id,
PlatformId: platform_id,
CoinName: coin.Name,
}
feeService.Add()
} }
} }
......
...@@ -12,6 +12,7 @@ type Fee struct { ...@@ -12,6 +12,7 @@ type Fee struct {
Fees float32 Fees float32
TransactionFees float32 TransactionFees float32
CoinName string CoinName string
TransferType uint8
PageNum int PageNum int
PageSize int PageSize int
...@@ -40,9 +41,10 @@ func (c *Fee) GetAll() ([]*models.Fee, error) { ...@@ -40,9 +41,10 @@ func (c *Fee) GetAll() ([]*models.Fee, error) {
func (c *Fee) Add() error { func (c *Fee) Add() error {
fee := map[string]interface{}{ fee := map[string]interface{}{
"cid": c.Cid, "cid": c.Cid,
"platform_id": c.PlatformId, "platform_id": c.PlatformId,
"coin_name": c.CoinName, "coin_name": c.CoinName,
"transfer_type": c.TransferType,
} }
if err := models.AddFee(fee); err != nil { if err := models.AddFee(fee); err != nil {
...@@ -117,5 +119,9 @@ func (c *Fee) getMaps() (map[string]interface{}) { ...@@ -117,5 +119,9 @@ func (c *Fee) getMaps() (map[string]interface{}) {
maps["coin_name"] = c.CoinName maps["coin_name"] = c.CoinName
} }
if c.TransferType != 0 {
maps["transfer_type"] = c.TransferType
}
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