Commit c8ae67fb authored by shajiaiming's avatar shajiaiming

fix

parent 5232ac11
...@@ -5,11 +5,13 @@ import ( ...@@ -5,11 +5,13 @@ import (
"bwallet/pkg/handler" "bwallet/pkg/handler"
"bwallet/pkg/util" "bwallet/pkg/util"
"bwallet/service/auth_service" "bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/service/recommend_coin_service" "bwallet/service/recommend_coin_service"
"bwallet/validate_service" "bwallet/validate_service"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/astaxie/beego/validation" "github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strconv"
"strings" "strings"
) )
...@@ -71,22 +73,6 @@ func AddRecommendCoin(c *gin.Context) { ...@@ -71,22 +73,6 @@ func AddRecommendCoin(c *gin.Context) {
} }
} }
//自定义验证
recommendCoinValidate := recommend_coin_service.RecommendCoin{
CategoryId: recommend_coin.CategoryId,
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()
...@@ -100,19 +86,85 @@ func AddRecommendCoin(c *gin.Context) { ...@@ -100,19 +86,85 @@ func AddRecommendCoin(c *gin.Context) {
} }
} }
recommendCoinService := recommend_coin_service.RecommendCoin{ for _, id := range strings.Split(recommend_coin.Cid, ",") {
Cid: recommend_coin.Cid, if id == "" {
Sort: recommend_coin.Sort, continue
PlatformId: platform_id, }
CategoryId: recommend_coin.CategoryId, coin_id, err := strconv.Atoi(id)
} if (nil != err) {
continue
}
coinService := coin_service.Coin{
Id: coin_id,
}
exists, err := coinService.ExistById()
if err != nil || !exists {
continue
}
if err := recommendCoinService.Add(); err != nil { existsRecommendCoinService := recommend_coin_service.RecommendCoin{
handler.SendResponse(c, errno.ErrAddCoin, nil) Cid: coin_id,
return PlatformId: platform_id,
CategoryId: recommend_coin.CategoryId,
}
existsRecommendCoinService.DeleteByCondition()
recommendCoinService := recommend_coin_service.RecommendCoin{
Cid: coin_id,
Sort: recommend_coin.Sort,
PlatformId: platform_id,
CategoryId: recommend_coin.CategoryId,
}
recommendCoinService.Add()
} }
handler.SendResponse(c, nil, nil) handler.SendResponse(c, nil, nil)
//自定义验证
/*
recommendCoinValidate := recommend_coin_service.RecommendCoin{
CategoryId: recommend_coin.CategoryId,
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")
authService := auth_service.Auth{Token: token}
auth, _ := authService.GetUserInfo()
group := auth.Group
var platform_id int
platform_id = auth.PlatformId
if ("administrator" == group) {
if recommend_coin.PlatformId != 0 {
platform_id = recommend_coin.PlatformId
}
}
recommendCoinService := recommend_coin_service.RecommendCoin{
Cid: recommend_coin.Cid,
Sort: recommend_coin.Sort,
PlatformId: platform_id,
CategoryId: recommend_coin.CategoryId,
}
if err := recommendCoinService.Add(); err != nil {
handler.SendResponse(c, errno.ErrAddCoin, nil)
return
}
handler.SendResponse(c, nil, nil)
*/
} }
func EditRecommendCoin(c *gin.Context) { func EditRecommendCoin(c *gin.Context) {
......
package validate_service package validate_service
type RecommendCoin struct { type RecommendCoin struct {
Cid int `json:"cid" validate:"required"` Cid string `json:"cid" validate:"required"`
Sort int `json:"sort" validate:"required"` Sort int `json:"sort" validate:"required"`
PlatformId int `json:"platform_id" validate:"required"` PlatformId int `json:"platform_id" validate:"required"`
CategoryId uint8 `json:"category_id" validate:"required"` CategoryId uint8 `json:"category_id" validate:"required"`
} }
type EditRecommendCoin struct { type EditRecommendCoin struct {
......
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