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
27ceb447
Commit
27ceb447
authored
Mar 24, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
77ce6f4a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
15 deletions
+64
-15
coin.go
models/coin.go
+25
-4
util.go
pkg/util/util.go
+27
-1
coin.go
routers/api/v1/coin.go
+10
-8
coin.go
service/coin_service/coin.go
+2
-2
No files found.
models/coin.go
View file @
27ceb447
...
@@ -2,6 +2,7 @@ package models
...
@@ -2,6 +2,7 @@ package models
import
(
import
(
"bwallet/pkg/setting"
"bwallet/pkg/setting"
"bwallet/pkg/util"
"encoding/json"
"encoding/json"
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm"
)
)
...
@@ -25,7 +26,7 @@ type Coin struct {
...
@@ -25,7 +26,7 @@ type Coin struct {
Decimals
int
`json:"decimals"`
//币种精度
Decimals
int
`json:"decimals"`
//币种精度
Address
string
`json:"address"`
//合约地址
Address
string
`json:"address"`
//合约地址
Treaty
int
`json:"treaty"`
//币种类型
Treaty
int
`json:"treaty"`
//币种类型
PlatformId
int
`json:"platform_id"`
PlatformId
string
`json:"platform_id"`
}
}
func
(
c
Coin
)
TableName
()
string
{
func
(
c
Coin
)
TableName
()
string
{
...
@@ -58,7 +59,17 @@ func ExistCoinById(id int) (bool, error) {
...
@@ -58,7 +59,17 @@ func ExistCoinById(id int) (bool, error) {
*/
*/
func
GetCoinTotal
(
maps
interface
{})
(
int
,
error
)
{
func
GetCoinTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
var
count
int
if
err
:=
db
.
Model
(
&
Coin
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
var
platform_id
int
term
:=
make
(
map
[
string
]
interface
{})
for
key
,
val
:=
range
maps
.
(
map
[
string
]
interface
{})
{
if
(
"platform_id"
==
key
)
{
platform_id
=
util
.
ToInt
(
val
)
}
else
{
term
[
key
]
=
val
}
}
if
err
:=
db
.
Model
(
&
Coin
{})
.
Where
(
"FIND_IN_SET(?, platform_id)"
,
platform_id
)
.
Where
(
term
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -72,8 +83,18 @@ func GetCoinTotal(maps interface{}) (int, error) {
...
@@ -72,8 +83,18 @@ 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
var
platform_id
int
term
:=
make
(
map
[
string
]
interface
{})
for
key
,
val
:=
range
maps
.
(
map
[
string
]
interface
{})
{
if
(
"platform_id"
==
key
)
{
platform_id
=
util
.
ToInt
(
val
)
}
else
{
term
[
key
]
=
val
}
}
err
:=
db
.
Where
(
"FIND_IN_SET(?, platform_id)"
,
platform_id
)
.
Where
(
term
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
coins
)
.
Error
err
:=
db
.
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
}
}
...
@@ -138,7 +159,7 @@ func AddCoin(data map[string]interface{}) (error) {
...
@@ -138,7 +159,7 @@ func AddCoin(data map[string]interface{}) (error) {
CirculateCount
:
data
[
"circulate_count"
]
.
(
float64
),
CirculateCount
:
data
[
"circulate_count"
]
.
(
float64
),
Decimals
:
data
[
"decimals"
]
.
(
int
),
Decimals
:
data
[
"decimals"
]
.
(
int
),
Address
:
data
[
"address"
]
.
(
string
),
Address
:
data
[
"address"
]
.
(
string
),
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
PlatformId
:
data
[
"platform_id"
]
.
(
string
),
Treaty
:
data
[
"treaty"
]
.
(
int
),
Treaty
:
data
[
"treaty"
]
.
(
int
),
}
}
if
err
:=
db
.
Create
(
&
coin
)
.
Error
;
err
!=
nil
{
if
err
:=
db
.
Create
(
&
coin
)
.
Error
;
err
!=
nil
{
...
...
pkg/util/util.go
View file @
27ceb447
package
util
package
util
import
"bwallet/pkg/setting"
import
(
"bwallet/pkg/setting"
"strconv"
)
// Setup Initialize the util
// Setup Initialize the util
func
Setup
()
{
func
Setup
()
{
jwtSecret
=
[]
byte
(
setting
.
AppSetting
.
JwtSecret
)
jwtSecret
=
[]
byte
(
setting
.
AppSetting
.
JwtSecret
)
}
func
ToInt
(
o
interface
{})
int
{
if
o
==
nil
{
return
0
}
switch
t
:=
o
.
(
type
)
{
case
float64
:
return
int
(
t
)
case
int
:
return
int
(
t
)
case
int64
:
return
int
(
t
)
case
string
:
tInt
,
err
:=
strconv
.
Atoi
(
t
)
if
err
!=
nil
{
return
-
1
}
return
tInt
default
:
return
-
1
}
}
}
\ No newline at end of file
routers/api/v1/coin.go
View file @
27ceb447
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"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"
)
)
...
@@ -35,7 +36,7 @@ func GetCoin(c *gin.Context) {
...
@@ -35,7 +36,7 @@ func GetCoin(c *gin.Context) {
}
}
coinService
:=
coin_service
.
Coin
{
coinService
:=
coin_service
.
Coin
{
Id
:
id
,
Id
:
id
,
PlatformId
:
platform_id
,
PlatformId
:
strconv
.
Itoa
(
platform_id
)
,
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
...
@@ -78,9 +79,9 @@ func GetCoins(c *gin.Context) {
...
@@ -78,9 +79,9 @@ func GetCoins(c *gin.Context) {
chain
=
c
.
Query
(
"chain"
)
chain
=
c
.
Query
(
"chain"
)
}
}
var
platform_id
int
platform_id
:=
""
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
platform_id
=
c
om
.
StrTo
(
c
.
DefaultQuery
(
"platform_id"
,
"1"
))
.
MustInt
(
)
platform_id
=
c
.
DefaultQuery
(
"platform_id"
,
"1"
)
}
}
if
valid
.
HasErrors
()
{
if
valid
.
HasErrors
()
{
...
@@ -153,7 +154,7 @@ func AddCoin(c *gin.Context) {
...
@@ -153,7 +154,7 @@ func AddCoin(c *gin.Context) {
Decimals
:
coin
.
Decimals
,
Decimals
:
coin
.
Decimals
,
Address
:
coin
.
Address
,
Address
:
coin
.
Address
,
Treaty
:
coin
.
Treaty
,
Treaty
:
coin
.
Treaty
,
PlatformId
:
coin
.
PlatformId
,
PlatformId
:
strconv
.
Itoa
(
coin
.
PlatformId
)
,
}
}
if
err
:=
coinService
.
Add
();
err
!=
nil
{
if
err
:=
coinService
.
Add
();
err
!=
nil
{
...
@@ -191,7 +192,7 @@ func EditCoin(c *gin.Context) {
...
@@ -191,7 +192,7 @@ func EditCoin(c *gin.Context) {
CirculateCount
:
coin
.
CirculateCount
,
CirculateCount
:
coin
.
CirculateCount
,
Decimals
:
coin
.
Decimals
,
Decimals
:
coin
.
Decimals
,
Address
:
coin
.
Address
,
Address
:
coin
.
Address
,
PlatformId
:
coin
.
PlatformId
,
PlatformId
:
strconv
.
Itoa
(
coin
.
PlatformId
)
,
Treaty
:
coin
.
Treaty
,
Treaty
:
coin
.
Treaty
,
}
}
...
@@ -210,11 +211,12 @@ func EditCoin(c *gin.Context) {
...
@@ -210,11 +211,12 @@ func EditCoin(c *gin.Context) {
auth
,
_
:=
authService
.
GetUserInfo
()
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
group
:=
auth
.
Group
coin_model
:=
coin_service
.
Coin
{
Id
:
coin
.
Id
}
//
coin_model := coin_service.Coin{Id: coin.Id}
coin_exist
,
_
:=
coin_model
.
Get
()
//
coin_exist, _ := coin_model.Get()
if
(
"administrator"
!=
group
)
{
if
(
"administrator"
!=
group
)
{
if
(
coin
.
PlatformId
!=
auth
.
PlatformId
)
||
(
auth
.
PlatformId
!=
coin_exist
.
PlatformId
){
//if (coin.PlatformId != auth.PlatformId) || (auth.PlatformId != coin_exist.PlatformId){
if
(
coin
.
PlatformId
!=
auth
.
PlatformId
){
handler
.
SendResponse
(
c
,
errno
.
ErrAuthCoin
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrAuthCoin
,
nil
)
return
return
}
}
...
...
service/coin_service/coin.go
View file @
27ceb447
...
@@ -21,7 +21,7 @@ type Coin struct {
...
@@ -21,7 +21,7 @@ type Coin struct {
CirculateCount
float64
CirculateCount
float64
Decimals
int
Decimals
int
Address
string
Address
string
PlatformId
int
PlatformId
string
Treaty
int
Treaty
int
PageNum
int
PageNum
int
...
@@ -192,7 +192,7 @@ func (c *Coin) getMaps() (map[string]interface{}) {
...
@@ -192,7 +192,7 @@ func (c *Coin) getMaps() (map[string]interface{}) {
maps
[
"platform"
]
=
c
.
Platform
maps
[
"platform"
]
=
c
.
Platform
}
}
if
c
.
PlatformId
!=
0
{
if
c
.
PlatformId
!=
""
{
maps
[
"platform_id"
]
=
c
.
PlatformId
maps
[
"platform_id"
]
=
c
.
PlatformId
}
}
...
...
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