Commit 4c4e7b60 authored by shajiaiming's avatar shajiaiming

fix

parent 3e8e05a0
...@@ -73,6 +73,14 @@ var ( ...@@ -73,6 +73,14 @@ var (
ErrUpdateCoin = &Errno{Code: 20102, Message: "The coin update error."} ErrUpdateCoin = &Errno{Code: 20102, Message: "The coin update error."}
ErrDeleteCoin = &Errno{Code: 20102, Message: "The coin delete error."} ErrDeleteCoin = &Errno{Code: 20102, Message: "The coin delete error."}
// recommend coin errors
ErrRecommendCoinNotFound = &Errno{Code: 20101, Message: "The recommend coin was not found."}
ErrCountRecommendCoin = &Errno{Code: 20102, Message: "The recommend coins statistic error."}
ErrAddRecommendCoin = &Errno{Code: 20101, Message: "The recommend coin add error."}
ErrUpdateRecommendCoin = &Errno{Code: 20102, Message: "The recommend coin update error."}
ErrDeleteRecommendCoin = &Errno{Code: 20102, Message: "The recommend coin delete error."}
ErrExistRecommendCoin = &Errno{Code: 20103, Message: "The recommend coin already exists."}
// wallet errors // wallet errors
ErrWalletNotFound = &Errno{Code: 20101, Message: "The wallet was not found."} ErrWalletNotFound = &Errno{Code: 20101, Message: "The wallet was not found."}
ErrCountWallet = &Errno{Code: 20102, Message: "The wallets statistic error."} ErrCountWallet = &Errno{Code: 20102, Message: "The wallets statistic error."}
...@@ -93,6 +101,7 @@ var ( ...@@ -93,6 +101,7 @@ var (
ErrAddSupportedCurrency = &Errno{Code: 20101, Message: "The supported currency add error."} ErrAddSupportedCurrency = &Errno{Code: 20101, Message: "The supported currency add error."}
ErrUpdateSupportedCurrency = &Errno{Code: 20102, Message: "The supported currency update error."} ErrUpdateSupportedCurrency = &Errno{Code: 20102, Message: "The supported currency update error."}
ErrDeleteSupportedCurrency = &Errno{Code: 20102, Message: "The supported currency delete error."} ErrDeleteSupportedCurrency = &Errno{Code: 20102, Message: "The supported currency delete error."}
ErrExistSupportedCurrency = &Errno{Code: 20103, Message: "The supported currency already exists."}
// user errors // user errors
ErrUserTokenIncorrect = &Errno{Code: 40001, Message: "The user token was incorrect."} ErrUserTokenIncorrect = &Errno{Code: 40001, Message: "The user token was incorrect."}
......
...@@ -129,11 +129,13 @@ func AddCoin(c *gin.Context) { ...@@ -129,11 +129,13 @@ func AddCoin(c *gin.Context) {
authService := auth_service.Auth{Token: token} authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo() auth, _ := authService.GetUserInfo()
group := auth.Group group := auth.Group
var platform_id int var platform_id int
platform_id = auth.PlatformId platform_id = auth.PlatformId
if ("administrator" == group) { if ("administrator" == group) {
platform_id = coin.PlatformId if coin.PlatformId != 0 {
platform_id = coin.PlatformId
}
} }
coinService := coin_service.Coin{ coinService := coin_service.Coin{
......
...@@ -65,15 +65,32 @@ func AddRecommendCoin(c *gin.Context) { ...@@ -65,15 +65,32 @@ func AddRecommendCoin(c *gin.Context) {
} }
} }
//自定义验证
recommendCoinValidate := recommend_coin_service.RecommendCoin{
PlatformId: recommend_coin.PlatformId,
Cid: recommend_coin.Cid,
}
total, err := recommendCoinValidate.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountRecommendCoin, nil)
return
}
if (total > 0) {
handler.SendResponse(c, errno.ErrExistRecommendCoin, nil)
return
}
token := c.Request.Header.Get("Token") token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token} authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo() auth, _ := authService.GetUserInfo()
group := auth.Group group := auth.Group
var platform_id int var platform_id int
platform_id = auth.PlatformId platform_id = auth.PlatformId
if ("administrator" == group) { if ("administrator" == group) {
platform_id = recommend_coin.PlatformId if recommend_coin.PlatformId != 0 {
platform_id = recommend_coin.PlatformId
}
} }
recommendCoinService := recommend_coin_service.RecommendCoin{ recommendCoinService := recommend_coin_service.RecommendCoin{
......
...@@ -95,15 +95,6 @@ func GetSupportedCurrencies(c *gin.Context) { ...@@ -95,15 +95,6 @@ func GetSupportedCurrencies(c *gin.Context) {
} }
func AddSupportedCurrency(c *gin.Context) { func AddSupportedCurrency(c *gin.Context) {
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
return
}
currency := validate_service.SupportedCurrency{} currency := validate_service.SupportedCurrency{}
c.ShouldBindJSON(&currency) c.ShouldBindJSON(&currency)
...@@ -115,9 +106,37 @@ func AddSupportedCurrency(c *gin.Context) { ...@@ -115,9 +106,37 @@ func AddSupportedCurrency(c *gin.Context) {
} }
} }
currencyService := supported_currency_service.SupportedCurrency{ //自定义验证
supportedCurrencyValidate := supported_currency_service.SupportedCurrency{
PlatformId: currency.PlatformId, PlatformId: currency.PlatformId,
CurrencyId: currency.CurrencyId, CurrencyId: currency.CurrencyId,
}
total, err := supportedCurrencyValidate.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountSupportedCurrency, nil)
return
}
if (total > 0) {
handler.SendResponse(c, errno.ErrExistSupportedCurrency, nil)
return
}
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
var platform_id int
platform_id = auth.PlatformId
if ("administrator" == group) {
if currency.PlatformId != 0 {
platform_id = currency.PlatformId
}
}
currencyService := supported_currency_service.SupportedCurrency{
PlatformId: platform_id,
CurrencyId: currency.CurrencyId,
Sort: currency.Sort, Sort: currency.Sort,
} }
...@@ -143,8 +162,6 @@ func EditSupportedCurrency(c *gin.Context) { ...@@ -143,8 +162,6 @@ func EditSupportedCurrency(c *gin.Context) {
currencyService := supported_currency_service.SupportedCurrency{ currencyService := supported_currency_service.SupportedCurrency{
ID: currency.Id, ID: currency.Id,
PlatformId: currency.PlatformId,
CurrencyId: currency.CurrencyId,
Sort: currency.Sort, Sort: currency.Sort,
} }
......
...@@ -48,9 +48,7 @@ func (c *SupportedCurrency) Add() error { ...@@ -48,9 +48,7 @@ func (c *SupportedCurrency) Add() error {
func (c *SupportedCurrency) Edit() error { func (c *SupportedCurrency) Edit() error {
return models.EditSupportedCurrency(c.ID, map[string]interface{}{ return models.EditSupportedCurrency(c.ID, map[string]interface{}{
"platform_id": c.PlatformId, "sort": c.Sort,
"currency_id": c.CurrencyId,
"sort": c.Sort,
}) })
} }
...@@ -77,6 +75,10 @@ func (c *SupportedCurrency) getMaps() (map[string]interface{}) { ...@@ -77,6 +75,10 @@ func (c *SupportedCurrency) getMaps() (map[string]interface{}) {
maps["platform_id"] = c.PlatformId maps["platform_id"] = c.PlatformId
} }
if c.CurrencyId != 0 {
maps["currency_id"] = c.CurrencyId
}
return maps return maps
} }
......
...@@ -7,6 +7,6 @@ type SupportedCurrency struct { ...@@ -7,6 +7,6 @@ type SupportedCurrency struct {
} }
type EditSupportedCurrency struct { type EditSupportedCurrency struct {
SupportedCurrency Id int `json:"id" validate:"required"`
Id int `json:"id" validate:"required"` Sort int `json:"sort" validate:"required"`
} }
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