dividends_order.go
7.5 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
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsOrder/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsOrder/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
// 分红订单实体对象
type DividendsOrderService struct {
}
// 创建分红订单实体对象
func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createDividendsOrderCommand *command.CreateDividendsOrderCommand) (interface{}, error) {
orderGoods := []allied_creation_cooperation.DividendsOrderGoodAdd{}
for _, v := range createDividendsOrderCommand.OrderGoods {
good := allied_creation_cooperation.DividendsOrderGoodAdd{
CooperationContractNumber: v.CooperationContractNumber,
DividendsOrderNumber: v.DividendsOrderNumber,
OrderGoodAmount: 0,
OrderGoodExpense: v.OrderGoodExpense,
OrderGoodName: v.OrderGoodName,
OrderGoodPrice: v.OrderGoodPrice,
OrderGoodQuantity: v.OrderGoodQuantity,
}
// orderGoodAmount := v.OrderGoodPrice*float64(v.OrderGoodQuantity) - v.OrderGoodExpense
// good.OrderGoodAmount = orderGoodAmount
orderGoods = append(orderGoods, good)
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createDividendsOrderCommand.Operator)
result, err := creationCooperationGateway.DividendsOrderAdd(allied_creation_cooperation.ReqDividendsOrderAdd{
CompanyId: int(createDividendsOrderCommand.Operator.CompanyId),
UserId: int(createDividendsOrderCommand.Operator.UserId),
CustomerName: createDividendsOrderCommand.CustomerName,
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
OperatorUid: int(createDividendsOrderCommand.Operator.UserId),
OrderTime: strconv.Itoa(int(createDividendsOrderCommand.OrderTime)),
Remarks: createDividendsOrderCommand.Remarks,
RegionName: createDividendsOrderCommand.RegionName,
OrderGoods: orderGoods,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dto.ToDividendsOrder(&result.DividendsOrder, createDividendsOrderCommand.Operator.OrgId), nil
}
// 返回分红订单实体对象
func (dividendsOrderService *DividendsOrderService) GetDividendsOrder(getDividendsOrderQuery *query.GetDividendsOrderQuery) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getDividendsOrderQuery.Operator)
result, err := creationCooperationGateway.DividendsOrderGet(allied_creation_cooperation.ReqDividendsOrderGet{
DividendsOrderId: getDividendsOrderQuery.DividendsOrderId,
DividendsOrderNumber: getDividendsOrderQuery.DividendsOrderNumber,
OrgId: getDividendsOrderQuery.OrgId,
CompanyId: int(getDividendsOrderQuery.Operator.CompanyId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dto.ToDividendsOrder(&result.DividendsOrder, getDividendsOrderQuery.Operator.OrgId), nil
}
// 移除分红订单实体对象
func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeDividendsOrderCommand *command.RemoveDividendsOrderCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(removeDividendsOrderCommand.Operator)
result, err := creationCooperationGateway.DividendsOrderBatchRemove(allied_creation_cooperation.ReqDividendsOrderBatchRemove{
DividendsOrderIds: removeDividendsOrderCommand.DividendsOrderId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 查询分红订单方法
func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (int, interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(searchDividendsOrderQuery.Operator)
result, err := creationCooperationGateway.DividendsOrderSearch(allied_creation_cooperation.ReqDividendsOrderSearch{
PageNumber: searchDividendsOrderQuery.PageNumber,
PageSize: searchDividendsOrderQuery.PageSize,
CustomerName: searchDividendsOrderQuery.CustomerName,
DividendsOrderNumber: searchDividendsOrderQuery.DividendsOrderNumber,
OrgIds: searchDividendsOrderQuery.Operator.OrgIds,
CompanyId: int(searchDividendsOrderQuery.Operator.CompanyId),
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
dataList := []dto.DividendsOrder{}
for i := range result.Grid.List {
item := dto.ToDividendsOrder(&result.Grid.List[i], searchDividendsOrderQuery.Operator.OrgId)
dataList = append(dataList, *item)
}
return result.Grid.Total, dataList, nil
}
// 更新分红订单实体对象
func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateDividendsOrderCommand *command.UpdateDividendsOrderCommand) (interface{}, error) {
orderGoods := []allied_creation_cooperation.DividendsOrderGoodAdd{}
for _, v := range updateDividendsOrderCommand.OrderGoods {
good := allied_creation_cooperation.DividendsOrderGoodAdd{
OrderGoodId: int64(v.OrderGoodId),
CooperationContractNumber: v.CooperationContractNumber,
DividendsOrderNumber: v.DividendsOrderNumber,
OrderGoodExpense: v.OrderGoodExpense,
OrderGoodAmount: 0,
OrderGoodName: v.OrderGoodName,
OrderGoodPrice: v.OrderGoodPrice,
OrderGoodQuantity: v.OrderGoodQuantity,
}
// orderGoodAmount := v.OrderGoodPrice*float64(v.OrderGoodQuantity) - v.OrderGoodExpense
// good.OrderGoodAmount = orderGoodAmount
orderGoods = append(orderGoods, good)
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(updateDividendsOrderCommand.Operator)
_, err := creationCooperationGateway.DividendsOrderUpdate(allied_creation_cooperation.ReqDividendsOrderUpdate{
DividendsOrderId: updateDividendsOrderCommand.DividendsOrderID,
CompanyId: int(updateDividendsOrderCommand.Operator.CompanyId),
CustomerName: updateDividendsOrderCommand.CustomerName,
DividendsOrderAmount: updateDividendsOrderCommand.DividendsOrderAmount,
DividendsOriginalOrderNum: updateDividendsOrderCommand.DividendsOriginalOrderNum,
OperatorUid: int(updateDividendsOrderCommand.Operator.UserId),
OrderTime: strconv.Itoa(int(updateDividendsOrderCommand.OrderTime)),
Remarks: updateDividendsOrderCommand.Remarks,
RegionName: updateDividendsOrderCommand.RegionName,
OrderGoods: orderGoods,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return updateDividendsOrderCommand, nil
}
func NewDividendsOrderService(options map[string]interface{}) *DividendsOrderService {
newDividendsOrderService := &DividendsOrderService{}
return newDividendsOrderService
}