Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SLG
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
service
SLG
Commits
37425a2d
Commit
37425a2d
authored
May 09, 2022
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
middleware & bonus detail
parent
ca322959
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
136 additions
and
37 deletions
+136
-37
main.go
main.go
+1
-0
auth.go
middleware/auth/auth.go
+34
-0
bonus.go
models/bonus.go
+22
-21
bonus_detail.go
models/bonus_detail.go
+13
-9
user.go
models/user.go
+14
-0
bonus.go
routers/h5/bonus.go
+2
-2
user_bank_card.go
routers/h5/user_bank_card.go
+19
-0
router.go
routers/router.go
+3
-0
bonus_service.go
service/bonus_detail_service/bonus_service.go
+23
-5
bonus_service.go
service/bonus_service/bonus_service.go
+5
-0
No files found.
main.go
View file @
37425a2d
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"slg/models"
"slg/models"
//"slg/pkg/cron"
"slg/pkg/gredis"
"slg/pkg/gredis"
"slg/pkg/setting"
"slg/pkg/setting"
"slg/pkg/util"
"slg/pkg/util"
...
...
middleware/auth/auth.go
0 → 100644
View file @
37425a2d
package
auth
import
(
"github.com/gin-gonic/gin"
"slg/pkg/e"
"slg/models"
"slg/pkg/handler"
"slg/pkg/errno"
)
func
AUTH
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
var
code
int
code
=
e
.
SUCCESS
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
if
token
==
""
{
code
=
e
.
INVALID_PARAMS
}
else
{
_
,
err
:=
models
.
CheckToken
(
token
)
if
err
!=
nil
{
code
=
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
}
}
if
code
!=
e
.
SUCCESS
{
handler
.
SendResponse
(
c
,
errno
.
PermissionDenied
,
nil
)
c
.
Abort
()
return
}
c
.
Next
()
}
}
models/bonus.go
View file @
37425a2d
...
@@ -43,6 +43,16 @@ func Exist(oid string) (*Bonus, error) {
...
@@ -43,6 +43,16 @@ func Exist(oid string) (*Bonus, error) {
* @return
* @return
*/
*/
func
AddBonus
(
data
map
[
string
]
interface
{})
error
{
func
AddBonus
(
data
map
[
string
]
interface
{})
error
{
tx
:=
db
.
Begin
()
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
tx
.
Rollback
()
}
}()
if
err
:=
tx
.
Error
;
err
!=
nil
{
return
err
}
bonus
:=
Bonus
{
bonus
:=
Bonus
{
Oid
:
data
[
"oid"
]
.
(
string
),
Oid
:
data
[
"oid"
]
.
(
string
),
MerchantId
:
data
[
"merchant_id"
]
.
(
string
),
MerchantId
:
data
[
"merchant_id"
]
.
(
string
),
...
@@ -59,17 +69,6 @@ func AddBonus(data map[string]interface{}) error {
...
@@ -59,17 +69,6 @@ func AddBonus(data map[string]interface{}) error {
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
}
}
tx
:=
db
.
Begin
()
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
tx
.
Rollback
()
}
}()
if
err
:=
tx
.
Error
;
err
!=
nil
{
return
err
}
if
err
:=
tx
.
Debug
()
.
Create
(
&
bonus
)
.
Error
;
err
!=
nil
{
if
err
:=
tx
.
Debug
()
.
Create
(
&
bonus
)
.
Error
;
err
!=
nil
{
tx
.
Rollback
()
tx
.
Rollback
()
return
err
return
err
...
@@ -77,11 +76,12 @@ func AddBonus(data map[string]interface{}) error {
...
@@ -77,11 +76,12 @@ func AddBonus(data map[string]interface{}) error {
if
data
[
"invite_uid"
]
!=
""
{
if
data
[
"invite_uid"
]
!=
""
{
bonusDetail
:=
BonusDetail
{
bonusDetail
:=
BonusDetail
{
Uid
:
data
[
"invite_uid"
]
.
(
string
),
Uid
:
data
[
"invite_uid"
]
.
(
string
),
BonusAmount
:
data
[
"invite_bonus_amount"
]
.
(
string
),
BonusAmount
:
data
[
"invite_bonus_amount"
]
.
(
string
),
BonusType
:
Invite
,
BonusProportion
:
data
[
"invite_proportion"
]
.
(
string
),
CreateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
BonusType
:
Invite
,
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
CreateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
}
}
if
err
:=
tx
.
Debug
()
.
Table
(
"bonus_detail"
)
.
Create
(
&
bonusDetail
)
.
Error
;
err
!=
nil
{
if
err
:=
tx
.
Debug
()
.
Table
(
"bonus_detail"
)
.
Create
(
&
bonusDetail
)
.
Error
;
err
!=
nil
{
tx
.
Rollback
()
tx
.
Rollback
()
...
@@ -119,11 +119,12 @@ func AddBonus(data map[string]interface{}) error {
...
@@ -119,11 +119,12 @@ func AddBonus(data map[string]interface{}) error {
if
data
[
"share_uid"
]
!=
""
{
if
data
[
"share_uid"
]
!=
""
{
bonusDetail
:=
BonusDetail
{
bonusDetail
:=
BonusDetail
{
Uid
:
data
[
"share_uid"
]
.
(
string
),
Uid
:
data
[
"share_uid"
]
.
(
string
),
BonusAmount
:
data
[
"share_bonus_amount"
]
.
(
string
),
BonusAmount
:
data
[
"share_bonus_amount"
]
.
(
string
),
BonusType
:
Share
,
BonusProportion
:
data
[
"share_proportion"
]
.
(
string
),
CreateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
BonusType
:
Share
,
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
CreateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
UpdateTime
:
time
.
Now
()
.
UTC
()
.
Unix
(),
}
}
if
err
:=
tx
.
Debug
()
.
Table
(
"bonus_detail"
)
.
Create
(
&
bonusDetail
)
.
Error
;
err
!=
nil
{
if
err
:=
tx
.
Debug
()
.
Table
(
"bonus_detail"
)
.
Create
(
&
bonusDetail
)
.
Error
;
err
!=
nil
{
tx
.
Rollback
()
tx
.
Rollback
()
...
...
models/bonus_detail.go
View file @
37425a2d
...
@@ -3,23 +3,27 @@ package models
...
@@ -3,23 +3,27 @@ package models
import
"github.com/jinzhu/gorm"
import
"github.com/jinzhu/gorm"
const
Invite
=
1
//邀请
const
Invite
=
1
//邀请
const
Share
=
2
//分享
const
Share
=
2
//分享
const
Redraw
=
3
//提取
const
Redraw
=
3
//提取
type
BonusDetail
struct
{
type
BonusDetail
struct
{
Model
Model
Uid
string
`json:"uid"`
Uid
string
`json:"uid"`
BonusAmount
string
`json:"bonus_amount"`
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
BonusType
uint8
`json:"bonus_type"`
CreateTime
int64
`json:"create_time"`
BonusProportion
string
`json:"bonus_proportion"`
UpdateTime
int64
`json:"update_time"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
}
}
type
BonusDetailResp
struct
{
type
BonusDetailResp
struct
{
BonusAmount
string
`json:"bonus_amount"`
Describe
string
`json:"describe"`
BonusType
uint8
`json:"bonus_type"`
BonusProportion
string
`json:"bonus_proportion"`
CreateTime
string
`json:"create_time"`
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
Remart
string
`json:"remart"`
CreateTime
string
`json:"create_time"`
}
}
func
GetBonusDetailCount
(
conditions
interface
{})
(
int
,
error
)
{
func
GetBonusDetailCount
(
conditions
interface
{})
(
int
,
error
)
{
...
...
models/user.go
View file @
37425a2d
...
@@ -40,3 +40,17 @@ func GetUserInfos(conditions interface{}) ([]*User, error) {
...
@@ -40,3 +40,17 @@ func GetUserInfos(conditions interface{}) ([]*User, error) {
return
users
,
nil
return
users
,
nil
}
}
/**
* 通过uid获取用户信息
* @return
*/
func
CheckToken
(
token
string
)
(
bool
,
error
)
{
var
user
User
err
:=
db
.
Select
(
"uid"
)
.
Where
(
"token = ?"
,
token
)
.
First
(
&
user
)
.
Error
if
err
!=
nil
{
return
false
,
err
}
return
true
,
nil
}
routers/h5/bonus.go
View file @
37425a2d
...
@@ -26,10 +26,10 @@ func GetBonusStatistics(c *gin.Context) {
...
@@ -26,10 +26,10 @@ func GetBonusStatistics(c *gin.Context) {
func
GetBonusDetailList
(
c
*
gin
.
Context
)
{
func
GetBonusDetailList
(
c
*
gin
.
Context
)
{
var
uid
=
"c420fb06d76b4fd09050579ab175cff0"
var
uid
=
"c420fb06d76b4fd09050579ab175cff0"
var
bonus_type
=
1
bonus_type
:=
c
.
DefaultQuery
(
"bonus_type"
,
"0"
)
bonusDetailService
:=
bonus_detail_service
.
BonusDetailService
{
bonusDetailService
:=
bonus_detail_service
.
BonusDetailService
{
Uid
:
uid
,
Uid
:
uid
,
BonusType
:
uint8
(
bonus_type
),
BonusType
:
uint8
(
util
.
ToUint
(
bonus_type
)
),
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
...
...
routers/h5/user_bank_card.go
View file @
37425a2d
...
@@ -10,6 +10,25 @@ import (
...
@@ -10,6 +10,25 @@ import (
"slg/service/user_bank_card_service"
"slg/service/user_bank_card_service"
)
)
func
GetBankCard
(
c
*
gin
.
Context
)
{
var
userBankCardService
user_bank_card_service
.
UserBankCardService
userBankCardService
.
Uid
=
"16a6220e5ed643afa552b8364fd90fdd"
//exists, _ := userBankCardService.ExistBankCard()
//if !exists {
// handler.SendResponse(c, errno.ErrBankCardNotFound, nil)
// return
//}
user_bank_card
,
err
:=
userBankCardService
.
GetUserBankCardInfo
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrAddBankCard
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
user_bank_card
)
return
}
func
BindBankCard
(
c
*
gin
.
Context
)
{
func
BindBankCard
(
c
*
gin
.
Context
)
{
var
bank_card
validate_service
.
BindBankCardReq
var
bank_card
validate_service
.
BindBankCardReq
_
=
c
.
ShouldBindJSON
(
&
bank_card
)
_
=
c
.
ShouldBindJSON
(
&
bank_card
)
...
...
routers/router.go
View file @
37425a2d
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"slg/routers/api/backend"
"slg/routers/api/backend"
"slg/routers/h5"
"slg/routers/h5"
"slg/middleware/auth"
)
)
func
InitRouter
()
*
gin
.
Engine
{
func
InitRouter
()
*
gin
.
Engine
{
...
@@ -12,9 +13,11 @@ func InitRouter() *gin.Engine {
...
@@ -12,9 +13,11 @@ func InitRouter() *gin.Engine {
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
gin
.
Recovery
())
client
:=
r
.
Group
(
"/h5"
)
client
:=
r
.
Group
(
"/h5"
)
client
.
Use
(
auth
.
AUTH
())
client
.
GET
(
"/bonus-statistics"
,
h5
.
GetBonusStatistics
)
client
.
GET
(
"/bonus-statistics"
,
h5
.
GetBonusStatistics
)
client
.
GET
(
"/bonus-detail-list"
,
h5
.
GetBonusDetailList
)
client
.
GET
(
"/bonus-detail-list"
,
h5
.
GetBonusDetailList
)
client
.
GET
(
"/bank-card"
,
h5
.
GetBankCard
)
client
.
POST
(
"/bind-bank-card"
,
h5
.
BindBankCard
)
client
.
POST
(
"/bind-bank-card"
,
h5
.
BindBankCard
)
api
:=
r
.
Group
(
"/api"
)
api
:=
r
.
Group
(
"/api"
)
...
...
service/bonus_detail_service/bonus_service.go
View file @
37425a2d
...
@@ -6,11 +6,12 @@ import (
...
@@ -6,11 +6,12 @@ import (
)
)
type
BonusDetailService
struct
{
type
BonusDetailService
struct
{
Uid
string
`json:"uid"`
Uid
string
`json:"uid"`
BonusAmount
string
`json:"bonus_amount"`
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
BonusType
uint8
`json:"bonus_type"`
CreateTime
int64
`json:"create_time"`
BonusProportion
string
`json:"bonus_proportion"`
UpdateTime
int64
`json:"update_time"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
PageNum
int
PageNum
int
PageSize
int
PageSize
int
...
@@ -42,6 +43,19 @@ func (b *BonusDetailService) GetBonusDetailList() ([]*models.BonusDetailResp, er
...
@@ -42,6 +43,19 @@ func (b *BonusDetailService) GetBonusDetailList() ([]*models.BonusDetailResp, er
for
_
,
value
:=
range
bonusDetailList
{
for
_
,
value
:=
range
bonusDetailList
{
record
:=
&
models
.
BonusDetailResp
{}
record
:=
&
models
.
BonusDetailResp
{}
if
value
.
BonusType
==
models
.
Invite
{
record
.
Describe
=
"邀请注册佣金收益"
record
.
Remart
=
"存入我的奖励账户"
}
if
value
.
BonusType
==
models
.
Share
{
record
.
Describe
=
"推广分销佣金收益"
record
.
Remart
=
"存入我的奖励账户"
}
if
value
.
BonusType
==
models
.
Redraw
{
record
.
Describe
=
"零钱提现"
record
.
Remart
=
"提现到银行卡"
}
record
.
BonusProportion
=
value
.
BonusProportion
record
.
BonusAmount
=
value
.
BonusAmount
record
.
BonusAmount
=
value
.
BonusAmount
record
.
BonusType
=
value
.
BonusType
record
.
BonusType
=
value
.
BonusType
record
.
CreateTime
=
util
.
FormatUnix
(
value
.
CreateTime
)
record
.
CreateTime
=
util
.
FormatUnix
(
value
.
CreateTime
)
...
@@ -59,5 +73,9 @@ func (b *BonusDetailService) getBonusDetailCondition() map[string]interface{} {
...
@@ -59,5 +73,9 @@ func (b *BonusDetailService) getBonusDetailCondition() map[string]interface{} {
conditions
[
"uid"
]
=
b
.
Uid
conditions
[
"uid"
]
=
b
.
Uid
}
}
if
b
.
BonusType
!=
0
{
conditions
[
"bonus_type"
]
=
b
.
BonusType
}
return
conditions
return
conditions
}
}
service/bonus_service/bonus_service.go
View file @
37425a2d
...
@@ -212,14 +212,19 @@ func (b *BonusService) SettlementBonus() error {
...
@@ -212,14 +212,19 @@ func (b *BonusService) SettlementBonus() error {
"update_time"
:
time
.
Now
()
.
UTC
()
.
Unix
(),
"update_time"
:
time
.
Now
()
.
UTC
()
.
Unix
(),
"merchant_id"
:
merchant_uid
,
"merchant_id"
:
merchant_uid
,
"merchant_bonus_amount"
:
merchant_bonus_amount
,
"merchant_bonus_amount"
:
merchant_bonus_amount
,
"merchant_proportion"
:
util
.
ToString
(
merchant
),
"author_uid"
:
author_uid
,
"author_uid"
:
author_uid
,
"author_bonus_amount"
:
author_bonus_amount
,
"author_bonus_amount"
:
author_bonus_amount
,
"author_proportion"
:
util
.
ToString
(
author
),
"invite_uid"
:
invite_uid
,
"invite_uid"
:
invite_uid
,
"invite_bonus_amount"
:
invite_bonus_amount
,
"invite_bonus_amount"
:
invite_bonus_amount
,
"invite_proportion"
:
util
.
ToString
(
invite
),
"share_uid"
:
share_uid
,
"share_uid"
:
share_uid
,
"share_bonus_amount"
:
share_bonus_amount
,
"share_bonus_amount"
:
share_bonus_amount
,
"share_proportion"
:
util
.
ToString
(
share
),
"platform_uid"
:
platform_uid
,
"platform_uid"
:
platform_uid
,
"platform_bonus_amount"
:
platform_bonus_amount
,
"platform_bonus_amount"
:
platform_bonus_amount
,
"platform_proportion"
:
util
.
ToString
(
platform
),
}
}
tmp
,
_
:=
json
.
Marshal
(
bonus
)
tmp
,
_
:=
json
.
Marshal
(
bonus
)
...
...
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