business_bonus_controller.go
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package controllers
import (
"errors"
"github.com/astaxie/beego/logs"
businessCommand "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command"
businessQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query"
businessService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type BusinessBonusController struct {
BaseController
}
func (c *BusinessBonusController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
return
}
}
func (c *BusinessBonusController) ListBusinessBonus() {
type Parameter struct {
PageNumber int `json:"pageNumber"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
SearchText string `json:"searchText"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageSize == 0 {
param.PageSize = 20
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
companyId := c.GetUserCompany()
srv := businessService.NewBusinessBonusService(nil)
cnt, result, err := srv.ListBusinessBonus(businessQuery.ListBusinessBonusQuery{
CompanyId: companyId,
Limit: param.PageSize,
Offset: param.PageSize * (param.PageNumber - 1),
})
if err != nil {
c.ResponseError(err)
return
}
c.ResponsePageList(result, cnt, param.PageNumber)
}
func (c *BusinessBonusController) UpdateBusinessBonus() {
type Parameter struct {
Id int64 `json:"id"`
DividendsReceivable string `json:"dividendsReceivable"`
StateOfPayment string `json:"stateOfPayment"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
companyId := c.GetUserCompany()
srv := businessService.NewBusinessBonusService(nil)
err = srv.UpdateBusinessBonus(businessCommand.UpdateBusinessBonusCommand{
CompanyId: companyId,
})
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
}
func (c *BusinessBonusController) GetBusinessBonus() {
type Parameter struct {
Id int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
companyId := c.GetUserCompany()
srv := businessService.NewBusinessBonusService(nil)
data, err := srv.GetBusinessBonus(businessQuery.GetBusinessBonusQuery{
Id: param.Id,
CompanyId: companyId,
})
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(data)
}