dividends_controller.go
7.9 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package controllers
import (
"errors"
"fmt"
"github.com/astaxie/beego/logs"
OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
OrderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
OrderSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
PartnerInfoQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
PartnerInfoSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"strconv"
)
type DividendsController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *DividendsController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
return
}
}
//Edit 编辑分红支付
func (c *DividendsController) Edit() {
//用与适配前端定义的数据结构
type DividendPaymentItem struct {
PaymentForGoods float64 `json:"paymentForGoods"`
StateOfPayment int `json:"stateOfPayment"`
Id int `json:"id"`
}
type Parameter struct {
Id string `json:"id"` //订单编号
DividendPayment []DividendPaymentItem `json:"dividendPayment"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if len(param.Id) == 0 {
c.ResponseError(errors.New("id is empty"))
return
}
orderId, _ := strconv.ParseInt(param.Id, 10, 64)
cmd := OrderPaymentCmd.CreateOrderPaymentCommand{
OrderId: orderId,
DivdendPaymentItem: make([]OrderPaymentCmd.DivdendPyamentItem, 0),
}
//编辑
for i := range param.DividendPayment {
item := param.DividendPayment[i]
paymentItem := OrderPaymentCmd.DivdendPyamentItem{}
paymentItem.PaymentForGoods = item.PaymentForGoods
paymentItem.StateOfPayment = item.StateOfPayment
paymentItem.PaymentSn = i + 1
paymentItem.PaymentId = item.Id
if paymentItem.StateOfPayment == domain.BonusPaid {
cmd.TotalPaymentAmount += paymentItem.PaymentForGoods
}
cmd.DivdendPaymentItem = append(cmd.DivdendPaymentItem, paymentItem)
}
serve := OrderPaymentSvr.NewOrderPaymentService(nil)
_, err = serve.CreateOrderPayment(&cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//Edit 分红支付详情
func (c *DividendsController) Detail() {
type Parameter struct {
Id string `json:"id"` //订单编号
}
var (
param Parameter
err error
order *domain.Order
partner *domain.PartnerInfo
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := OrderPaymentQuery.GetOrderPaymentQuery{}
cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64)
var (
OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil)
OrderSvr = OrderSvr.NewOrderService(nil)
PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil)
)
var data []*domain.OrderPayment
data, err = OrderPaymentSvr.ListOrderPayment(&cmd)
if err != nil {
c.ResponseError(err)
return
}
if order, err = OrderSvr.GetOrder(OrderQuery.GetOrderQuery{OrderId: cmd.OrderId}); err != nil {
c.ResponseError(err)
return
}
if partner, err = PartnerInfoSvr.GetPartnerInfo(PartnerInfoQuery.GetPartnerInfoQuery{Id: order.PartnerInfo.Id}); err != nil {
c.ResponseError(err)
return
}
type DividendPayment struct {
PaymentForGoods float64 `json:"paymentForGoods"`
UpdateTime string `json:"updateTime"`
StateOfPayment int `json:"stateOfPayment"`
Dividend float64 `json:"dividend"`
DividendProportion float64 `json:"dividendProportion"`
Id int64 `json:"id"`
}
type Order struct {
OrderNumber string `json:"orderNumber"` //订单号
OrderState int `json:"orderState"` //订单状态
CreateTime string `json:"createTime"` //订单创建时间
OrderName string `json:"orderName"` //订单名称
OrderNum string `json:"orderNum"` //订单数量
OrderAmount string `json:"orderAmount"` //订单金额
Id string `json:"id"` //订单编号
}
type Partner struct {
PartnerName string `json:"partnerName"` //合伙人姓名
DividendProportion float64 `json:"dividendProportion"` //分红比例
DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
DividendSpending float64 `json:"dividendSpending"` //分红支出
ReceiveDividends float64 `json:"receiveDividends"` //实收分红
NotReceivedDividends float64 `json:"notReceivedDividends"` //未收分红
RceivedDividends float64 `json:"receivedDividends"` //已收分红
}
type Commission struct {
SalesmanName string `json:"salesmanName"` //业务员名称
CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
ExpectedCommission float64 `json:"expectedCommission"` //业务员预计抽成
}
type Response struct {
DividendPayment []DividendPayment `json:"dividendPayment"`
Order Order `json:"order"`
Partner Partner `json:"partner"`
Commission Commission `json:"commission"`
}
rsp := Response{DividendPayment: make([]DividendPayment, 0)}
for i := range data {
item := data[i]
payment := DividendPayment{
PaymentForGoods: item.PaymentAmount,
UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
StateOfPayment: item.BonusStatus,
Dividend: utils.Decimal(item.PaymentAmount * (order.PartnerBonusPercent / 100.0)),
DividendProportion: order.PartnerBonusPercent,
Id: item.Id,
}
rsp.DividendPayment = append(rsp.DividendPayment, payment)
}
rsp.Order = Order{
OrderNumber: order.OrderCode,
OrderState: order.OrderStatus,
CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
OrderName: order.OrderName,
OrderNum: fmt.Sprintf("%v", order.OrderCount),
OrderAmount: fmt.Sprintf("%v", order.OrderAmount),
Id: fmt.Sprintf("%v", order.Id),
}
rsp.Partner = Partner{
PartnerName: partner.Partner.PartnerName,
DividendProportion: order.PartnerBonusPercent,
DividendsReceivable: order.OrderTotalBonus() + order.OrderBonusOutstanding(), //应收分红 = 实收分红+分红支出
DividendSpending: order.OrderBonusOutstanding(), //分红支出
ReceiveDividends: order.OrderBonusReceive() + order.OrderBonusWait(), //应实收分红 = 已收分红 + 等待分红
NotReceivedDividends: order.OrderBonusWait(), //未收分红
RceivedDividends: order.OrderBonusReceive(),
}
rsp.Commission = Commission{
CommissionProportion: order.SalesmanBonusPercent,
ExpectedCommission: utils.Decimal(order.OrderActualAmount * (order.SalesmanBonusPercent / 100)),
}
if len(partner.Salesman) > 0 {
rsp.Commission.SalesmanName = partner.Salesman[0].Name
}
c.ResponseData(rsp)
return
}
//分红管理
func (c *DividendsController) List() {
var (
param OrderPaymentQuery.ListDividendOrdersQuery
err error
count int
)
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
}
serve := OrderPaymentSvr.NewOrderPaymentService(nil)
var data interface{}
count, data, err = serve.ListDividendOrders(¶m)
if err != nil {
c.ResponseError(err)
return
}
c.ResponsePageList(data, count, param.PageNumber)
return
}