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
a1a6e20a
Commit
a1a6e20a
authored
Dec 24, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
平行链管理
parent
b070ebd7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
674 additions
and
207 deletions
+674
-207
go.mod
go.mod
+1
-2
go.sum
go.sum
+0
-0
chain.go
models/chain.go
+137
-0
coin.go
models/coin.go
+2
-2
wallet.go
models/wallet.go
+9
-3
code.go
pkg/e/code.go
+19
-19
msg.go
pkg/e/msg.go
+25
-22
chain.go
routers/api/v1/chain.go
+236
-0
coin.go
routers/api/v1/coin.go
+20
-15
coin_recommend.go
routers/api/v1/coin_recommend.go
+11
-11
explore_app_category.go
routers/api/v1/explore_app_category.go
+0
-48
wallet.go
routers/api/v1/wallet.go
+90
-32
router.go
routers/router.go
+25
-19
chain.go
service/chain_service/chain.go
+89
-0
category.go
service/explore_service/category.go
+0
-34
wallet.go
service/wallet_service/wallet.go
+10
-0
No files found.
go.mod
View file @
a1a6e20a
...
@@ -12,6 +12,5 @@ require (
...
@@ -12,6 +12,5 @@ require (
github.com/go-sql-driver/mysql v1.4.1
github.com/go-sql-driver/mysql v1.4.1
github.com/gomodule/redigo v2.0.0+incompatible
github.com/gomodule/redigo v2.0.0+incompatible
github.com/jinzhu/gorm v1.9.10
github.com/jinzhu/gorm v1.9.10
github.com/kr/pretty v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0
gopkg.in/ini.v1 v1.51.0 // indirect
)
)
go.sum
View file @
a1a6e20a
This diff is collapsed.
Click to expand it.
models/chain.go
0 → 100644
View file @
a1a6e20a
package
models
import
(
"github.com/jinzhu/gorm"
)
type
Chain
struct
{
ID
int
`json:"primary_key"`
Platform
string
`json:"platform"`
//平行链名称
Address
string
`json:"address"`
//代扣地址
PrivateKey
string
`json:"private_key"`
//代扣私钥
Execer
string
`json:"execer"`
//执行器
Token
string
`json:"token"`
//基础代币
Fee
float32
`json:"fee"`
//手续费(基础代币)
BrowerUrl
string
`json:"brower_url"`
//浏览器链接
}
func
(
c
Chain
)
TableName
()
string
{
return
"wallet_chain"
}
/**
* 通过id检查链是否存在
* @param id
* @return
*/
func
ExistChainById
(
id
int
)
(
bool
,
error
)
{
var
chain
Chain
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
chain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
chain
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
/**
* 获取符合条件的信息总数
* @param id
* @return
*/
func
GetChainTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Model
(
&
Chain
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
/**
* 获取符合条件的信息
* @param id
* @return
*/
func
GetChains
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
Chain
,
error
)
{
var
chains
[]
*
Chain
err
:=
db
.
Where
(
maps
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
chains
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
chains
,
nil
}
/**
* 通过id获取指定链信息
* @param id
* @return
*/
func
GetChain
(
id
int
)
(
*
Chain
,
error
)
{
var
chain
Chain
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
chain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
chain
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
chain
,
nil
}
/**
* 添加链信息
* @param
* @return
*/
func
AddChain
(
data
map
[
string
]
interface
{})
(
error
)
{
chain
:=
Chain
{
Platform
:
data
[
"platform"
]
.
(
string
),
Address
:
data
[
"address"
]
.
(
string
),
PrivateKey
:
data
[
"private_key"
]
.
(
string
),
Execer
:
data
[
"execer"
]
.
(
string
),
Token
:
data
[
"token"
]
.
(
string
),
Fee
:
data
[
"fee"
]
.
(
float32
),
BrowerUrl
:
data
[
"brower_url"
]
.
(
string
),
}
if
err
:=
db
.
Create
(
&
chain
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
/**
* 更新链信息
* @param
* @return
*/
func
EditChain
(
id
int
,
data
interface
{})
error
{
if
err
:=
db
.
Model
(
&
Chain
{})
.
Where
(
"id = ?"
,
id
)
.
Updates
(
data
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
/**
* 删除链信息
* @param
* @return
*/
func
DeleteChain
(
id
int
)
error
{
if
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
Delete
(
Chain
{})
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
models/coin.go
View file @
a1a6e20a
...
@@ -32,7 +32,7 @@ type Coin struct {
...
@@ -32,7 +32,7 @@ type Coin struct {
}
}
func
(
c
Coin
)
TableName
()
string
{
func
(
c
Coin
)
TableName
()
string
{
return
"
coins
"
return
"
wallet_coin
"
}
}
...
@@ -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
.
Debug
()
.
Where
(
maps
)
.
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
}
}
...
...
models/wallet.go
View file @
a1a6e20a
...
@@ -7,9 +7,12 @@ import (
...
@@ -7,9 +7,12 @@ import (
type
Wallet
struct
{
type
Wallet
struct
{
Model
Model
Name
string
`json:"name"`
Name
string
`gorm:"size:255;not null;" json:"name"`
DownloadUrl
string
`json:"download_url"`
DownloadUrl
string
`gorm:"not null;" json:"download_url"`
Introduce
string
`json:"introduce"`
Introduce
string
`gorm:"not null;" json:"introduce"`
ChainId
int
`gorm:"not null;default:0" json:"chain_id"`
IssueCharge
float32
`gorm:"not null;default:0.00" json:"issue_charge"`
ChargeUnit
string
`gorm:"not null;default:BTY" json:"charge_unit"`
}
}
func
(
w
Wallet
)
TableName
()
string
{
func
(
w
Wallet
)
TableName
()
string
{
...
@@ -69,6 +72,9 @@ func AddWallet(data map[string]interface{}) (error) {
...
@@ -69,6 +72,9 @@ func AddWallet(data map[string]interface{}) (error) {
Name
:
data
[
"name"
]
.
(
string
),
Name
:
data
[
"name"
]
.
(
string
),
DownloadUrl
:
data
[
"download_url"
]
.
(
string
),
DownloadUrl
:
data
[
"download_url"
]
.
(
string
),
Introduce
:
data
[
"introduce"
]
.
(
string
),
Introduce
:
data
[
"introduce"
]
.
(
string
),
ChargeUnit
:
data
[
"charge_unit"
]
.
(
string
),
IssueCharge
:
data
[
"issue_charge"
]
.
(
float32
),
ChainId
:
data
[
"chain_id"
]
.
(
int
),
}
}
if
err
:=
db
.
Create
(
&
wallet
)
.
Error
;
err
!=
nil
{
if
err
:=
db
.
Create
(
&
wallet
)
.
Error
;
err
!=
nil
{
return
err
return
err
...
...
pkg/e/code.go
View file @
a1a6e20a
...
@@ -5,26 +5,26 @@ const (
...
@@ -5,26 +5,26 @@ const (
ERROR
=
500
ERROR
=
500
INVALID_PARAMS
=
400
INVALID_PARAMS
=
400
ERROR_EXIST_TAG
=
10001
ERROR_EXIST_COIN
=
10001
ERROR_EXIST_TAG_FAIL
=
10002
ERROR_GET_COIN_FAIL
=
10002
ERROR_NOT_EXIST_TAG
=
10003
ERROR_COUNT_COIN_FAIL
=
10003
ERROR_GET_TAGS_FAIL
=
10004
ERROR_ADD_COIN_FAIL
=
10004
ERROR_COUNT_TAG_FAIL
=
10005
ERROR_UPDATE_COIN_FAIL
=
10005
ERROR_ADD_TAG_FAIL
=
10006
ERROR_DELETE_COIN_FAIL
=
10006
ERROR_EDIT_TAG_FAIL
=
10007
ERROR_DELETE_TAG_FAIL
=
10008
ERROR_EXPORT_TAG_FAIL
=
10009
ERROR_IMPORT_TAG_FAIL
=
10010
ERROR_NOT_EXIST_ARTICLE
=
10011
ERROR_EXIST_WALLET
=
10011
ERROR_CHECK_EXIST_ARTICLE_FAIL
=
10012
ERROR_GET_WALLET_FAIL
=
10012
ERROR_ADD_ARTICLE_FAIL
=
10013
ERROR_COUNT_WALLET_FAIL
=
10013
ERROR_DELETE_COIN_FAIL
=
10014
ERROR_ADD_WALLET_FAIL
=
10014
ERROR_EDIT_ARTICLE_FAIL
=
10015
ERROR_UPDATE_WALLET_FAIL
=
10015
ERROR_COUNT_ARTICLE_FAIL
=
10016
ERROR_DELETE_WALLET_FAIL
=
10016
ERROR_GET_ARTICLES_FAIL
=
10017
ERROR_GET_ARTICLE_FAIL
=
10018
ERROR_EXIST_CHAIN
=
10111
ERROR_GEN_ARTICLE_POSTER_FAIL
=
10019
ERROR_GET_CHAIN_FAIL
=
10112
ERROR_COUNT_CHAIN_FAIL
=
10113
ERROR_ADD_CHAIN_FAIL
=
10114
ERROR_UPDATE_CHAIN_FAIL
=
10115
ERROR_DELETE_CHAIN_FAIL
=
10116
ERROR_NOT_EXIST_CATEGORY
=
10011
ERROR_NOT_EXIST_CATEGORY
=
10011
ERROR_CHECK_EXIST_CATEGORY_FAIL
=
10012
ERROR_CHECK_EXIST_CATEGORY_FAIL
=
10012
...
...
pkg/e/msg.go
View file @
a1a6e20a
package
e
package
e
var
MsgFlags
=
map
[
int
]
string
{
var
MsgFlags
=
map
[
int
]
string
{
SUCCESS
:
"ok"
,
SUCCESS
:
"ok"
,
ERROR
:
"fail"
,
ERROR
:
"fail"
,
INVALID_PARAMS
:
"请求参数错误"
,
INVALID_PARAMS
:
"请求参数错误"
,
ERROR_EXIST_TAG
:
"已存在该标签名称"
,
ERROR_EXIST_TAG_FAIL
:
"获取已存在标签失败"
,
ERROR_EXIST_COIN
:
"币种验证失败"
,
ERROR_NOT_EXIST_TAG
:
"该标签不存在"
,
ERROR_GET_COIN_FAIL
:
"币种信息获取失败"
,
ERROR_GET_TAGS_FAIL
:
"获取所有标签失败"
,
ERROR_COUNT_COIN_FAIL
:
"币种数量统计失败"
,
ERROR_COUNT_TAG_FAIL
:
"统计标签失败"
,
ERROR_ADD_COIN_FAIL
:
"币种添加失败"
,
ERROR_ADD_TAG_FAIL
:
"新增标签失败"
,
ERROR_UPDATE_COIN_FAIL
:
"币种更新失败"
,
ERROR_EDIT_TAG_FAIL
:
"修改标签失败"
,
ERROR_DELETE_COIN_FAIL
:
"币种删除失败"
,
ERROR_DELETE_TAG_FAIL
:
"删除标签失败"
,
ERROR_EXPORT_TAG_FAIL
:
"导出标签失败"
,
ERROR_EXIST_WALLET
:
"钱包验证失败"
,
ERROR_IMPORT_TAG_FAIL
:
"导入标签失败"
,
ERROR_GET_WALLET_FAIL
:
"钱包信息获取失败"
,
ERROR_NOT_EXIST_ARTICLE
:
"该币种不存在"
,
ERROR_COUNT_WALLET_FAIL
:
"钱包数量统计失败"
,
ERROR_ADD_ARTICLE_FAIL
:
"新增币种失败"
,
ERROR_ADD_WALLET_FAIL
:
"钱包添加失败"
,
ERROR_DELETE_COIN_FAIL
:
"删除币种失败"
,
ERROR_UPDATE_WALLET_FAIL
:
"钱包更新失败"
,
ERROR_CHECK_EXIST_ARTICLE_FAIL
:
"检查币种是否存在失败"
,
ERROR_DELETE_WALLET_FAIL
:
"钱包删除失败"
,
ERROR_EDIT_ARTICLE_FAIL
:
"修改币种失败"
,
ERROR_COUNT_ARTICLE_FAIL
:
"统计币种失败"
,
ERROR_EXIST_CHAIN
:
"平行链失败"
,
ERROR_GET_ARTICLES_FAIL
:
"获取多个币种失败"
,
ERROR_GET_CHAIN_FAIL
:
"平行链信息获取失败"
,
ERROR_GET_ARTICLE_FAIL
:
"获取单个币种失败"
,
ERROR_COUNT_CHAIN_FAIL
:
"平行链数量统计失败"
,
ERROR_GEN_ARTICLE_POSTER_FAIL
:
"生成币种海报失败"
,
ERROR_ADD_CHAIN_FAIL
:
"平行链添加失败"
,
ERROR_UPDATE_CHAIN_FAIL
:
"平行链更新失败"
,
ERROR_DELETE_CHAIN_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生成失败"
,
...
...
routers/api/v1/chain.go
0 → 100644
View file @
a1a6e20a
package
v1
import
(
"github.com/gin-gonic/gin"
"bwallet/pkg/app"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"net/http"
"bwallet/pkg/e"
"bwallet/service/chain_service"
"bwallet/pkg/util"
"bwallet/service/auth_service"
)
type
AddChainForm
struct
{
Platform
string
`form:"platform" valid:"Required;MinSize(2);MaxSize(50)"`
Address
string
`form:"address" valid:"Required;MinSize(2);MaxSize(50)"`
PrivateKey
string
`form:"private_key" valid:"Required;MinSize(10);MaxSize(100)"`
Execer
string
`form:"execer" valid:"Required;MinSize(5);MaxSize(50)"`
Token
string
`form:"token" valid:"Required;MinSize(2);MaxSize(10)"`
Fee
float32
`form:"fee"`
BrowerUrl
string
`form:"brower_url" valid:"Required;MinSize(5);MaxSize(50)"`
}
type
EditChainForm
struct
{
ID
int
`form:"id" valid:"Required;Min(1)"`
Platform
string
`form:"platform" valid:"Required;MinSize(2);MaxSize(50)"`
Address
string
`form:"address" valid:"Required;MinSize(2);MaxSize(50)"`
PrivateKey
string
`form:"private_key" valid:"Required;MinSize(10);MaxSize(100)"`
Execer
string
`form:"execer" valid:"Required;MinSize(5);MaxSize(50)"`
Token
string
`form:"token" valid:"Required;MinSize(2);MaxSize(10)"`
Fee
float32
`form:"fee"`
BrowerUrl
string
`form:"brower_url" valid:"Required;MinSize(5);MaxSize(50)"`
}
func
GetChain
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
c
}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
return
}
chainService
:=
chain_service
.
Chain
{
ID
:
id
}
exists
,
err
:=
chainService
.
ExistById
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_EXIST_CHAIN
,
nil
)
return
}
if
(
!
exists
)
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_EXIST_CHAIN
,
nil
)
return
}
chain
,
err
:=
chainService
.
Get
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_CHAIN_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
chain
)
}
func
GetChains
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
valid
:=
validation
.
Validation
{}
platform
:=
""
if
arg
:=
c
.
Query
(
"platform"
);
arg
!=
""
{
platform
=
c
.
Query
(
"platform"
)
}
if
valid
.
HasErrors
()
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
chainService
:=
chain_service
.
Chain
{
Platform
:
platform
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
total
,
err
:=
chainService
.
Count
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_CHAIN_FAIL
,
nil
)
return
}
chains
,
err
:=
chainService
.
GetAll
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_CHAIN_FAIL
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
chains
data
[
"total"
]
=
total
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
}
func
AddChain
(
c
*
gin
.
Context
)
{
var
(
appG
=
app
.
Gin
{
C
:
c
}
form
AddChainForm
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
httpCode
,
errCode
:=
app
.
BindAndValid
(
c
,
&
form
)
if
errCode
!=
e
.
SUCCESS
{
appG
.
Response
(
httpCode
,
errCode
,
nil
)
return
}
chainService
:=
chain_service
.
Chain
{
Platform
:
form
.
Platform
,
Address
:
form
.
Address
,
PrivateKey
:
form
.
PrivateKey
,
Execer
:
form
.
Execer
,
Token
:
form
.
Token
,
Fee
:
form
.
Fee
,
BrowerUrl
:
form
.
BrowerUrl
,
}
if
err
:=
chainService
.
Add
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_WALLET_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
}
func
EditChain
(
c
*
gin
.
Context
)
{
var
(
appG
=
app
.
Gin
{
C
:
c
}
form
=
EditChainForm
{
ID
:
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()}
)
httpCode
,
errCode
:=
app
.
BindAndValid
(
c
,
&
form
)
if
errCode
!=
e
.
SUCCESS
{
appG
.
Response
(
httpCode
,
errCode
,
nil
)
return
}
cbainService
:=
chain_service
.
Chain
{
ID
:
form
.
ID
,
Platform
:
form
.
Platform
,
Address
:
form
.
Address
,
PrivateKey
:
form
.
PrivateKey
,
Execer
:
form
.
Execer
,
Token
:
form
.
Token
,
Fee
:
form
.
Fee
,
BrowerUrl
:
form
.
BrowerUrl
,
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
&&
auth
.
PlatformId
!=
form
.
ID
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
exists
,
err
:=
cbainService
.
ExistById
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_EXIST_WALLET
,
nil
)
return
}
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_EXIST_WALLET
,
nil
)
return
}
if
err
:=
cbainService
.
Edit
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_UPDATE_WALLET_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
}
func
DeleteChain
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
chainService
:=
chain_service
.
Chain
{
ID
:
id
}
exists
,
err
:=
chainService
.
ExistById
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_EXIST_WALLET
,
nil
)
return
}
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_EXIST_WALLET
,
nil
)
return
}
err
=
chainService
.
Delete
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_DELETE_WALLET_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
}
routers/api/v1/coin.go
View file @
a1a6e20a
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ 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
{
...
@@ -93,7 +92,7 @@ func GetCoin(c *gin.Context) {
...
@@ -93,7 +92,7 @@ func GetCoin(c *gin.Context) {
coin
,
err
:=
coinService
.
GetAll
()
coin
,
err
:=
coinService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
COIN
_FAIL
,
nil
)
return
return
}
}
...
@@ -149,13 +148,13 @@ func GetCoins(c *gin.Context) {
...
@@ -149,13 +148,13 @@ func GetCoins(c *gin.Context) {
total
,
err
:=
coinService
.
Count
()
total
,
err
:=
coinService
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_
COIN
_FAIL
,
nil
)
return
return
}
}
coins
,
err
:=
coinService
.
GetAll
()
coins
,
err
:=
coinService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
ARTICLES
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
COIN
_FAIL
,
nil
)
return
return
}
}
...
@@ -213,7 +212,7 @@ func AddCoin(c *gin.Context) {
...
@@ -213,7 +212,7 @@ func AddCoin(c *gin.Context) {
}
}
if
err
:=
coinService
.
Add
();
err
!=
nil
{
if
err
:=
coinService
.
Add
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_
COIN
_FAIL
,
nil
)
return
return
}
}
...
@@ -258,11 +257,11 @@ func EditCoin(c *gin.Context) {
...
@@ -258,11 +257,11 @@ func EditCoin(c *gin.Context) {
exists
,
err
:=
coinService
.
ExistById
()
exists
,
err
:=
coinService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
CHECK_EXIST_ARTICLE_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
EXIST_COIN
,
nil
)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
NOT_EXIST_ARTICLE
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
EXIST_COIN
,
nil
)
return
return
}
}
...
@@ -271,7 +270,6 @@ func EditCoin(c *gin.Context) {
...
@@ -271,7 +270,6 @@ func EditCoin(c *gin.Context) {
auth
,
_
:=
authService
.
GetUserInfo
()
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
if
(
"administrator"
!=
group
)
{
fmt
.
Println
(
form
.
Id
)
coin_model
:=
coin_service
.
Coin
{
Id
:
form
.
Id
}
coin_model
:=
coin_service
.
Coin
{
Id
:
form
.
Id
}
coin
,
_
:=
coin_model
.
Get
()
coin
,
_
:=
coin_model
.
Get
()
if
coin
.
PlatformId
!=
auth
.
PlatformId
{
if
coin
.
PlatformId
!=
auth
.
PlatformId
{
...
@@ -280,7 +278,7 @@ func EditCoin(c *gin.Context) {
...
@@ -280,7 +278,7 @@ func EditCoin(c *gin.Context) {
}
}
}
}
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_
UPDATE_COIN
_FAIL
,
nil
)
return
return
}
}
...
@@ -302,12 +300,12 @@ func DeleteCoin(c *gin.Context) {
...
@@ -302,12 +300,12 @@ func DeleteCoin(c *gin.Context) {
coinService
:=
coin_service
.
Coin
{
Id
:
id
}
coinService
:=
coin_service
.
Coin
{
Id
:
id
}
exists
,
err
:=
coinService
.
ExistById
()
exists
,
err
:=
coinService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
CHECK_EXIST_ARTICLE_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
EXIST_COIN
,
nil
)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
NOT_EXIST_ARTICLE
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
EXIST_COIN
,
nil
)
return
return
}
}
...
@@ -337,7 +335,7 @@ func GetCoinsPlatform(c *gin.Context) {
...
@@ -337,7 +335,7 @@ func GetCoinsPlatform(c *gin.Context) {
coinService
:=
coin_service
.
Coin
{}
coinService
:=
coin_service
.
Coin
{}
coins
,
err
:=
coinService
.
GetCoinsPlatform
()
coins
,
err
:=
coinService
.
GetCoinsPlatform
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
ARTICLES
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
COIN
_FAIL
,
nil
)
return
return
}
}
...
@@ -347,11 +345,18 @@ func GetCoinsPlatform(c *gin.Context) {
...
@@ -347,11 +345,18 @@ func GetCoinsPlatform(c *gin.Context) {
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
}
}
func
GetChains
(
c
*
gin
.
Context
)
{
func
GetPrimaryChains
(
c
*
gin
.
Context
)
{
fmt
.
Println
(
"aaa"
)
appG
:=
app
.
Gin
{
c
}
appG
:=
app
.
Gin
{
c
}
data
:=
make
(
map
[
string
]
interface
{})
data
:=
make
(
map
[
string
]
interface
{})
data
[
"lists"
]
=
[]
string
{
"aa"
,
"bbb"
}
data
[
"items"
]
=
[]
string
{
"BTC"
,
"ETH"
,
"BTY"
,
"DCR"
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
}
func
GetTypes
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
c
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
[]
string
{
"coins"
,
"er c20/token"
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
}
}
routers/api/v1/coin_recommend.go
View file @
a1a6e20a
...
@@ -75,18 +75,18 @@ func GetCoinRecommend(c *gin.Context) {
...
@@ -75,18 +75,18 @@ func GetCoinRecommend(c *gin.Context) {
exists
,
err
:=
coinRecommendService
.
ExistById
()
exists
,
err
:=
coinRecommendService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_CHECK_EXIST_ARTICLE_FAIL, nil)
return
return
}
}
if
(
!
exists
)
{
if
(
!
exists
)
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_NOT_EXIST_ARTICLE
,
nil
)
//
appG.Response(http.StatusOK, e.ERROR_NOT_EXIST_ARTICLE, nil)
return
return
}
}
coinRecommend
,
err
:=
coinRecommendService
.
Get
()
coinRecommend
,
err
:=
coinRecommendService
.
Get
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_GET_ARTICLE_FAIL, nil)
return
return
}
}
...
@@ -121,13 +121,13 @@ func GetCoinsRecommend(c *gin.Context) {
...
@@ -121,13 +121,13 @@ func GetCoinsRecommend(c *gin.Context) {
total
,
err
:=
coinRecommendService
.
Count
()
total
,
err
:=
coinRecommendService
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_COUNT_ARTICLE_FAIL, nil)
return
return
}
}
coinRecommends
,
err
:=
coinRecommendService
.
GetAll
()
coinRecommends
,
err
:=
coinRecommendService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_ARTICLES_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_GET_ARTICLES_FAIL, nil)
return
return
}
}
...
@@ -159,7 +159,7 @@ func AddCoinRecommend(c *gin.Context) {
...
@@ -159,7 +159,7 @@ func AddCoinRecommend(c *gin.Context) {
}
}
if
err
:=
coinRecommendService
.
Add
();
err
!=
nil
{
if
err
:=
coinRecommendService
.
Add
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_ADD_ARTICLE_FAIL, nil)
return
return
}
}
...
@@ -189,16 +189,16 @@ func EditCoinRecommend(c *gin.Context) {
...
@@ -189,16 +189,16 @@ func EditCoinRecommend(c *gin.Context) {
exists
,
err
:=
coinRecommendService
.
ExistById
()
exists
,
err
:=
coinRecommendService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_CHECK_EXIST_ARTICLE_FAIL, nil)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_NOT_EXIST_ARTICLE
,
nil
)
//
appG.Response(http.StatusOK, e.ERROR_NOT_EXIST_ARTICLE, nil)
return
return
}
}
if
err
:=
coinRecommendService
.
Edit
();
err
!=
nil
{
if
err
:=
coinRecommendService
.
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
}
}
...
@@ -220,12 +220,12 @@ func DeleteCoinRecommend(c *gin.Context) {
...
@@ -220,12 +220,12 @@ func DeleteCoinRecommend(c *gin.Context) {
coinRecommendService
:=
coinRecommend_service
.
CoinRecommend
{
Id
:
id
}
coinRecommendService
:=
coinRecommend_service
.
CoinRecommend
{
Id
:
id
}
exists
,
err
:=
coinRecommendService
.
ExistById
()
exists
,
err
:=
coinRecommendService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_ARTICLE_FAIL
,
nil
)
//
appG.Response(http.StatusInternalServerError, e.ERROR_CHECK_EXIST_ARTICLE_FAIL, nil)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_NOT_EXIST_ARTICLE
,
nil
)
//
appG.Response(http.StatusOK, e.ERROR_NOT_EXIST_ARTICLE, nil)
return
return
}
}
...
...
routers/api/v1/explore_app_category.go
deleted
100644 → 0
View file @
b070ebd7
package
v1
import
(
"github.com/gin-gonic/gin"
"bwallet/pkg/app"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"net/http"
"bwallet/pkg/e"
"bwallet/service/explore_service"
)
/**
* 通过id获取指定类别信息
* @return
*/
func
GetCategory
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
if
valid
.
HasErrors
()
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
categoryService
:=
explore_service
.
Category
{
Id
:
id
}
exists
,
err
:=
categoryService
.
ExistById
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_CATEGORY_FAIL
,
nil
)
return
}
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_NOT_EXIST_CATEGORY
,
nil
)
return
}
category
,
err
:=
categoryService
.
Get
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_ARTICLE_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
category
)
}
routers/api/v1/wallet.go
View file @
a1a6e20a
...
@@ -9,21 +9,26 @@ import (
...
@@ -9,21 +9,26 @@ import (
"bwallet/pkg/e"
"bwallet/pkg/e"
"bwallet/service/wallet_service"
"bwallet/service/wallet_service"
"bwallet/pkg/util"
"bwallet/pkg/util"
"bwallet/
pkg/setting
"
"bwallet/
service/auth_service
"
)
)
type
AddWalletForm
struct
{
type
AddWalletForm
struct
{
Name
string
`form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
Name
string
`form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
DownloadUrl
string
`form:"download_url"`
DownloadUrl
string
`form:"download_url"`
Introduce
string
`form:"introduce" valid:"MaxSize(500)"`
Introduce
string
`form:"introduce" valid:"MaxSize(500)"`
ChainId
int
`form:"chain_id" gorm:"default:'0'"`
IssueCharge
float32
`form:"issue_charge" gorm:"default:'0.00'"`
ChargeUnit
string
`form:"charge_unit" gorm:"default:'BTY'"`
}
}
type
EditWalletForm
struct
{
type
EditWalletForm
struct
{
Id
int
`form:"id" valid:"Required;Min(1)"`
Id
int
`form:"id" valid:"Required;Min(1)"`
Name
string
`form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
Name
string
`form:"name" valid:"Required;MinSize(2);MaxSize(50)"`
DownloadUrl
string
`form:"download_url"`
DownloadUrl
string
`form:"download_url"`
Nickname
string
`form:"nickname" valid:"MaxSize(100)"`
Introduce
string
`form:"introduce" valid:"MaxSize(500)"`
Introduce
string
`form:"introduce" valid:"MaxSize(500)"`
ChainId
int
`form:"chain_id" gorm:"default:'0'"`
IssueCharge
float32
`form:"issue_charge" gorm:"default:'0.00'"`
ChargeUnit
string
`form:"charge_unit" gorm:"default:'BTY'"`
}
}
func
GetWallet
(
c
*
gin
.
Context
)
{
func
GetWallet
(
c
*
gin
.
Context
)
{
...
@@ -38,22 +43,33 @@ func GetWallet(c *gin.Context) {
...
@@ -38,22 +43,33 @@ func GetWallet(c *gin.Context) {
return
return
}
}
walletService
:=
wallet_service
.
Wallet
{
Id
:
id
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
platform_id
=
id
if
(
"administrator"
!=
group
&&
id
!=
auth
.
PlatformId
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
walletService
:=
wallet_service
.
Wallet
{
Id
:
platform_id
}
exists
,
err
:=
walletService
.
ExistById
()
exists
,
err
:=
walletService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
CHECK_EXIST_ARTICLE_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
if
(
!
exists
)
{
if
(
!
exists
)
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
NOT_EXIST_ARTICLE
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
wallet
,
err
:=
walletService
.
Get
()
wallet
,
err
:=
walletService
.
Get
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
WALLET
_FAIL
,
nil
)
return
return
}
}
...
@@ -69,37 +85,49 @@ func GetWallets(c *gin.Context) {
...
@@ -69,37 +85,49 @@ func GetWallets(c *gin.Context) {
name
=
c
.
Query
(
"name"
)
name
=
c
.
Query
(
"name"
)
}
}
page_size
:=
setting
.
AppSetting
.
PageSize
if
arg
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"pagesize"
,
"0"
))
.
MustInt
();
arg
!=
0
{
page_size
=
com
.
StrTo
(
c
.
Query
(
"pagesize"
))
.
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
)
return
return
}
}
walletService
:=
wallet_service
.
Wallet
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
Name
:
name
,
authService
:=
auth_service
.
Auth
{
Token
:
token
}
PageNum
:
util
.
GetPage
(
c
),
auth
,
_
:=
authService
.
GetUserInfo
()
PageSize
:
page_size
,
var
platform_id
int
platform_id
=
auth
.
PlatformId
group
:=
auth
.
Group
walletService
:=
wallet_service
.
Wallet
{}
if
(
"administrator"
==
group
)
{
walletService
=
wallet_service
.
Wallet
{
Name
:
name
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
else
{
walletService
=
wallet_service
.
Wallet
{
Id
:
platform_id
,
Name
:
name
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
}
total
,
err
:=
walletService
.
Count
()
total
,
err
:=
walletService
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_COUNT_
WALLET
_FAIL
,
nil
)
return
return
}
}
wallets
,
err
:=
walletService
.
GetAll
()
wallets
,
err
:=
walletService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
ARTICLES
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_GET_
WALLET
_FAIL
,
nil
)
return
return
}
}
data
:=
make
(
map
[
string
]
interface
{})
data
:=
make
(
map
[
string
]
interface
{})
data
[
"
list
s"
]
=
wallets
data
[
"
item
s"
]
=
wallets
data
[
"total"
]
=
total
data
[
"total"
]
=
total
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
data
)
...
@@ -111,6 +139,15 @@ func AddWallet(c *gin.Context) {
...
@@ -111,6 +139,15 @@ func AddWallet(c *gin.Context) {
form
AddWalletForm
form
AddWalletForm
)
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
httpCode
,
errCode
:=
app
.
BindAndValid
(
c
,
&
form
)
httpCode
,
errCode
:=
app
.
BindAndValid
(
c
,
&
form
)
if
errCode
!=
e
.
SUCCESS
{
if
errCode
!=
e
.
SUCCESS
{
appG
.
Response
(
httpCode
,
errCode
,
nil
)
appG
.
Response
(
httpCode
,
errCode
,
nil
)
...
@@ -120,10 +157,13 @@ func AddWallet(c *gin.Context) {
...
@@ -120,10 +157,13 @@ func AddWallet(c *gin.Context) {
Name
:
form
.
Name
,
Name
:
form
.
Name
,
DownloadUrl
:
form
.
DownloadUrl
,
DownloadUrl
:
form
.
DownloadUrl
,
Introduce
:
form
.
Introduce
,
Introduce
:
form
.
Introduce
,
ChainId
:
form
.
ChainId
,
IssueCharge
:
form
.
IssueCharge
,
ChargeUnit
:
form
.
ChargeUnit
,
}
}
if
err
:=
walletService
.
Add
();
err
!=
nil
{
if
err
:=
walletService
.
Add
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_
ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_ADD_
WALLET
_FAIL
,
nil
)
return
return
}
}
...
@@ -148,18 +188,27 @@ func EditWallet(c *gin.Context) {
...
@@ -148,18 +188,27 @@ func EditWallet(c *gin.Context) {
Introduce
:
form
.
Introduce
,
Introduce
:
form
.
Introduce
,
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
&&
auth
.
PlatformId
!=
form
.
Id
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
exists
,
err
:=
walletService
.
ExistById
()
exists
,
err
:=
walletService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
CHECK_EXIST_ARTICLE_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
NOT_EXIST_ARTICLE
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
if
err
:=
walletService
.
Edit
();
err
!=
nil
{
if
err
:=
walletService
.
Edit
();
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
ADD_ARTICLE
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
UPDATE_WALLET
_FAIL
,
nil
)
return
return
}
}
...
@@ -178,21 +227,30 @@ func DeleteWallet(c *gin.Context) {
...
@@ -178,21 +227,30 @@ func DeleteWallet(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
&&
auth
.
PlatformId
!=
id
)
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
walletService
:=
wallet_service
.
Wallet
{
Id
:
id
}
walletService
:=
wallet_service
.
Wallet
{
Id
:
id
}
exists
,
err
:=
walletService
.
ExistById
()
exists
,
err
:=
walletService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
CHECK_EXIST_ARTICLE_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
if
!
exists
{
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
NOT_EXIST_ARTICLE
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_
EXIST_WALLET
,
nil
)
return
return
}
}
err
=
walletService
.
Delete
()
err
=
walletService
.
Delete
()
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_DELETE_
COIN
_FAIL
,
nil
)
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_DELETE_
WALLET
_FAIL
,
nil
)
return
return
}
}
...
...
routers/router.go
View file @
a1a6e20a
...
@@ -28,26 +28,32 @@ func InitRouter() *gin.Engine {
...
@@ -28,26 +28,32 @@ func InitRouter() *gin.Engine {
api
.
Use
(
auth
.
AUTH
())
api
.
Use
(
auth
.
AUTH
())
{
{
//api.GET("/coins", v1.GetCoins)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
//api.POST("/coin", v1.AddCoin)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
//api.GET("/coin/:id", v1.GetCoin)
api
.
GET
(
"/coin/:id"
,
v1
.
GetCoin
)
//api.PUT("/coin", v1.EditCoin)
api
.
PUT
(
"/coin"
,
v1
.
EditCoin
)
//api.DELETE("/coin/:id", v1.DeleteCoin)
api
.
DELETE
(
"/coin/:id"
,
v1
.
DeleteCoin
)
//api.GET("/get-platform", v1.GetCoinsPlatform)
api
.
GET
(
"/primary-chains"
,
v1
.
GetPrimaryChains
)
api
.
GET
(
"/types"
,
v1
.
GetTypes
)
api
.
GET
(
"/get-platform"
,
v1
.
GetCoinsPlatform
)
api
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
api
.
POST
(
"/wallet"
,
v1
.
AddWallet
)
api
.
GET
(
"/wallet/:id"
,
v1
.
GetWallet
)
api
.
PUT
(
"/wallet/:id"
,
v1
.
EditWallet
)
api
.
DELETE
(
"/wallet/:id"
,
v1
.
DeleteWallet
)
api
.
GET
(
"/chains"
,
v1
.
GetChains
)
api
.
GET
(
"/chains"
,
v1
.
GetChains
)
//api.GET("/types", v1.GetTypes)
api
.
POST
(
"/chain"
,
v1
.
AddChain
)
api
.
GET
(
"/chain/:id"
,
v1
.
GetChain
)
//api.GET("/wallets", v1.GetWallets)
api
.
PUT
(
"/chain"
,
v1
.
EditChain
)
//api.POST("/wallet", v1.AddWallet)
api
.
DELETE
(
"/chain/:id"
,
v1
.
DeleteChain
)
//api.GET("/wallet/:id", v1.GetWallet)
//api.PUT("/wallet/:id", v1.EditWallet)
api
.
GET
(
"/coins-recommend"
,
v1
.
GetCoinsRecommend
)
//api.DELETE("/wallet/:id", v1.DeleteWallet)
api
.
POST
(
"/coin-recommend"
,
v1
.
AddCoinRecommend
)
//
api
.
GET
(
"/coin-recommend/:id"
,
v1
.
GetCoinRecommend
)
//api.GET("/coins-recommend", v1.GetCoinsRecommend)
api
.
PUT
(
"/coin-recommend/:id"
,
v1
.
EditCoinRecommend
)
//api.POST("/coin-recommend", v1.AddCoinRecommend)
api
.
DELETE
(
"/coin-recommend/:id"
,
v1
.
DeleteCoinRecommend
)
//api.GET("/coin-recommend/:id", v1.GetCoinRecommend)
//api.PUT("/coin-recommend/:id", v1.EditCoinRecommend)
//api.DELETE("/coin-recommend/:id", v1.DeleteCoinRecommend)
}
}
return
r
return
r
...
...
service/chain_service/chain.go
0 → 100644
View file @
a1a6e20a
package
chain_service
import
"bwallet/models"
type
Chain
struct
{
ID
int
Platform
string
Address
string
PrivateKey
string
Execer
string
Token
string
Fee
float32
BrowerUrl
string
PageNum
int
PageSize
int
}
func
(
c
*
Chain
)
Get
()
(
*
models
.
Chain
,
error
)
{
chain
,
err
:=
models
.
GetChain
(
c
.
ID
)
if
err
!=
nil
{
return
nil
,
err
}
return
chain
,
nil
}
func
(
c
*
Chain
)
GetAll
()
([]
*
models
.
Chain
,
error
)
{
var
chains
[]
*
models
.
Chain
chains
,
err
:=
models
.
GetChains
(
c
.
PageNum
,
c
.
PageSize
,
c
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
return
chains
,
nil
}
func
(
c
*
Chain
)
Add
()
error
{
chain
:=
map
[
string
]
interface
{}{
"platform"
:
c
.
Platform
,
"address"
:
c
.
Address
,
"private_key"
:
c
.
PrivateKey
,
"execer"
:
c
.
Execer
,
"token"
:
c
.
Token
,
"brower_url"
:
c
.
BrowerUrl
,
"fee"
:
c
.
Fee
,
}
if
err
:=
models
.
AddChain
(
chain
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
c
*
Chain
)
Edit
()
error
{
return
models
.
EditChain
(
c
.
ID
,
map
[
string
]
interface
{}{
"platform"
:
c
.
Platform
,
"address"
:
c
.
Address
,
"private_key"
:
c
.
PrivateKey
,
"execer"
:
c
.
Execer
,
"token"
:
c
.
Token
,
"brower_url"
:
c
.
BrowerUrl
,
"fee"
:
c
.
Fee
,
})
}
func
(
c
*
Chain
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistChainById
(
c
.
ID
)
}
func
(
c
*
Chain
)
Count
()
(
int
,
error
)
{
return
models
.
GetChainTotal
(
c
.
getMaps
())
}
func
(
c
*
Chain
)
Delete
()
error
{
return
models
.
DeleteChain
(
c
.
ID
)
}
func
(
c
*
Chain
)
getMaps
()
(
map
[
string
]
interface
{})
{
maps
:=
make
(
map
[
string
]
interface
{})
if
c
.
ID
!=
0
{
maps
[
"id"
]
=
c
.
ID
}
return
maps
}
service/explore_service/category.go
deleted
100644 → 0
View file @
b070ebd7
package
explore_service
import
(
"bwallet/models"
"encoding/json"
)
type
Category
struct
{
Id
int
Name
string
Sort
int
Limit
int
Style
int
Status
int
PlatformId
int
}
func
(
c
*
Category
)
Get
()
(
*
models
.
ExploreAppCategory
,
error
)
{
category
,
err
:=
models
.
GetCategory
(
c
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
var
name
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
category
.
Name
),
&
name
);
err
==
nil
{
category
.
Name
=
name
[
"zh-CN"
]
.
(
string
)
}
return
category
,
nil
}
func
(
c
*
Category
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistCategoryById
(
c
.
Id
)
}
service/wallet_service/wallet.go
View file @
a1a6e20a
...
@@ -9,6 +9,9 @@ type Wallet struct {
...
@@ -9,6 +9,9 @@ type Wallet struct {
Name
string
Name
string
DownloadUrl
string
DownloadUrl
string
Introduce
string
Introduce
string
ChainId
int
IssueCharge
float32
ChargeUnit
string
PageNum
int
PageNum
int
PageSize
int
PageSize
int
...
@@ -40,6 +43,9 @@ func (w *Wallet) Add() error {
...
@@ -40,6 +43,9 @@ func (w *Wallet) Add() error {
"name"
:
w
.
Name
,
"name"
:
w
.
Name
,
"download_url"
:
w
.
DownloadUrl
,
"download_url"
:
w
.
DownloadUrl
,
"introduce"
:
w
.
Introduce
,
"introduce"
:
w
.
Introduce
,
"chain_id"
:
w
.
ChainId
,
"charge_unit"
:
w
.
ChargeUnit
,
"issue_charge"
:
w
.
IssueCharge
,
}
}
if
err
:=
models
.
AddWallet
(
wallet
);
err
!=
nil
{
if
err
:=
models
.
AddWallet
(
wallet
);
err
!=
nil
{
...
@@ -72,6 +78,10 @@ func (w *Wallet) Delete() error {
...
@@ -72,6 +78,10 @@ func (w *Wallet) Delete() error {
func
(
c
*
Wallet
)
getMaps
()
(
map
[
string
]
interface
{})
{
func
(
c
*
Wallet
)
getMaps
()
(
map
[
string
]
interface
{})
{
maps
:=
make
(
map
[
string
]
interface
{})
maps
:=
make
(
map
[
string
]
interface
{})
if
c
.
Id
!=
0
{
maps
[
"id"
]
=
c
.
Id
}
if
c
.
Name
!=
""
{
if
c
.
Name
!=
""
{
maps
[
"name"
]
=
c
.
Name
maps
[
"name"
]
=
c
.
Name
}
}
...
...
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