Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
c8ae67fb
Commit
c8ae67fb
authored
Mar 04, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
5232ac11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
29 deletions
+81
-29
recommend_coin.go
routers/api/v1/recommend_coin.go
+77
-25
recommend_coin.go
validate_service/recommend_coin.go
+4
-4
No files found.
routers/api/v1/recommend_coin.go
View file @
c8ae67fb
...
...
@@ -5,11 +5,13 @@ import (
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/service/recommend_coin_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"strconv"
"strings"
)
...
...
@@ -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"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
...
...
@@ -100,19 +86,85 @@ func AddRecommendCoin(c *gin.Context) {
}
}
recommendCoinService
:=
recommend_coin_service
.
RecommendCoin
{
Cid
:
recommend_coin
.
Cid
,
Sort
:
recommend_coin
.
Sort
,
PlatformId
:
platform_id
,
CategoryId
:
recommend_coin
.
CategoryId
,
}
for
_
,
id
:=
range
strings
.
Split
(
recommend_coin
.
Cid
,
","
)
{
if
id
==
""
{
continue
}
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
{
handler
.
SendResponse
(
c
,
errno
.
ErrAddCoin
,
nil
)
return
existsRecommendCoinService
:=
recommend_coin_service
.
RecommendCoin
{
Cid
:
coin_id
,
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
)
//自定义验证
/*
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
)
{
...
...
validate_service/recommend_coin.go
View file @
c8ae67fb
package
validate_service
type
RecommendCoin
struct
{
Cid
int
`json:"cid" validate:"required"`
Sort
int
`json:"sort" validate:"required"`
PlatformId
int
`json:"platform_id" validate:"required"`
CategoryId
uint8
`json:"category_id" validate:"required"`
Cid
string
`json:"cid" validate:"required"`
Sort
int
`json:"sort" validate:"required"`
PlatformId
int
`json:"platform_id" validate:"required"`
CategoryId
uint8
`json:"category_id" validate:"required"`
}
type
EditRecommendCoin
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment