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
68ac34a5
Commit
68ac34a5
authored
Apr 28, 2022
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
h5 bonus init
parent
a672986c
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
351 additions
and
13 deletions
+351
-13
bonus.go
models/bonus.go
+19
-0
bonus_detail.go
models/bonus_detail.go
+38
-0
bonus_statistics.go
models/bonus_statistics.go
+27
-0
errno.go
pkg/errno/errno.go
+6
-5
setting.go
pkg/setting/setting.go
+1
-1
bonus.go
routers/api/backend/bonus.go
+45
-4
bonus.go
routers/h5/bonus.go
+56
-0
router.go
routers/router.go
+4
-1
bonus_service.go
service/bonus_detail_service/bonus_service.go
+63
-0
bonus_service.go
service/bonus_service/bonus_service.go
+60
-2
bonus_service.go
service/bonus_statistics_service/bonus_service.go
+32
-0
No files found.
models/bonus.go
View file @
68ac34a5
...
@@ -65,3 +65,22 @@ func AddBonus(data map[string]interface{}) error {
...
@@ -65,3 +65,22 @@ func AddBonus(data map[string]interface{}) error {
return
nil
return
nil
}
}
func
GetCount
(
conditions
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Model
(
&
Bonus
{})
.
Where
(
conditions
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
func
GetBonus
(
pageNum
,
pageSize
int
,
conditions
interface
{})
([]
*
Bonus
,
error
)
{
var
bonus
[]
*
Bonus
err
:=
db
.
Debug
()
.
Where
(
conditions
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
bonus
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
bonus
,
nil
}
models/bonus_detail.go
0 → 100644
View file @
68ac34a5
package
models
import
"github.com/jinzhu/gorm"
type
BonusDetail
struct
{
Model
Uid
string
`json:"uid"`
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
}
type
BonusDetailResp
struct
{
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
CreateTime
string
`json:"create_time"`
}
func
GetBonusDetailCount
(
conditions
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Model
(
&
BonusDetail
{})
.
Where
(
conditions
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
func
GetBonusDetailList
(
pageNum
,
pageSize
int
,
conditions
interface
{})
([]
*
BonusDetail
,
error
)
{
var
bonusDetail
[]
*
BonusDetail
err
:=
db
.
Debug
()
.
Where
(
conditions
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
bonusDetail
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
bonusDetail
,
nil
}
models/bonus_statistics.go
0 → 100644
View file @
68ac34a5
package
models
type
BonusStatistics
struct
{
Model
Uid
string
`json:"uid"`
InviteBonusAmount
string
`json:"invite_bonus_amount"`
ShareBonusAmount
string
`json:"share_bonus_amount"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
}
type
BonusStatisticsResp
struct
{
BonusAmount
string
`json:"bonus_amount"`
InviteBonusAmount
string
`json:"invite_bonus_amount"`
ShareBonusAmount
string
`json:"share_bonus_amount"`
}
func
GetBonusStatistics
(
uid
string
)
(
*
BonusStatistics
,
error
)
{
var
bonusStatistics
BonusStatistics
err
:=
db
.
Debug
()
.
Where
(
"uid = ?"
,
uid
)
.
First
(
&
bonusStatistics
)
.
Error
if
err
!=
nil
{
return
nil
,
err
}
return
&
bonusStatistics
,
nil
}
pkg/errno/errno.go
View file @
68ac34a5
...
@@ -66,9 +66,10 @@ var (
...
@@ -66,9 +66,10 @@ var (
PermissionDenied
=
&
Errno
{
Code
:
403
,
Message
:
"Permission Denied"
}
PermissionDenied
=
&
Errno
{
Code
:
403
,
Message
:
"Permission Denied"
}
// bank errors
//Bonus errors
ErrBankNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"银行账号绑定未找到."
}
ErrBonusNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"佣金记录未找到."
}
ErrAddBank
=
&
Errno
{
Code
:
20102
,
Message
:
"银行账号绑定失败."
}
ErrAddBonus
=
&
Errno
{
Code
:
20102
,
Message
:
"佣金添加失败."
}
ErrUpdateBank
=
&
Errno
{
Code
:
20103
,
Message
:
"银行账号更新失败."
}
ErrUpdateBonus
=
&
Errno
{
Code
:
20103
,
Message
:
"佣金更新失败."
}
ErrDeleteBank
=
&
Errno
{
Code
:
20104
,
Message
:
"银行账号删除失败."
}
ErrDeleteBonus
=
&
Errno
{
Code
:
20104
,
Message
:
"佣金删除失败."
}
ErrCountBonus
=
&
Errno
{
Code
:
20105
,
Message
:
"佣金统计失败."
}
)
)
pkg/setting/setting.go
View file @
68ac34a5
...
@@ -86,7 +86,7 @@ func Setup() {
...
@@ -86,7 +86,7 @@ func Setup() {
log
.
Fatalf
(
"setting.Setup, fail to parse 'conf/h5.ini': %v"
,
err
)
log
.
Fatalf
(
"setting.Setup, fail to parse 'conf/h5.ini': %v"
,
err
)
}
}
mapTo
(
"
h5
"
,
AppSetting
)
mapTo
(
"
app
"
,
AppSetting
)
mapTo
(
"server"
,
ServerSetting
)
mapTo
(
"server"
,
ServerSetting
)
mapTo
(
"database"
,
DatabaseSetting
)
mapTo
(
"database"
,
DatabaseSetting
)
mapTo
(
"redis"
,
RedisSetting
)
mapTo
(
"redis"
,
RedisSetting
)
...
...
routers/api/backend/bonus.go
View file @
68ac34a5
package
backend
package
backend
import
(
import
(
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"slg/pkg/errno"
"slg/pkg/handler"
"slg/pkg/handler"
"slg/pkg/util"
"slg/service/bonus_service"
)
)
func
GetBonus
(
c
*
gin
.
Context
){
func
GetBonus
(
c
*
gin
.
Context
)
{
var
oid
string
if
arg
:=
c
.
Query
(
"oid"
);
arg
!=
""
{
oid
=
c
.
Query
(
"oid"
)
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
var
merchant_id
string
if
arg
:=
c
.
Query
(
"merchant_id"
);
arg
!=
""
{
merchant_id
=
c
.
Query
(
"merchant_id"
)
}
var
status
uint8
if
arg
:=
c
.
Query
(
"status"
);
arg
!=
""
{
status
=
uint8
(
util
.
ToUint32
(
c
.
Query
(
"status"
)))
}
fmt
.
Println
(
merchant_id
)
bonusService
:=
bonus_service
.
BonusService
{
Oid
:
oid
,
MerchantId
:
merchant_id
,
Status
:
status
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
count
,
err
:=
bonusService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountBonus
,
nil
)
return
}
bonus
,
err
:=
bonusService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
bonus
data
[
"total"
]
=
count
handler
.
SendResponse
(
c
,
nil
,
data
)
return
return
}
}
\ No newline at end of file
routers/h5/bonus.go
0 → 100644
View file @
68ac34a5
package
h5
import
(
"github.com/gin-gonic/gin"
"slg/pkg/errno"
"slg/pkg/handler"
"slg/pkg/util"
"slg/service/bonus_detail_service"
"slg/service/bonus_statistics_service"
)
func
GetBonusStatistics
(
c
*
gin
.
Context
)
{
bonusStatisticsService
:=
bonus_statistics_service
.
BonusStatisticsService
{
Uid
:
"c420fb06d76b4fd09050579ab175cff0"
,
}
bonusStatistics
,
err
:=
bonusStatisticsService
.
GetBonusStatistics
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
bonusStatistics
)
return
}
func
GetBonusDetailList
(
c
*
gin
.
Context
)
{
var
uid
=
"c420fb06d76b4fd09050579ab175cff0"
var
bonus_type
=
1
bonusDetailService
:=
bonus_detail_service
.
BonusDetailService
{
Uid
:
uid
,
BonusType
:
uint8
(
bonus_type
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
count
,
err
:=
bonusDetailService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountBonus
,
nil
)
return
}
bonusDetailList
,
err
:=
bonusDetailService
.
GetBonusDetailList
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
bonusDetailList
data
[
"total"
]
=
count
handler
.
SendResponse
(
c
,
nil
,
data
)
return
}
routers/router.go
View file @
68ac34a5
...
@@ -3,6 +3,7 @@ package routers
...
@@ -3,6 +3,7 @@ package routers
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"slg/routers/api/backend"
"slg/routers/api/backend"
"slg/routers/h5"
)
)
func
InitRouter
()
*
gin
.
Engine
{
func
InitRouter
()
*
gin
.
Engine
{
...
@@ -10,7 +11,9 @@ func InitRouter() *gin.Engine {
...
@@ -10,7 +11,9 @@ func InitRouter() *gin.Engine {
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
gin
.
Recovery
())
//client := r.Group("/h5")
client
:=
r
.
Group
(
"/h5"
)
client
.
GET
(
"/bonus-statistics"
,
h5
.
GetBonusStatistics
)
client
.
GET
(
"/bonus-detail-list"
,
h5
.
GetBonusDetailList
)
api
:=
r
.
Group
(
"/api"
)
api
:=
r
.
Group
(
"/api"
)
api
.
GET
(
"/bonus-list"
,
backend
.
GetBonus
)
api
.
GET
(
"/bonus-list"
,
backend
.
GetBonus
)
...
...
service/bonus_detail_service/bonus_service.go
0 → 100644
View file @
68ac34a5
package
bonus_detail_service
import
(
"slg/models"
"slg/pkg/util"
)
type
BonusDetailService
struct
{
Uid
string
`json:"uid"`
BonusAmount
string
`json:"bonus_amount"`
BonusType
uint8
`json:"bonus_type"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
PageNum
int
PageSize
int
}
/**
* 获取符合条件的信息总数
* @params
* @return
*/
func
(
b
*
BonusDetailService
)
Count
()
(
int
,
error
)
{
return
models
.
GetBonusDetailCount
(
b
.
getBonusDetailCondition
())
}
/**
* 获取符合条件的信息
* @param
* @return
*/
func
(
b
*
BonusDetailService
)
GetBonusDetailList
()
([]
*
models
.
BonusDetailResp
,
error
)
{
var
bonusDetailList
[]
*
models
.
BonusDetail
bonusDetailList
,
err
:=
models
.
GetBonusDetailList
(
b
.
PageNum
,
b
.
PageSize
,
b
.
getBonusDetailCondition
())
if
err
!=
nil
{
return
nil
,
err
}
var
records
=
[]
*
models
.
BonusDetailResp
{}
for
_
,
value
:=
range
bonusDetailList
{
record
:=
&
models
.
BonusDetailResp
{}
record
.
BonusAmount
=
value
.
BonusAmount
record
.
BonusType
=
value
.
BonusType
record
.
CreateTime
=
util
.
FormatUnix
(
value
.
CreateTime
)
records
=
append
(
records
,
record
)
}
return
records
,
nil
}
func
(
b
*
BonusDetailService
)
getBonusDetailCondition
()
map
[
string
]
interface
{}
{
conditions
:=
make
(
map
[
string
]
interface
{})
if
b
.
Uid
!=
""
{
conditions
[
"uid"
]
=
b
.
Uid
}
return
conditions
}
service/bonus_service/bonus_service.go
View file @
68ac34a5
...
@@ -17,7 +17,66 @@ import (
...
@@ -17,7 +17,66 @@ import (
)
)
type
BonusService
struct
{
type
BonusService
struct
{
Oid
string
`json:"oid"`
Oid
string
`json:"oid"`
MerchantId
string
`json:"merchant_id"`
MerchantBonusAmount
string
`json:"merchant_bonus_amount"`
AuthorUid
string
`json:"author_uid"`
AuthorBonusAmount
string
`json:"author_bonus_amount"`
InviteUid
string
`json:"invite_uid"`
InviteBonusAmount
string
`json:"invite_bonus_amount"`
ShareUid
string
`json:"share_uid"`
ShareBonusAmount
string
`json:"share_bonus_amount"`
PlatformUid
string
`json:"platform_uid"`
PlatformBonusAmount
string
`json:"platform_bonus_amount"`
Status
uint8
`json:"status"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
PageNum
int
PageSize
int
}
/**
* 获取符合条件的信息总数
* @params
* @return
*/
func
(
b
*
BonusService
)
Count
()
(
int
,
error
)
{
return
models
.
GetCount
(
b
.
getCondition
())
}
/**
* 获取符合条件的信息
* @param
* @return
*/
func
(
b
*
BonusService
)
GetAll
()
([]
*
models
.
Bonus
,
error
)
{
var
bonus
[]
*
models
.
Bonus
bonus
,
err
:=
models
.
GetBonus
(
b
.
PageNum
,
b
.
PageSize
,
b
.
getCondition
())
if
err
!=
nil
{
return
nil
,
err
}
return
bonus
,
nil
}
func
(
b
*
BonusService
)
getCondition
()
map
[
string
]
interface
{}
{
conditions
:=
make
(
map
[
string
]
interface
{})
if
b
.
Status
!=
0
{
conditions
[
"status"
]
=
b
.
Status
}
if
b
.
Oid
!=
""
{
conditions
[
"oid"
]
=
b
.
Oid
}
if
b
.
MerchantId
!=
""
{
conditions
[
"merchant_id"
]
=
b
.
MerchantId
}
return
conditions
}
}
/**
/**
...
@@ -40,7 +99,6 @@ func (b *BonusService) SettlementBonus() error {
...
@@ -40,7 +99,6 @@ func (b *BonusService) SettlementBonus() error {
invite
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Invite
invite
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Invite
share
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Share
share
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Share
platform
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Platform
platform
:=
conf
.
Bonus
.
Levels
[
"one"
]
.
Platform
fmt
.
Println
(
conf
.
Bonus
.
Levels
[
"one"
]
.
Merchant
)
bonus_info
,
err
:=
models
.
Exist
(
b
.
Oid
)
bonus_info
,
err
:=
models
.
Exist
(
b
.
Oid
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
service/bonus_statistics_service/bonus_service.go
0 → 100644
View file @
68ac34a5
package
bonus_statistics_service
import
(
"github.com/jinzhu/gorm"
"github.com/shopspring/decimal"
"slg/models"
)
type
BonusStatisticsService
struct
{
Uid
string
`json:"uid"`
InviteBonusAmount
string
`json:"invite_bonus_amount"`
ShareBonusAmount
string
`json:"share_bonus_amount"`
CreateTime
int64
`json:"create_time"`
UpdateTime
int64
`json:"update_time"`
}
func
(
b
*
BonusStatisticsService
)
GetBonusStatistics
()
(
*
models
.
BonusStatisticsResp
,
error
)
{
bonusStatistics
,
err
:=
models
.
GetBonusStatistics
(
b
.
Uid
)
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
var
record
=
models
.
BonusStatisticsResp
{}
record
.
InviteBonusAmount
=
bonusStatistics
.
InviteBonusAmount
record
.
ShareBonusAmount
=
bonusStatistics
.
ShareBonusAmount
invite_bonus_amount_tmp
,
_
:=
decimal
.
NewFromString
(
bonusStatistics
.
InviteBonusAmount
)
share_bonus_amount_tmp
,
_
:=
decimal
.
NewFromString
(
bonusStatistics
.
ShareBonusAmount
)
record
.
BonusAmount
=
invite_bonus_amount_tmp
.
Add
(
share_bonus_amount_tmp
)
.
Round
(
2
)
.
String
()
return
&
record
,
nil
}
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