Commit 8125825e authored by shajiaiming's avatar shajiaiming

fix

parent cbe425aa
...@@ -40,7 +40,7 @@ func CheckToken(token string) (bool, error) { ...@@ -40,7 +40,7 @@ func CheckToken(token string) (bool, error) {
return true, nil return true, nil
} }
func GetUserInfo (token string) (*Auth, error){ func GetUserInfo(token string) (*Auth, error) {
var auth Auth var auth Auth
if err := db.Where("access_token = ?", token).First(&auth).Error; err != nil { if err := db.Where("access_token = ?", token).First(&auth).Error; err != nil {
return nil, err return nil, err
......
...@@ -77,7 +77,7 @@ func GetCoinTotal(maps interface{}) (int, error) { ...@@ -77,7 +77,7 @@ func GetCoinTotal(maps interface{}) (int, error) {
func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) { func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) {
var coins []*Coin var coins []*Coin
err := db.Where(maps).Offset(pageNum).Limit(pageSize).Find(&coins).Error err := db.Debug().Where(maps).Offset(pageNum).Limit(pageSize).Find(&coins).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
...@@ -92,7 +92,7 @@ func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) { ...@@ -92,7 +92,7 @@ func GetCoins(pageNum, pageSize int, maps interface{}) ([]*Coin, error) {
*/ */
func GetCoin(id int) (*Coin, error) { func GetCoin(id int) (*Coin, error) {
var coin Coin var coin Coin
err := db.Table("coin").Where("id = ?", id).First(&coin).Error err := db.Where("id = ?", id).First(&coin).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
......
...@@ -19,7 +19,7 @@ const ( ...@@ -19,7 +19,7 @@ const (
ERROR_NOT_EXIST_ARTICLE = 10011 ERROR_NOT_EXIST_ARTICLE = 10011
ERROR_CHECK_EXIST_ARTICLE_FAIL = 10012 ERROR_CHECK_EXIST_ARTICLE_FAIL = 10012
ERROR_ADD_ARTICLE_FAIL = 10013 ERROR_ADD_ARTICLE_FAIL = 10013
ERROR_DELETE_ARTICLE_FAIL = 10014 ERROR_DELETE_COIN_FAIL = 10014
ERROR_EDIT_ARTICLE_FAIL = 10015 ERROR_EDIT_ARTICLE_FAIL = 10015
ERROR_COUNT_ARTICLE_FAIL = 10016 ERROR_COUNT_ARTICLE_FAIL = 10016
ERROR_GET_ARTICLES_FAIL = 10017 ERROR_GET_ARTICLES_FAIL = 10017
......
...@@ -14,15 +14,15 @@ var MsgFlags = map[int]string{ ...@@ -14,15 +14,15 @@ var MsgFlags = map[int]string{
ERROR_DELETE_TAG_FAIL: "删除标签失败", ERROR_DELETE_TAG_FAIL: "删除标签失败",
ERROR_EXPORT_TAG_FAIL: "导出标签失败", ERROR_EXPORT_TAG_FAIL: "导出标签失败",
ERROR_IMPORT_TAG_FAIL: "导入标签失败", ERROR_IMPORT_TAG_FAIL: "导入标签失败",
ERROR_NOT_EXIST_ARTICLE: "该文章不存在", ERROR_NOT_EXIST_ARTICLE: "该币种不存在",
ERROR_ADD_ARTICLE_FAIL: "新增文章失败", ERROR_ADD_ARTICLE_FAIL: "新增币种失败",
ERROR_DELETE_ARTICLE_FAIL: "删除文章失败", ERROR_DELETE_COIN_FAIL: "删除币种失败",
ERROR_CHECK_EXIST_ARTICLE_FAIL: "检查文章是否存在失败", ERROR_CHECK_EXIST_ARTICLE_FAIL: "检查币种是否存在失败",
ERROR_EDIT_ARTICLE_FAIL: "修改文章失败", ERROR_EDIT_ARTICLE_FAIL: "修改币种失败",
ERROR_COUNT_ARTICLE_FAIL: "统计文章失败", ERROR_COUNT_ARTICLE_FAIL: "统计币种失败",
ERROR_GET_ARTICLES_FAIL: "获取多个文章失败", ERROR_GET_ARTICLES_FAIL: "获取多个币种失败",
ERROR_GET_ARTICLE_FAIL: "获取单个文章失败", ERROR_GET_ARTICLE_FAIL: "获取单个币种失败",
ERROR_GEN_ARTICLE_POSTER_FAIL: "生成文章海报失败", ERROR_GEN_ARTICLE_POSTER_FAIL: "生成币种海报失败",
ERROR_AUTH_CHECK_TOKEN_FAIL: "Token鉴权失败", ERROR_AUTH_CHECK_TOKEN_FAIL: "Token鉴权失败",
ERROR_AUTH_CHECK_TOKEN_TIMEOUT: "Token已超时", ERROR_AUTH_CHECK_TOKEN_TIMEOUT: "Token已超时",
ERROR_AUTH_TOKEN: "Token生成失败", ERROR_AUTH_TOKEN: "Token生成失败",
......
...@@ -10,22 +10,20 @@ import ( ...@@ -10,22 +10,20 @@ import (
"bwallet/service/coin_service" "bwallet/service/coin_service"
"bwallet/pkg/util" "bwallet/pkg/util"
"bwallet/service/auth_service" "bwallet/service/auth_service"
"fmt"
) )
type AddCoinForm struct { type AddCoinForm struct {
Sid string `form:"sid" valid:"MinSize(2);MaxSize(10)"` Sid string `form:"sid" valid:"MinSize(2);MaxSize(10)"`
Name string `form:"name" valid:"Required;MinSize(2);MaxSize(50)"` Name string `form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
OptionalName string `form:"optional_name" valid:"MaxSize(10)"`
Nickname string `form:"nickname" valid:"MaxSize(100)"` Nickname string `form:"nickname" valid:"MaxSize(100)"`
Icon string `form:"icon"` Icon string `form:"icon" valid:"MaxSize(250)"`
Introduce string `form:"introduce" valid:"MaxSize(500)"` Introduce string `form:"introduce" valid:"MaxSize(500)"`
Official string `form:"official" valid:"MaxSize(5)"` Official string `form:"official" valid:"MaxSize(5)"`
Paper string `form:"paper" valid:"MaxSize(10)"` Paper string `form:"paper" valid:"MaxSize(10)"`
Exchange int `form:"exchange" valid:"Max(10)"`
Platform string `form:"platform" valid:"MaxSize(10)"` Platform string `form:"platform" valid:"MaxSize(10)"`
Chain string `form:"chain" valid:"MaxSize(10)"` Chain string `form:"chain" valid:"MaxSize(10)"`
Release string `form:"release" valid:"Required"` Release string `form:"release" valid:"Required"`
Price float64 `form:"price"`
AreaSearch string `form:"area_search" valid:"MaxSize(100)"` AreaSearch string `form:"area_search" valid:"MaxSize(100)"`
PublishCount float64 `form:"publish_count"` PublishCount float64 `form:"publish_count"`
CirculateCount float64 `form:"circulate_count"` CirculateCount float64 `form:"circulate_count"`
...@@ -33,30 +31,35 @@ type AddCoinForm struct { ...@@ -33,30 +31,35 @@ type AddCoinForm struct {
Address string `form:"address" valid:"MaxSize(50)"` Address string `form:"address" valid:"MaxSize(50)"`
Treaty int `form:"treaty" valid:"Range(1,2)"` Treaty int `form:"treaty" valid:"Range(1,2)"`
PlatformId int `form:"platform_id" valid:"Required;Min(1)"` PlatformId int `form:"platform_id" valid:"Required;Min(1)"`
//OptionalName string `form:"optional_name" valid:"MaxSize(10)"`
//Exchange int `form:"exchange" valid:"Max(10)"`
//Price float64 `form:"price"`
} }
type EditCoinForm struct { type EditCoinForm struct {
Id int `form:"id" valid:"Required;Min(1)"` Id int `form:"id" valid:"Required;Min(1)"`
Sid string `form:"sid" valid:"MinSize(2);MaxSize(10)"` Sid string `form:"sid" valid:"MinSize(2);MaxSize(10)"`
Name string `form:"name" valid:"Required;MinSize(2);MaxSize(50)"` Name string `form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
OptionalName string `form:"optional_name" valid:"MaxSize(10)"`
Nickname string `form:"nickname" valid:"MaxSize(100)"` Nickname string `form:"nickname" valid:"MaxSize(100)"`
Icon string `form:"icon"` Icon string `form:"icon" valid:"MaxSize(250)"`
Introduce string `form:"introduce" valid:"MaxSize(500)"` Introduce string `form:"introduce" valid:"MaxSize(500)"`
Official string `form:"official" valid:"MaxSize(5)"` Official string `form:"official" valid:"MaxSize(5)"`
Paper string `form:"paper" valid:"MaxSize(10)"` Paper string `form:"paper" valid:"MaxSize(10)"`
Exchange int `form:"exchange" valid:"Max(10)"`
Platform string `form:"platform" valid:"MaxSize(10)"` Platform string `form:"platform" valid:"MaxSize(10)"`
Chain string `form:"chain" valid:"MaxSize(10)"` Chain string `form:"chain" valid:"MaxSize(10)"`
Release string `form:"release" valid:"Required"` Release string `form:"release" valid:"Required"`
Price float64 `form:"price"`
AreaSearch string `form:"area_search" valid:"MaxSize(100)"` AreaSearch string `form:"area_search" valid:"MaxSize(100)"`
PublishCount float64 `form:"publish_count"` PublishCount float64 `form:"publish_count"`
CirculateCount float64 `form:"circulate_count"` CirculateCount float64 `form:"circulate_count"`
Decimals int `form:"decimals" valid:"Max(10)"` Decimals int `form:"decimals" valid:"Max(10)"`
Address string `form:"address" valid:"MaxSize(50)"` Address string `form:"address" valid:"MaxSize(50)"`
Treaty int `form:"treaty" valid:"Range(1,2)"` Treaty int `form:"treaty" valid:"Range(1,2)"`
PlatformId int `form:"platform_id" valid:"Required;Min(1)"` //PlatformId int `form:"platform_id" valid:"Required;Min(1)"`
//OptionalName string `form:"optional_name" valid:"MaxSize(10)"`
//Exchange int `form:"exchange" valid:"Max(10)"`
//Price float64 `form:"price"`
} }
func GetCoin(c *gin.Context) { func GetCoin(c *gin.Context) {
...@@ -116,6 +119,19 @@ func GetCoins(c *gin.Context) { ...@@ -116,6 +119,19 @@ func GetCoins(c *gin.Context) {
chain = c.Query("chain") chain = c.Query("chain")
} }
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 arg := c.Query("platform_id"); arg != "" {
platform_id = com.StrTo(c.Query("platform_id")).MustInt()
}
}
if valid.HasErrors() { if valid.HasErrors() {
app.MarkErrors(valid.Errors) app.MarkErrors(valid.Errors)
appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
...@@ -123,11 +139,12 @@ func GetCoins(c *gin.Context) { ...@@ -123,11 +139,12 @@ func GetCoins(c *gin.Context) {
} }
coinService := coin_service.Coin{ coinService := coin_service.Coin{
Name: name, Name: name,
Chain: chain, Chain: chain,
Platform: platform, Platform: platform,
PageNum: util.GetPage(c), PlatformId: platform_id,
PageSize: util.GetLimit(c), PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
} }
total, err := coinService.Count() total, err := coinService.Count()
...@@ -160,27 +177,39 @@ func AddCoin(c *gin.Context) { ...@@ -160,27 +177,39 @@ func AddCoin(c *gin.Context) {
appG.Response(httpCode, errCode, nil) appG.Response(httpCode, errCode, nil)
return 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) {
platform_id = form.PlatformId
}
coinService := coin_service.Coin{ coinService := coin_service.Coin{
Sid: form.Sid, Sid: form.Sid,
Name: form.Name, Name: form.Name,
OptionalName: form.OptionalName,
Nickname: form.Nickname, Nickname: form.Nickname,
Icon: form.Icon, Icon: form.Icon,
Introduce: form.Introduce, Introduce: form.Introduce,
Official: form.Official, Official: form.Official,
Paper: form.Paper, Paper: form.Paper,
Exchange: form.Exchange,
Platform: form.Platform, Platform: form.Platform,
Chain: form.Chain, Chain: form.Chain,
Release: form.Release, Release: form.Release,
Price: form.Price,
AreaSearch: form.AreaSearch, AreaSearch: form.AreaSearch,
PublishCount: form.PublishCount, PublishCount: form.PublishCount,
CirculateCount: form.CirculateCount, CirculateCount: form.CirculateCount,
Decimals: form.Decimals, Decimals: form.Decimals,
Address: form.Address, Address: form.Address,
PlatformId: form.PlatformId,
Treaty: form.Treaty, Treaty: form.Treaty,
PlatformId: platform_id,
//OptionalName: form.OptionalName,
//Exchange: form.Exchange,
//Price: form.Price,
} }
if err := coinService.Add(); err != nil { if err := coinService.Add(); err != nil {
...@@ -206,24 +235,25 @@ func EditCoin(c *gin.Context) { ...@@ -206,24 +235,25 @@ func EditCoin(c *gin.Context) {
Id: form.Id, Id: form.Id,
Sid: form.Sid, Sid: form.Sid,
Name: form.Name, Name: form.Name,
OptionalName: form.OptionalName,
Nickname: form.Nickname, Nickname: form.Nickname,
Icon: form.Icon, Icon: form.Icon,
Introduce: form.Introduce, Introduce: form.Introduce,
Official: form.Official, Official: form.Official,
Paper: form.Paper, Paper: form.Paper,
Exchange: form.Exchange,
Platform: form.Platform, Platform: form.Platform,
Chain: form.Chain, Chain: form.Chain,
Release: form.Release, Release: form.Release,
Price: form.Price,
AreaSearch: form.AreaSearch, AreaSearch: form.AreaSearch,
PublishCount: form.PublishCount, PublishCount: form.PublishCount,
CirculateCount: form.CirculateCount, CirculateCount: form.CirculateCount,
Decimals: form.Decimals, Decimals: form.Decimals,
Address: form.Address, Address: form.Address,
PlatformId: form.PlatformId,
Treaty: form.Treaty, Treaty: form.Treaty,
//PlatformId: form.PlatformId,
//OptionalName: form.OptionalName,
//Exchange: form.Exchange,
//Price: form.Price,
} }
exists, err := coinService.ExistById() exists, err := coinService.ExistById()
...@@ -236,6 +266,19 @@ func EditCoin(c *gin.Context) { ...@@ -236,6 +266,19 @@ func EditCoin(c *gin.Context) {
return return
} }
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
fmt.Println(form.Id)
coin_model := coin_service.Coin{Id: form.Id}
coin, _ := coin_model.Get()
if coin.PlatformId != auth.PlatformId {
appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_CHECK_TOKEN_FAIL, nil)
return
}
}
if err := coinService.Edit(); err != nil { if err := coinService.Edit(); err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_ADD_ARTICLE_FAIL, nil) appG.Response(http.StatusInternalServerError, e.ERROR_ADD_ARTICLE_FAIL, nil)
return return
...@@ -268,9 +311,21 @@ func DeleteCoin(c *gin.Context) { ...@@ -268,9 +311,21 @@ func DeleteCoin(c *gin.Context) {
return return
} }
token := c.Request.Header.Get("Token")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
if ("administrator" != group) {
coin, _ := coinService.Get()
if coin.PlatformId != auth.PlatformId {
appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_CHECK_TOKEN_FAIL, nil)
return
}
}
err = coinService.Delete() err = coinService.Delete()
if err != nil { if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_ARTICLE_FAIL, nil) appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_COIN_FAIL, nil)
return return
} }
......
...@@ -231,7 +231,7 @@ func DeleteCoinRecommend(c *gin.Context) { ...@@ -231,7 +231,7 @@ func DeleteCoinRecommend(c *gin.Context) {
err = coinRecommendService.Delete() err = coinRecommendService.Delete()
if err != nil { if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_ARTICLE_FAIL, nil) appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_COIN_FAIL, nil)
return return
} }
......
...@@ -192,7 +192,7 @@ func DeleteWallet(c *gin.Context) { ...@@ -192,7 +192,7 @@ func DeleteWallet(c *gin.Context) {
err = walletService.Delete() err = walletService.Delete()
if err != nil { if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_ARTICLE_FAIL, nil) appG.Response(http.StatusInternalServerError, e.ERROR_DELETE_COIN_FAIL, nil)
return return
} }
......
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