Commit 8125825e authored by shajiaiming's avatar shajiaiming

fix

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