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
10885fed
Commit
10885fed
authored
Mar 02, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推荐类别
parent
a1dc2ae0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
468 additions
and
54 deletions
+468
-54
explore_app_category.go
models/explore_app_category.go
+0
-54
wallet_recommend_category.go
models/wallet_recommend_category.go
+129
-0
wallet_recommend_category.go
routers/api/v1/wallet_recommend_category.go
+227
-0
router.go
routers/router.go
+6
-0
wallet_recommend_category.go
...t_recommend_category_service/wallet_recommend_category.go
+90
-0
wallet_recommend_category.go
validate_service/wallet_recommend_category.go
+16
-0
No files found.
models/explore_app_category.go
deleted
100644 → 0
View file @
a1dc2ae0
package
models
import
"github.com/jinzhu/gorm"
type
ExploreAppCategory
struct
{
ID
uint64
`gorm:"primary_key;auto_increment" json:"id"`
Name
string
`gorm:"size:255;not null;" json:"name"`
Sort
uint32
`gorm:"not null;default:1" json:"sort"`
Limit
uint32
`gorm:"not null;default:1" json:"limit"`
Style
uint32
`gorm:"not null;default:1" json:"style"`
Status
uint8
`gorm:"not null;default:1" json:"status"`
PlatformId
uint64
`gorm:"not null;default:0" json:"platform_id"`
}
/**
* 通过id检查类别是否存在
* @param id
* @return
*/
func
ExistCategoryById
(
id
int
)
(
bool
,
error
)
{
var
category
ExploreAppCategory
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
category
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
/**
* 通过id获取指定类别信息
* @param id
* @return
*/
func
GetCategory
(
id
int
)
(
*
ExploreAppCategory
,
error
)
{
var
category
ExploreAppCategory
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
category
,
nil
}
models/wallet_recommend_category.go
0 → 100644
View file @
10885fed
package
models
import
(
"encoding/json"
"github.com/jinzhu/gorm"
)
type
WalletRecommendCategory
struct
{
ID
int
`gorm:"primary_key;auto_increment" json:"id"`
Name
json
.
RawMessage
`json:"name"`
Sort
uint32
`gorm:"not null;default:1" json:"sort"`
WalletType
uint8
`gorm:"not null;default:1" json:"wallet_type"`
Status
uint8
`gorm:"not null;default:1" json:"status"`
PlatformId
int
`gorm:"not null;default:0" json:"platform_id"`
}
/**
* 通过id检查类别是否存在
* @param id
* @return
*/
func
ExistCategoryById
(
id
int
)
(
bool
,
error
)
{
var
category
WalletRecommendCategory
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
category
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
/**
* 通过id获取指定类别信息
* @param id
* @return
*/
func
GetWalletRecommendCategory
(
id
int
)
(
*
WalletRecommendCategory
,
error
)
{
var
category
WalletRecommendCategory
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
category
,
nil
}
/**
* 获取符合条件的信息
* @return
*/
func
GetWalletRecommendCurrencies
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
WalletRecommendCategory
,
error
)
{
var
categories
[]
*
WalletRecommendCategory
err
:=
db
.
Select
(
"id, name, sort, status, wallet_type"
)
.
Find
(
&
categories
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
categories
,
nil
}
/**
* 添加推荐类别信息
* @param
* @return
*/
func
AddWalletRecommendCategory
(
data
map
[
string
]
interface
{})
(
error
)
{
category
:=
WalletRecommendCategory
{
Name
:
data
[
"name"
]
.
(
json
.
RawMessage
),
Sort
:
data
[
"sort"
]
.
(
uint32
),
WalletType
:
data
[
"wallet_type"
]
.
(
uint8
),
Status
:
data
[
"status"
]
.
(
uint8
),
PlatformId
:
data
[
"platform_id"
]
.
(
int
),
}
if
err
:=
db
.
Create
(
&
category
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
/**
* 更新推荐类别信息
* @param
* @return
*/
func
EditWalletRecommendCategory
(
id
int
,
data
interface
{})
error
{
if
err
:=
db
.
Model
(
&
WalletRecommendCategory
{})
.
Where
(
"id = ?"
,
id
)
.
Updates
(
data
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
/**
* 删除推荐类别信息
* @param
* @return
*/
func
DeleteWalletRecommendCategory
(
id
int
)
error
{
if
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
Delete
(
Coin
{})
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
/**
* 获取推荐类别数量
* @param
* @return
*/
func
GetRecommendCategoryTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Model
(
&
WalletRecommendCategory
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
routers/api/v1/wallet_recommend_category.go
0 → 100644
View file @
10885fed
package
v1
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/wallet_recommend_category_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"strings"
)
func
GetWalletRecommendCategory
(
c
*
gin
.
Context
)
{
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
if
(
"administrator"
==
group
)
{
platform_id
=
com
.
StrTo
(
c
.
DefaultQuery
(
"platform_id"
,
"1"
))
.
MustInt
()
}
else
{
platform_id
=
auth
.
PlatformId
}
categoryService
:=
wallet_recommend_category
.
WalletRecommendCategory
{
Id
:
id
,
PlatformId
:
platform_id
}
exists
,
err
:=
categoryService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrWalletNotFound
,
nil
)
return
}
if
(
!
exists
)
{
handler
.
SendResponse
(
c
,
errno
.
ErrWalletNotFound
,
nil
)
return
}
wallet
,
err
:=
categoryService
.
Get
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrWalletNotFound
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
wallet
)
}
func
GetWalletRecommendCategories
(
c
*
gin
.
Context
)
{
valid
:=
validation
.
Validation
{}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
if
(
"administrator"
==
group
)
{
platform_id
=
com
.
StrTo
(
c
.
DefaultQuery
(
"platform_id"
,
"1"
))
.
MustInt
()
}
else
{
platform_id
=
auth
.
PlatformId
}
var
wallet_type
uint8
if
arg
:=
c
.
Query
(
"type"
);
arg
!=
""
{
wallet_type
=
com
.
StrTo
(
c
.
Query
(
"type"
))
.
MustUint8
()
}
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
categoryService
:=
wallet_recommend_category
.
WalletRecommendCategory
{
PlatformId
:
platform_id
,
WalletType
:
wallet_type
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
total
,
err
:=
categoryService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountSupportedCurrency
,
nil
)
return
}
currencies
,
err
:=
categoryService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
currencies
data
[
"total"
]
=
total
handler
.
SendResponse
(
c
,
nil
,
data
)
}
func
AddWalletRecommendCategory
(
c
*
gin
.
Context
)
{
category
:=
validate_service
.
RecommendCategory
{}
c
.
ShouldBindJSON
(
&
category
)
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
category
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
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
category
.
PlatformId
!=
0
{
platform_id
=
category
.
PlatformId
}
}
categoryService
:=
wallet_recommend_category
.
WalletRecommendCategory
{
PlatformId
:
platform_id
,
Status
:
category
.
Status
,
Sort
:
category
.
Sort
,
WalletType
:
category
.
WalletType
,
}
if
err
:=
categoryService
.
Add
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrAddSupportedCurrency
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
EditWalletRecommendCategory
(
c
*
gin
.
Context
)
{
category
:=
validate_service
.
EditRecommendCategory
{}
c
.
ShouldBindJSON
(
&
category
)
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
category
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
categoryService
:=
wallet_recommend_category
.
WalletRecommendCategory
{
Id
:
category
.
Id
,
Status
:
category
.
Status
,
Sort
:
category
.
Sort
,
}
exists
,
err
:=
categoryService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrSupportedCurrencyNotFound
,
nil
)
return
}
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrSupportedCurrencyNotFound
,
nil
)
return
}
if
err
:=
categoryService
.
Edit
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateSupportedCurrency
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
DeleteWalletRecommendCategory
(
c
*
gin
.
Context
)
{
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
categoryService
:=
wallet_recommend_category
.
WalletRecommendCategory
{
Id
:
id
}
exists
,
err
:=
categoryService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
category
,
_
:=
categoryService
.
Get
()
if
category
.
PlatformId
!=
auth
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
}
err
=
categoryService
.
Delete
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteSupportedCurrency
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
routers/router.go
View file @
10885fed
...
@@ -54,6 +54,12 @@ func InitRouter() *gin.Engine {
...
@@ -54,6 +54,12 @@ func InitRouter() *gin.Engine {
api
.
PUT
(
"/chain"
,
v1
.
EditChain
)
api
.
PUT
(
"/chain"
,
v1
.
EditChain
)
api
.
DELETE
(
"/chain/:id"
,
v1
.
DeleteChain
)
api
.
DELETE
(
"/chain/:id"
,
v1
.
DeleteChain
)
api
.
GET
(
"/recommend-categories"
,
v1
.
GetWalletRecommendCategories
)
api
.
POST
(
"/recommend-category"
,
v1
.
AddWalletRecommendCategory
)
api
.
GET
(
"/recommend-category/:id"
,
v1
.
GetWalletRecommendCategory
)
api
.
DELETE
(
"/recommend-category/:id"
,
v1
.
DeleteWalletRecommendCategory
)
api
.
PUT
(
"/recommend-category"
,
v1
.
EditWalletRecommendCategory
)
api
.
GET
(
"/recommend-coins"
,
v1
.
GetRecommendCoins
)
api
.
GET
(
"/recommend-coins"
,
v1
.
GetRecommendCoins
)
api
.
POST
(
"/recommend-coin"
,
v1
.
AddRecommendCoin
)
api
.
POST
(
"/recommend-coin"
,
v1
.
AddRecommendCoin
)
api
.
PUT
(
"/recommend-coin"
,
v1
.
EditRecommendCoin
)
api
.
PUT
(
"/recommend-coin"
,
v1
.
EditRecommendCoin
)
...
...
service/wallet_recommend_category_service/wallet_recommend_category.go
0 → 100644
View file @
10885fed
package
wallet_recommend_category
import
(
"bwallet/models"
"encoding/json"
)
type
WalletRecommendCategory
struct
{
Id
int
Name
json
.
RawMessage
Sort
uint32
WalletType
uint8
Status
uint8
PlatformId
int
PageNum
int
PageSize
int
}
func
(
c
*
WalletRecommendCategory
)
Get
()
(
*
models
.
WalletRecommendCategory
,
error
)
{
currency
,
err
:=
models
.
GetWalletRecommendCategory
(
c
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
return
currency
,
nil
}
func
(
c
*
WalletRecommendCategory
)
GetAll
()
([]
*
models
.
WalletRecommendCategory
,
error
)
{
var
categories
[]
*
models
.
WalletRecommendCategory
categories
,
err
:=
models
.
GetWalletRecommendCurrencies
(
c
.
PageNum
,
c
.
PageSize
,
c
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
return
categories
,
nil
}
func
(
c
*
WalletRecommendCategory
)
Add
()
error
{
category
:=
map
[
string
]
interface
{}{
"name"
:
c
.
Name
,
"sort"
:
c
.
Sort
,
"wallet_type"
:
c
.
WalletType
,
"status"
:
c
.
Status
,
"platform_id"
:
c
.
PlatformId
,
}
if
err
:=
models
.
AddWalletRecommendCategory
(
category
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
c
*
WalletRecommendCategory
)
Edit
()
error
{
return
models
.
EditWalletRecommendCategory
(
c
.
Id
,
map
[
string
]
interface
{}{
"sort"
:
c
.
Sort
,
})
}
func
(
c
*
WalletRecommendCategory
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistCategoryById
(
c
.
Id
)
}
func
(
c
*
WalletRecommendCategory
)
Count
()
(
int
,
error
)
{
return
models
.
GetRecommendCategoryTotal
(
c
.
getMaps
())
}
func
(
c
*
WalletRecommendCategory
)
Delete
()
error
{
return
models
.
DeleteWalletRecommendCategory
(
c
.
Id
)
}
func
(
c
*
WalletRecommendCategory
)
getMaps
()
(
map
[
string
]
interface
{})
{
maps
:=
make
(
map
[
string
]
interface
{})
if
c
.
Id
!=
0
{
maps
[
"id"
]
=
c
.
Id
}
if
c
.
WalletType
!=
0
{
maps
[
"type"
]
=
c
.
WalletType
}
if
c
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
c
.
PlatformId
}
return
maps
}
validate_service/wallet_recommend_category.go
0 → 100644
View file @
10885fed
package
validate_service
import
"encoding/json"
type
RecommendCategory
struct
{
Name
json
.
RawMessage
`json:"name" validate:"required"`
Sort
uint32
`json:"sort" validate:"required"`
WalletType
uint8
`json:"wallet_type" validate:"required"`
Status
uint8
`json:"status" validate:"required"`
PlatformId
int
`json:"platform_id" validate:"required"`
}
type
EditRecommendCategory
struct
{
RecommendCategory
Id
int
`json:"id" validate:"required"`
}
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