Merge branch 'dev' into test
# Conflicts: # pkg/application/order/command/update_order.go # pkg/application/order/service/order.go # pkg/domain/order.go # pkg/infrastructure/repository/pg_order_repository.go # pkg/port/beego/controllers/order_controller.go
正在显示
20 个修改的文件
包含
0 行增加
和
2325 行删除
@@ -20,19 +20,3 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, | @@ -20,19 +20,3 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, | ||
20 | } | 20 | } |
21 | return dao.NewPartnerInfoDao(transactionContext) | 21 | return dao.NewPartnerInfoDao(transactionContext) |
22 | } | 22 | } |
23 | - | ||
24 | -func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) { | ||
25 | - var transactionContext *transaction.TransactionContext | ||
26 | - if value, ok := options["transactionContext"]; ok { | ||
27 | - transactionContext = value.(*transaction.TransactionContext) | ||
28 | - } | ||
29 | - return dao.NewOrderDao(transactionContext) | ||
30 | -} | ||
31 | - | ||
32 | -func CreateOrderPaymentDao(options map[string]interface{}) (*dao.OrderPayment, error) { | ||
33 | - var transactionContext *transaction.TransactionContext | ||
34 | - if value, ok := options["transactionContext"]; ok { | ||
35 | - transactionContext = value.(*transaction.TransactionContext) | ||
36 | - } | ||
37 | - return dao.NewOrderPayment(transactionContext) | ||
38 | -} |
@@ -33,24 +33,6 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | @@ -33,24 +33,6 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | ||
33 | return repository.NewAdminPermissionRepository(transactionContext) | 33 | return repository.NewAdminPermissionRepository(transactionContext) |
34 | } | 34 | } |
35 | 35 | ||
36 | -//CreateOrderPaymentRepository 分红单信息 | ||
37 | -func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) { | ||
38 | - var transactionContext *transaction.TransactionContext | ||
39 | - if value, ok := options["transactionContext"]; ok { | ||
40 | - transactionContext = value.(*transaction.TransactionContext) | ||
41 | - } | ||
42 | - return repository.NewOrderPaymentRepository(transactionContext) | ||
43 | -} | ||
44 | - | ||
45 | -//CreateOrderRepository 订单信息 | ||
46 | -func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) { | ||
47 | - var transactionContext *transaction.TransactionContext | ||
48 | - if value, ok := options["transactionContext"]; ok { | ||
49 | - transactionContext = value.(*transaction.TransactionContext) | ||
50 | - } | ||
51 | - return repository.NewOrderRepository(transactionContext) | ||
52 | -} | ||
53 | - | ||
54 | //CreateOrderBaseRepository 订单信息 | 36 | //CreateOrderBaseRepository 订单信息 |
55 | func CreateOrderBaseRepository(options map[string]interface{}) (domain.OrderBaseRepository, error) { | 37 | func CreateOrderBaseRepository(options map[string]interface{}) (domain.OrderBaseRepository, error) { |
56 | var transactionContext *transaction.TransactionContext | 38 | var transactionContext *transaction.TransactionContext |
1 | -package command | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
6 | -) | ||
7 | - | ||
8 | -type CreateOrderCommand struct { | ||
9 | - //订单区域 | ||
10 | - OrderRegion string | ||
11 | - //订单编号 | ||
12 | - OrderCode string `json:"orderCode"` | ||
13 | - //订单名称 | ||
14 | - OrderName string `json:"oderName"` | ||
15 | - //数量 | ||
16 | - OrderCount int `json:"orderCount"` | ||
17 | - //实际订单数量 | ||
18 | - OrderActualCount int `json:"orderActualCount"` | ||
19 | - //订单金额 | ||
20 | - OrderAmount float64 `json:"orderAmount"` | ||
21 | - //订单实际金额 | ||
22 | - OrderActualAmount float64 `json:"orderActualAmount"` | ||
23 | - //订单状态 | ||
24 | - OrderStatus int `json:"orderStatus"` | ||
25 | - //买家 | ||
26 | - BuyerName string `json:"buyerName"` | ||
27 | - //买家电话 | ||
28 | - BuyerPhone string `json:"buyerPhone"` | ||
29 | - //地址 | ||
30 | - BuyerAddress string `json:"address"` | ||
31 | - //合伙人数据 | ||
32 | - PartnerId int64 `json:"partId"` | ||
33 | - //合伙人分红百分比 | ||
34 | - PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
35 | - //业务员分红百分比 | ||
36 | - SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
37 | - //订单类型 | ||
38 | - OrderType int `json:"orderType"` | ||
39 | -} | ||
40 | - | ||
41 | -func (command CreateOrderCommand) ValidateCommand() error { | ||
42 | - if len(command.BuyerName) == 0 || len(command.BuyerPhone) == 0 { | ||
43 | - return lib.ThrowError(lib.ARG_ERROR, "买家信息必填") | ||
44 | - } | ||
45 | - if len(command.BuyerAddress) == 0 { | ||
46 | - return lib.ThrowError(lib.ARG_ERROR, "买家地址必填") | ||
47 | - } | ||
48 | - if len(command.OrderCode) == 0 { | ||
49 | - return lib.ThrowError(lib.ARG_ERROR, "订单编号必填") | ||
50 | - } | ||
51 | - if len(command.OrderRegion) == 0 { | ||
52 | - return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") | ||
53 | - } | ||
54 | - if !(command.OrderType == domain.OrderReal || | ||
55 | - command.OrderType == domain.OrderIntention) { | ||
56 | - return lib.ThrowError(lib.ARG_ERROR, "订单类型错误") | ||
57 | - } | ||
58 | - if !(command.OrderStatus == domain.OrderStatusDeliverSome || | ||
59 | - command.OrderStatus == domain.OrderStatusDeliverAll || | ||
60 | - command.OrderStatus == domain.OrderStatusReserve) { | ||
61 | - return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误") | ||
62 | - } | ||
63 | - return nil | ||
64 | -} |
1 | -package command | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
6 | -) | ||
7 | - | ||
8 | -type UpdateOrderCommand struct { | ||
9 | - //id | ||
10 | - Id int64 `json:"id"` | ||
11 | - //订单编号 | ||
12 | - OrderCode string `json:"orderCode"` | ||
13 | - //订单名称 | ||
14 | - OrderName string `json:"oderName"` | ||
15 | - //数量 | ||
16 | - OrderCount int `json:"orderCount"` | ||
17 | - //订单金额 | ||
18 | - OrderAmount float64 `json:"orderAmount"` | ||
19 | - //买家 | ||
20 | - BuyerPhone string `json:"buyerPhone"` | ||
21 | - //地址 | ||
22 | - BuyerAddress string `json:"address"` | ||
23 | - //订单区域 | ||
24 | - OrderRegion string `json:"orderRegion"` | ||
25 | - //合伙人分红百分比 | ||
26 | - PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
27 | - //业务员分红百分比 | ||
28 | - SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
29 | - //订单状态 | ||
30 | - OrderStatus int `json:"orderStatus"` | ||
31 | - //订单类型 | ||
32 | - OrderType int `json:"orderType"` | ||
33 | -} | ||
34 | - | ||
35 | -func (command UpdateOrderCommand) ValidateCommand() error { | ||
36 | - if command.Id == 0 { | ||
37 | - return lib.ThrowError(lib.ARG_ERROR, "订单id错误") | ||
38 | - } | ||
39 | - if len(command.BuyerPhone) == 0 { | ||
40 | - return lib.ThrowError(lib.ARG_ERROR, "买家信息必填") | ||
41 | - } | ||
42 | - if len(command.BuyerAddress) == 0 { | ||
43 | - return lib.ThrowError(lib.ARG_ERROR, "买家地址必填") | ||
44 | - } | ||
45 | - if len(command.OrderCode) == 0 { | ||
46 | - return lib.ThrowError(lib.ARG_ERROR, "订单编号必填") | ||
47 | - } | ||
48 | - if len(command.OrderRegion) == 0 { | ||
49 | - return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") | ||
50 | - } | ||
51 | - if !(command.OrderType == domain.OrderReal || | ||
52 | - command.OrderType == domain.OrderIntention) { | ||
53 | - return lib.ThrowError(lib.ARG_ERROR, "订单类型错误") | ||
54 | - } | ||
55 | - if !(command.OrderStatus == domain.OrderStatusDeliverSome || | ||
56 | - command.OrderStatus == domain.OrderStatusDeliverAll || | ||
57 | - command.OrderStatus == domain.OrderStatusReserve) { | ||
58 | - return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误") | ||
59 | - } | ||
60 | - return nil | ||
61 | -} |
1 | -package command | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
6 | -) | ||
7 | - | ||
8 | -type UpdateOrderRealCommand struct { | ||
9 | - //id | ||
10 | - Id int64 `json:"id"` | ||
11 | - //订单编号 | ||
12 | - OrderCode string `json:"orderCode"` | ||
13 | - //订单名称 | ||
14 | - OrderName string `json:"oderName"` | ||
15 | - //数量 | ||
16 | - OrderActualCount int `json:"orderActualCount"` | ||
17 | - //订单金额 | ||
18 | - OrderActualAmount float64 `json:"orderActualAmount"` | ||
19 | - //买家 | ||
20 | - BuyerPhone string `json:"buyerPhone"` | ||
21 | - //地址 | ||
22 | - BuyerAddress string `json:"address"` | ||
23 | - //订单区域 | ||
24 | - OrderRegion string `json:"orderRegion"` | ||
25 | - //合伙人分红百分比 | ||
26 | - PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
27 | - //业务员分红百分比 | ||
28 | - SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
29 | - //状态 | ||
30 | - OrderStatus int `json:"orderStatus"` | ||
31 | - | ||
32 | - Reason string `json:"reason"` | ||
33 | -} | ||
34 | - | ||
35 | -func (command UpdateOrderRealCommand) ValidateCommand() error { | ||
36 | - if command.Id == 0 { | ||
37 | - return lib.ThrowError(lib.ARG_ERROR, "订单id错误") | ||
38 | - } | ||
39 | - if len(command.BuyerPhone) == 0 { | ||
40 | - return lib.ThrowError(lib.ARG_ERROR, "买家信息必填") | ||
41 | - } | ||
42 | - if len(command.BuyerAddress) == 0 { | ||
43 | - return lib.ThrowError(lib.ARG_ERROR, "买家地址必填") | ||
44 | - } | ||
45 | - if len(command.OrderCode) == 0 { | ||
46 | - return lib.ThrowError(lib.ARG_ERROR, "订单编号必填") | ||
47 | - } | ||
48 | - if len(command.OrderRegion) == 0 { | ||
49 | - return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") | ||
50 | - } | ||
51 | - if !(command.OrderStatus == domain.OrderStatusDeliverSome || | ||
52 | - command.OrderStatus == domain.OrderStatusDeliverAll) { | ||
53 | - return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误") | ||
54 | - } | ||
55 | - return nil | ||
56 | -} |
pkg/application/order/query/get_order.go
已删除
100644 → 0
1 | -package query | ||
2 | - | ||
3 | -//ListOrderQuery 获取订单列表 | ||
4 | -type ListOrderQuery struct { | ||
5 | - //合伙人id | ||
6 | - PartnerId int64 `json:"partnerId" ` | ||
7 | - //订单编号 | ||
8 | - OrderCode string `json:"order_code"` | ||
9 | - // 查询偏离量 | ||
10 | - Offset int `json:"offset" ` | ||
11 | - // 查询限制 | ||
12 | - Limit int `json:"limit"` | ||
13 | - //订单类型 | ||
14 | - OrderType int `json:"orderType"` | ||
15 | -} |
pkg/application/order/service/order.go
已删除
100644 → 0
1 | -package service | ||
2 | - | ||
3 | -import ( | ||
4 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command" | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
8 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
9 | -) | ||
10 | - | ||
11 | -//OrderService 管理员相关服务 | ||
12 | -type OrderService struct { | ||
13 | -} | ||
14 | - | ||
15 | -func NewOrderService(option map[string]interface{}) *OrderService { | ||
16 | - newAdminUserService := new(OrderService) | ||
17 | - return newAdminUserService | ||
18 | -} | ||
19 | - | ||
20 | -func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ([]domain.Order, int, error) { | ||
21 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
22 | - if err != nil { | ||
23 | - return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
24 | - } | ||
25 | - var ( | ||
26 | - orderRepository domain.OrderRepository | ||
27 | - orders []domain.Order | ||
28 | - cnt int | ||
29 | - ) | ||
30 | - if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
31 | - "transactionContext": transactionContext, | ||
32 | - }); err != nil { | ||
33 | - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
34 | - } else { | ||
35 | - orderRepository = value | ||
36 | - } | ||
37 | - query := domain.OrderFindQuery{ | ||
38 | - PartnerId: listOrderQuery.PartnerId, | ||
39 | - OrderCode: listOrderQuery.OrderCode, | ||
40 | - Offset: listOrderQuery.Offset, | ||
41 | - Limit: listOrderQuery.Limit, | ||
42 | - OrderType: listOrderQuery.OrderType, | ||
43 | - } | ||
44 | - orders, err = orderRepository.Find(query) | ||
45 | - if err != nil { | ||
46 | - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | - } | ||
48 | - | ||
49 | - cnt, err = orderRepository.CountAll(query) | ||
50 | - if err != nil { | ||
51 | - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
52 | - } | ||
53 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
54 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
55 | - "transactionContext": transactionContext, | ||
56 | - }); err != nil { | ||
57 | - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
58 | - } | ||
59 | - for i := range orders { | ||
60 | - var partnerData *domain.PartnerInfo | ||
61 | - partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: orders[i].PartnerInfo.Id}) | ||
62 | - if err != nil { | ||
63 | - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
64 | - } | ||
65 | - orders[i].PartnerInfo = partnerData.Partner | ||
66 | - } | ||
67 | - return orders, cnt, nil | ||
68 | -} | ||
69 | - | ||
70 | -func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain.Order, error) { | ||
71 | - //实际业务 | ||
72 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
73 | - if err != nil { | ||
74 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
75 | - } | ||
76 | - var ( | ||
77 | - orderRepository domain.OrderRepository | ||
78 | - order *domain.Order | ||
79 | - ) | ||
80 | - if err = transactionContext.StartTransaction(); err != nil { | ||
81 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
82 | - } | ||
83 | - defer func() { | ||
84 | - transactionContext.RollbackTransaction() | ||
85 | - }() | ||
86 | - if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
87 | - "transactionContext": transactionContext, | ||
88 | - }); err != nil { | ||
89 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
90 | - } else { | ||
91 | - orderRepository = value | ||
92 | - } | ||
93 | - order, err = orderRepository.FindOne(domain.OrderFindOneQuery{ | ||
94 | - OrderId: getOrderQuery.OrderId, | ||
95 | - }) | ||
96 | - if err != nil { | ||
97 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
98 | - } | ||
99 | - | ||
100 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
101 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
102 | - "transactionContext": transactionContext, | ||
103 | - }); err != nil { | ||
104 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
105 | - } | ||
106 | - var partnerData *domain.PartnerInfo | ||
107 | - partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id}) | ||
108 | - if err != nil { | ||
109 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
110 | - } | ||
111 | - order.PartnerInfo = partnerData.Partner | ||
112 | - err = transactionContext.CommitTransaction() | ||
113 | - if err != nil { | ||
114 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
115 | - } | ||
116 | - return order, nil | ||
117 | -} | ||
118 | - | ||
119 | -//CreateOrder 创建意向单 | ||
120 | -func (service OrderService) CreateOrder(command command.CreateOrderCommand) error { | ||
121 | - var ( | ||
122 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
123 | - err error | ||
124 | - ) | ||
125 | - if err = command.ValidateCommand(); err != nil { | ||
126 | - return lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
127 | - } | ||
128 | - if err = transactionContext.StartTransaction(); err != nil { | ||
129 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
130 | - } | ||
131 | - defer func() { | ||
132 | - transactionContext.RollbackTransaction() | ||
133 | - }() | ||
134 | - | ||
135 | - orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
136 | - ok, err := orderDao.OrderCodeIsExist(command.OrderCode, 0) | ||
137 | - if err != nil { | ||
138 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
139 | - } | ||
140 | - if ok { | ||
141 | - return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在") | ||
142 | - } | ||
143 | - var PartnerInfoRepository domain.PartnerInfoRepository | ||
144 | - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
145 | - "transactionContext": transactionContext, | ||
146 | - }); err != nil { | ||
147 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
148 | - } | ||
149 | - var partnerData *domain.PartnerInfo | ||
150 | - partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.PartnerId}) | ||
151 | - if err != nil { | ||
152 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
153 | - } | ||
154 | - var orderRepository domain.OrderRepository | ||
155 | - if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{ | ||
156 | - "transactionContext": transactionContext, | ||
157 | - }); err != nil { | ||
158 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
159 | - } | ||
160 | - newOrder := domain.Order{ | ||
161 | - //订单类型 | ||
162 | - OrderType: command.OrderType, | ||
163 | - //订单编号 | ||
164 | - OrderCode: command.OrderCode, | ||
165 | - //订单名称 | ||
166 | - OrderName: command.OrderName, | ||
167 | - //订单状态 | ||
168 | - OrderStatus: command.OrderStatus, | ||
169 | - //数量 | ||
170 | - OrderCount: command.OrderCount, | ||
171 | - //实际数量 | ||
172 | - OrderActualCount: command.OrderActualCount, | ||
173 | - //订单金额 | ||
174 | - OrderAmount: command.OrderAmount, | ||
175 | - //实际订单金额 | ||
176 | - OrderActualAmount: command.OrderActualAmount, | ||
177 | - //订单已支付分红金额(货款) | ||
178 | - OrderPaymentAmount: 0, | ||
179 | - //订单区域信息 | ||
180 | - OrderRegionInfo: domain.RegionInfo{ | ||
181 | - RegionName: command.OrderRegion, | ||
182 | - }, | ||
183 | - //买家 | ||
184 | - Buyer: domain.Buyer{ | ||
185 | - BuyerName: command.BuyerName, | ||
186 | - ShippingAddress: command.BuyerAddress, | ||
187 | - ContactInfo: command.BuyerPhone, | ||
188 | - }, | ||
189 | - PartnerInfo: partnerData.Partner, | ||
190 | - //合伙人分红百分比 | ||
191 | - PartnerBonusPercent: command.PartnerBonusPercent, | ||
192 | - //业务员分红百分比 | ||
193 | - SalesmanBonusPercent: command.SalesmanBonusPercent, | ||
194 | - } | ||
195 | - err = orderRepository.Save(newOrder) | ||
196 | - if err != nil { | ||
197 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
198 | - } | ||
199 | - err = transactionContext.CommitTransaction() | ||
200 | - if err != nil { | ||
201 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
202 | - } | ||
203 | - return nil | ||
204 | -} | ||
205 | - | ||
206 | -//UpdateOrderPurpose 更新意向单 | ||
207 | -func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderCommand) error { | ||
208 | - var ( | ||
209 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
210 | - err error | ||
211 | - ) | ||
212 | - if err = command.ValidateCommand(); err != nil { | ||
213 | - return lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
214 | - } | ||
215 | - if err = transactionContext.StartTransaction(); err != nil { | ||
216 | - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
217 | - } | ||
218 | - defer func() { | ||
219 | - transactionContext.RollbackTransaction() | ||
220 | - }() | ||
221 | - orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
222 | - ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id) | ||
223 | - if err != nil { | ||
224 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
225 | - } | ||
226 | - if ok { | ||
227 | - return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在") | ||
228 | - } | ||
229 | - var ( | ||
230 | - orderRepository domain.OrderRepository | ||
231 | - orderData *domain.Order | ||
232 | - ) | ||
233 | - if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{ | ||
234 | - "transactionContext": transactionContext, | ||
235 | - }); err != nil { | ||
236 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
237 | - } | ||
238 | - orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{ | ||
239 | - OrderId: command.Id, | ||
240 | - }) | ||
241 | - if err != nil { | ||
242 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
243 | - } | ||
244 | - if orderData.OrderType != domain.OrderIntention { | ||
245 | - return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单") | ||
246 | - } | ||
247 | - updateMap := map[string]interface{}{ | ||
248 | - //订单编号 | ||
249 | - "orderCode": command.OrderCode, | ||
250 | - "oderName": command.OrderName, | ||
251 | - "orderCount": command.OrderCount, | ||
252 | - "orderAmount": command.OrderAmount, | ||
253 | - "orderActualCount": command.OrderCount, | ||
254 | - "orderActualAmount": command.OrderAmount, | ||
255 | - "buyer": domain.Buyer{ | ||
256 | - BuyerName: orderData.Buyer.BuyerName, | ||
257 | - ContactInfo: command.BuyerPhone, | ||
258 | - ShippingAddress: command.BuyerAddress, | ||
259 | - }, | ||
260 | - "orderRegion": domain.RegionInfo{ | ||
261 | - RegionName: command.OrderRegion, | ||
262 | - }, | ||
263 | - "partnerBonusPercent": command.PartnerBonusPercent, | ||
264 | - "salesmanBonusPercent": command.SalesmanBonusPercent, | ||
265 | - "orderStatus": command.OrderStatus, | ||
266 | - "orderType": command.OrderType, | ||
267 | - } | ||
268 | - | ||
269 | - err = orderData.Update(updateMap) | ||
270 | - if err != nil { | ||
271 | - return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | ||
272 | - } | ||
273 | - err = orderRepository.Save(*orderData) | ||
274 | - if err != nil { | ||
275 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
276 | - } | ||
277 | - err = transactionContext.CommitTransaction() | ||
278 | - if err != nil { | ||
279 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
280 | - } | ||
281 | - return nil | ||
282 | -} | ||
283 | - | ||
284 | -//RemoveOrder 删除意向单 | ||
285 | -func (service OrderService) RemoveOrder(id int64) error { | ||
286 | - //实际业务 | ||
287 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
288 | - if err != nil { | ||
289 | - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
290 | - } | ||
291 | - if err = transactionContext.StartTransaction(); err != nil { | ||
292 | - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
293 | - } | ||
294 | - defer func() { | ||
295 | - transactionContext.RollbackTransaction() | ||
296 | - }() | ||
297 | - var ( | ||
298 | - orderRepository domain.OrderRepository | ||
299 | - order *domain.Order | ||
300 | - ) | ||
301 | - if value, err := factory.CreateOrderRepository(map[string]interface{}{ | ||
302 | - "transactionContext": transactionContext, | ||
303 | - }); err != nil { | ||
304 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
305 | - } else { | ||
306 | - orderRepository = value | ||
307 | - } | ||
308 | - order, err = orderRepository.FindOne(domain.OrderFindOneQuery{ | ||
309 | - OrderId: id, | ||
310 | - }) | ||
311 | - if err != nil { | ||
312 | - return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error()) | ||
313 | - } | ||
314 | - if order.OrderType != domain.OrderIntention { | ||
315 | - return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单") | ||
316 | - } | ||
317 | - err = orderRepository.Remove(order.Id) | ||
318 | - if err != nil { | ||
319 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
320 | - } | ||
321 | - err = transactionContext.CommitTransaction() | ||
322 | - if err != nil { | ||
323 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
324 | - } | ||
325 | - return nil | ||
326 | -} | ||
327 | - | ||
328 | -//UpdateOrderReal 更新为实发单 | ||
329 | -func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error { | ||
330 | - var ( | ||
331 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
332 | - err error | ||
333 | - ) | ||
334 | - if err = command.ValidateCommand(); err != nil { | ||
335 | - return lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
336 | - } | ||
337 | - if err = transactionContext.StartTransaction(); err != nil { | ||
338 | - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
339 | - } | ||
340 | - defer func() { | ||
341 | - transactionContext.RollbackTransaction() | ||
342 | - }() | ||
343 | - orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
344 | - ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id) | ||
345 | - if err != nil { | ||
346 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
347 | - } | ||
348 | - if ok { | ||
349 | - return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在") | ||
350 | - } | ||
351 | - var ( | ||
352 | - orderRepository domain.OrderRepository | ||
353 | - orderData *domain.Order | ||
354 | - ) | ||
355 | - if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{ | ||
356 | - "transactionContext": transactionContext, | ||
357 | - }); err != nil { | ||
358 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
359 | - } | ||
360 | - orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{ | ||
361 | - OrderId: command.Id, | ||
362 | - }) | ||
363 | - if err != nil { | ||
364 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
365 | - } | ||
366 | - err = orderData.Update(map[string]interface{}{ | ||
367 | - //订单编号 | ||
368 | - "orderCode": command.OrderCode, | ||
369 | - "oderName": command.OrderName, | ||
370 | - "orderActualCount": command.OrderActualCount, | ||
371 | - "orderActualAmount": command.OrderActualAmount, | ||
372 | - "buyer": domain.Buyer{ | ||
373 | - BuyerName: orderData.Buyer.BuyerName, | ||
374 | - ContactInfo: command.BuyerPhone, | ||
375 | - ShippingAddress: command.BuyerAddress, | ||
376 | - }, | ||
377 | - "orderRegion": domain.RegionInfo{ | ||
378 | - RegionName: command.OrderRegion, | ||
379 | - }, | ||
380 | - "partnerBonusPercent": command.PartnerBonusPercent, | ||
381 | - "salesmanBonusPercent": command.SalesmanBonusPercent, | ||
382 | - "orderStatus": command.OrderStatus, | ||
383 | - "orderType": domain.OrderReal, | ||
384 | - "reason": command.Reason, | ||
385 | - }) | ||
386 | - if err != nil { | ||
387 | - return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | ||
388 | - } | ||
389 | - err = orderRepository.Save(*orderData) | ||
390 | - if err != nil { | ||
391 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
392 | - } | ||
393 | - err = transactionContext.CommitTransaction() | ||
394 | - if err != nil { | ||
395 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
396 | - } | ||
397 | - return nil | ||
398 | -} |
1 | -package command | ||
2 | - | ||
3 | -type CreateOrderPaymentCommand struct { | ||
4 | - //订单编号 | ||
5 | - OrderId int64 `json:"orderId"` | ||
6 | - DivdendPaymentItem []DivdendPyamentItem `json:"dividendPayment"` | ||
7 | - TotalPaymentAmount float64 `json:"payment_amount"` | ||
8 | -} | ||
9 | - | ||
10 | -type DivdendPyamentItem struct { | ||
11 | - // 货款 | ||
12 | - PaymentForGoods float64 `json:"paymentForGoods,omitempty"` | ||
13 | - // 支付状态 | ||
14 | - StateOfPayment int `json:"stateOfPayment,omitempty"` | ||
15 | - //支付批次 | ||
16 | - PaymentSn int `json:"paymentSn,omitempty"` | ||
17 | - //支付编号 | ||
18 | - PaymentId int `json:"id,omitempty"` | ||
19 | -} | ||
20 | - | ||
21 | -func (command CreateOrderPaymentCommand) ValidateCommand() error { | ||
22 | - return nil | ||
23 | -} |
1 | -package query | ||
2 | - | ||
3 | -type ListDividendOrdersQuery struct { | ||
4 | - // 合伙人类别 | ||
5 | - PartnerId int `json:"partner"` | ||
6 | - SearchText string `json:"searchText"` | ||
7 | - PageSize int `json:"pageSize"` | ||
8 | - PageNumber int `json:"pageNumber"` | ||
9 | -} | ||
10 | - | ||
11 | -func (q *ListDividendOrdersQuery) ValidateQuery() error { | ||
12 | - | ||
13 | - return nil | ||
14 | -} |
1 | -package service | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "github.com/linmadan/egglib-go/core/application" | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
8 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
9 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
10 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils" | ||
11 | - "time" | ||
12 | - | ||
13 | - //"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
14 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
15 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
16 | -) | ||
17 | - | ||
18 | -// 客户价值服务 | ||
19 | -type OrderPaymentService struct { | ||
20 | -} | ||
21 | - | ||
22 | -func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService { | ||
23 | - newOrderPaymentService := &OrderPaymentService{} | ||
24 | - return newOrderPaymentService | ||
25 | -} | ||
26 | - | ||
27 | -// 创建订单支付数据 | ||
28 | -func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *command.CreateOrderPaymentCommand) (data interface{}, err error) { | ||
29 | - var ( | ||
30 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
31 | - OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
32 | - OrderPaymentDao, _ = factory.CreateOrderPaymentDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
33 | - ) | ||
34 | - if err = command.ValidateCommand(); err != nil { | ||
35 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
36 | - } | ||
37 | - if err = transactionContext.StartTransaction(); err != nil { | ||
38 | - return nil, err | ||
39 | - } | ||
40 | - defer func() { | ||
41 | - if err == nil { | ||
42 | - err = transactionContext.CommitTransaction() | ||
43 | - } | ||
44 | - if err != nil { | ||
45 | - transactionContext.RollbackTransaction() | ||
46 | - } | ||
47 | - }() | ||
48 | - //检查订单是否存在 | ||
49 | - | ||
50 | - var OrderPaymentRepository domain.OrderPaymentRepository | ||
51 | - if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
52 | - "transactionContext": transactionContext, | ||
53 | - }); err != nil { | ||
54 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
55 | - } | ||
56 | - orderBase, e := OrderDao.GetOrderBaseInfo(command.OrderId) | ||
57 | - if e != nil { | ||
58 | - err = e | ||
59 | - return | ||
60 | - } | ||
61 | - var excludeIdList []int | ||
62 | - var bonusStatus int = domain.BonusPaid //分红状态 | ||
63 | - excludeIdList = append(excludeIdList, 0) | ||
64 | - for i := range command.DivdendPaymentItem { | ||
65 | - paymentItem := command.DivdendPaymentItem[i] | ||
66 | - dm := &domain.OrderPayment{ | ||
67 | - OrderId: command.OrderId, | ||
68 | - CreateAt: time.Now(), | ||
69 | - UpdateAt: time.Now(), | ||
70 | - } | ||
71 | - if bonusStatus == domain.BonusPaid && paymentItem.StateOfPayment == domain.BonusWaitPay { | ||
72 | - bonusStatus = domain.BonusWaitPay | ||
73 | - } | ||
74 | - if paymentItem.PaymentId > 0 { | ||
75 | - //检查货款 已存在 / 未存在 | ||
76 | - if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentId: paymentItem.PaymentId}); e == nil { | ||
77 | - //状态更金额一样的时候 不做更新 | ||
78 | - if findDm.BonusStatus == paymentItem.StateOfPayment && findDm.PaymentAmount == paymentItem.PaymentForGoods { | ||
79 | - excludeIdList = append(excludeIdList, paymentItem.PaymentId) | ||
80 | - continue | ||
81 | - } | ||
82 | - dm = findDm | ||
83 | - } | ||
84 | - } | ||
85 | - dm.PartnerId = orderBase["PartnerId"].(int64) | ||
86 | - bonusPercent := orderBase["PartnerBonusPercent"].(float64) | ||
87 | - dm.BonusAmount = utils.Decimal(paymentItem.PaymentForGoods * (bonusPercent / 100.0)) | ||
88 | - dm.PaymentAmount = paymentItem.PaymentForGoods | ||
89 | - dm.BonusStatus = paymentItem.StateOfPayment | ||
90 | - dm.UpdateAt = time.Now() | ||
91 | - if data, err = OrderPaymentRepository.Save(dm); err != nil { | ||
92 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
93 | - } | ||
94 | - excludeIdList = append(excludeIdList, int(dm.Id)) | ||
95 | - } | ||
96 | - | ||
97 | - if err = OrderPaymentDao.Remove(command.OrderId, domain.BonusWaitPay, excludeIdList); err != nil { | ||
98 | - return | ||
99 | - } | ||
100 | - if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil { | ||
101 | - return | ||
102 | - } | ||
103 | - | ||
104 | - return | ||
105 | -} | ||
106 | - | ||
107 | -// 返回订单支付列表 | ||
108 | -func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) ([]*domain.OrderPayment, error) { | ||
109 | - var ( | ||
110 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
111 | - OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
112 | - OrderPayments []*domain.OrderPayment | ||
113 | - err error | ||
114 | - ) | ||
115 | - if err = listOrderPaymentQuery.ValidateQuery(); err != nil { | ||
116 | - return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
117 | - } | ||
118 | - if err := transactionContext.StartTransaction(); err != nil { | ||
119 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
120 | - } | ||
121 | - defer func() { | ||
122 | - transactionContext.RollbackTransaction() | ||
123 | - }() | ||
124 | - var OrderPaymentRepository domain.OrderPaymentRepository | ||
125 | - if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
126 | - "transactionContext": transactionContext, | ||
127 | - }); err != nil { | ||
128 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
129 | - } | ||
130 | - queryOption := domain.OrderPaymentQuery{ | ||
131 | - OrderId: listOrderPaymentQuery.OrderId, | ||
132 | - } | ||
133 | - _, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId) | ||
134 | - if e != nil { | ||
135 | - return nil, e | ||
136 | - } | ||
137 | - if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { | ||
138 | - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
139 | - } | ||
140 | - if err = transactionContext.CommitTransaction(); err != nil { | ||
141 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
142 | - } | ||
143 | - return OrderPayments, nil | ||
144 | -} | ||
145 | - | ||
146 | -// 返回分红管理列表 | ||
147 | -func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaymentQuery *query.ListDividendOrdersQuery) (int, interface{}, error) { | ||
148 | - var ( | ||
149 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
150 | - //OrderPayments []*domain.OrderPayment | ||
151 | - count int | ||
152 | - err error | ||
153 | - OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
154 | - orders []*models.Order | ||
155 | - ) | ||
156 | - if err = listOrderPaymentQuery.ValidateQuery(); err != nil { | ||
157 | - return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
158 | - } | ||
159 | - if err := transactionContext.StartTransaction(); err != nil { | ||
160 | - return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
161 | - } | ||
162 | - defer func() { | ||
163 | - transactionContext.RollbackTransaction() | ||
164 | - }() | ||
165 | - if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{ | ||
166 | - "orderCode": listOrderPaymentQuery.SearchText, | ||
167 | - "partnerId": listOrderPaymentQuery.PartnerId, | ||
168 | - "orderType": 1, | ||
169 | - "offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize, | ||
170 | - "limit": listOrderPaymentQuery.PageSize, | ||
171 | - }); err != nil { | ||
172 | - return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
173 | - } | ||
174 | - | ||
175 | - type DividendOrderItem struct { | ||
176 | - OrderId string `json:"id"` //订单编号 | ||
177 | - OrderNumber string `json:"orderNumber"` //订单号 | ||
178 | - OrderState int `json:"orderState"` //订单状态 | ||
179 | - StateOfPayment int `json:"stateOfPayment"` //支付状态 | ||
180 | - CreateTime string `json:"createTime"` //订单创建时间 | ||
181 | - PartnerName string `json:"partnerName"` //合伙人姓名 | ||
182 | - DividendProportion float64 `json:"dividendProportion"` //分红比例 | ||
183 | - DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红 | ||
184 | - DividendSpending float64 `json:"dividendSpending"` //分红支出 | ||
185 | - ReceiveDividends float64 `json:"receiveDividends"` //实收分红 | ||
186 | - CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例 | ||
187 | - } | ||
188 | - var list = make([]DividendOrderItem, 0) | ||
189 | - for i := range orders { | ||
190 | - order := orders[i] | ||
191 | - item := DividendOrderItem{ | ||
192 | - OrderId: fmt.Sprintf("%v", order.Id), | ||
193 | - OrderNumber: order.OrderCode, | ||
194 | - OrderState: order.OrderStatus, | ||
195 | - StateOfPayment: order.BonusStatus, | ||
196 | - CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
197 | - PartnerName: order.PartnerInfo.PartnerName, | ||
198 | - DividendProportion: order.PartnerBonusPercent, | ||
199 | - DividendsReceivable: utils.Decimal(order.OrderAmount * (order.PartnerBonusPercent / 100.0)), | ||
200 | - DividendSpending: 0, | ||
201 | - ReceiveDividends: utils.Decimal(order.OrderActualAmount * (order.PartnerBonusPercent / 100.0)), | ||
202 | - CommissionProportion: order.SalesmanBonusPercent, | ||
203 | - } | ||
204 | - if order.OrderActualAmount < order.OrderAmount { | ||
205 | - item.DividendSpending = utils.Decimal((order.OrderAmount - order.OrderActualAmount) * (order.PartnerBonusPercent / 100.0)) | ||
206 | - } | ||
207 | - list = append(list, item) | ||
208 | - } | ||
209 | - | ||
210 | - if err = transactionContext.CommitTransaction(); err != nil { | ||
211 | - return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
212 | - } | ||
213 | - return count, list, nil | ||
214 | -} |
pkg/domain/order.go
已删除
100644 → 0
1 | -package domain | ||
2 | - | ||
3 | -import ( | ||
4 | - "time" | ||
5 | - | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils" | ||
7 | -) | ||
8 | - | ||
9 | -const ( | ||
10 | - OrderStatusReserve = iota + 1 //预定中 | ||
11 | - OrderStatusDeliverSome //部分发货 | ||
12 | - OrderStatusDeliverAll //全部发货 | ||
13 | -) | ||
14 | - | ||
15 | -type Order struct { | ||
16 | - Id int64 `json:"id"` | ||
17 | - //订单类型 | ||
18 | - OrderType int `json:"orderType"` | ||
19 | - //订单编号 | ||
20 | - OrderCode string `json:"orderCode"` | ||
21 | - //订单名称 | ||
22 | - OrderName string `json:"oderName"` | ||
23 | - //订单状态 | ||
24 | - OrderStatus int `json:"orderStatus"` | ||
25 | - //数量 | ||
26 | - OrderCount int `json:"orderCount"` | ||
27 | - //实际数量 | ||
28 | - OrderActualCount int `json:"orderActualCount"` | ||
29 | - //订单金额 | ||
30 | - OrderAmount float64 `json:"orderAmount"` | ||
31 | - //实际订单金额 | ||
32 | - OrderActualAmount float64 `json:"orderActualAmount"` | ||
33 | - //订单已支付分红金额(货款) | ||
34 | - OrderPaymentAmount float64 `json:"orderPaymentAmount"` | ||
35 | - //订单区域信息 | ||
36 | - OrderRegionInfo RegionInfo `json:"orderRegionInfo"` | ||
37 | - //买家 | ||
38 | - Buyer Buyer `json:"buyer"` | ||
39 | - //合伙人数据 | ||
40 | - PartnerInfo Partner `json:"partnerInfo"` | ||
41 | - //合伙人分红百分比 | ||
42 | - PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
43 | - //业务员分红百分比 | ||
44 | - SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
45 | - //最后查看得时间 | ||
46 | - LastViewTime time.Time `json:"lastViewTime"` | ||
47 | - //更新时间 | ||
48 | - UpdateAt time.Time `json:"updateAt"` | ||
49 | - CreateAt time.Time `json:"createAt"` | ||
50 | - | ||
51 | - //理由 | ||
52 | - Reason string | ||
53 | -} | ||
54 | - | ||
55 | -//TODO | ||
56 | -func (order *Order) Update(data map[string]interface{}) error { | ||
57 | - if v, ok := data["orderType"]; ok { | ||
58 | - order.OrderType = v.(int) | ||
59 | - } | ||
60 | - if v, ok := data["orderCode"]; ok { | ||
61 | - order.OrderCode = v.(string) | ||
62 | - } | ||
63 | - if v, ok := data["oderName"]; ok { | ||
64 | - order.OrderName = v.(string) | ||
65 | - } | ||
66 | - if v, ok := data["orderStatus"]; ok { | ||
67 | - order.OrderStatus = v.(int) | ||
68 | - } | ||
69 | - if v, ok := data["orderCount"]; ok { | ||
70 | - order.OrderCount = v.(int) | ||
71 | - } | ||
72 | - if v, ok := data["orderActualCount"]; ok { | ||
73 | - order.OrderActualCount = v.(int) | ||
74 | - } | ||
75 | - if v, ok := data["orderAmount"]; ok { | ||
76 | - order.OrderAmount = v.(float64) | ||
77 | - } | ||
78 | - if v, ok := data["orderActualAmount"]; ok { | ||
79 | - order.OrderActualAmount = v.(float64) | ||
80 | - } | ||
81 | - if v, ok := data["orderPaymentAmount"]; ok { | ||
82 | - order.OrderPaymentAmount = v.(float64) | ||
83 | - } | ||
84 | - if v, ok := data["orderRegion"]; ok { | ||
85 | - order.OrderRegionInfo = v.(RegionInfo) | ||
86 | - } | ||
87 | - if v, ok := data["buyer"]; ok { | ||
88 | - order.Buyer = v.(Buyer) | ||
89 | - } | ||
90 | - if v, ok := data["partnerInfo"]; ok { | ||
91 | - order.PartnerInfo = v.(Partner) | ||
92 | - } | ||
93 | - if v, ok := data["partnerBonusPercent"]; ok { | ||
94 | - order.PartnerBonusPercent = v.(float64) | ||
95 | - } | ||
96 | - if v, ok := data["salesmanBonusPercent"]; ok { | ||
97 | - order.SalesmanBonusPercent = v.(float64) | ||
98 | - } | ||
99 | - if v, ok := data["reason"]; ok { | ||
100 | - order.Reason = v.(string) | ||
101 | - } | ||
102 | - return nil | ||
103 | -} | ||
104 | - | ||
105 | -//订单累计分红 | ||
106 | -func (m *Order) OrderTotalBonus() float64 { | ||
107 | - return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0)) | ||
108 | -} | ||
109 | - | ||
110 | -//订单已收分红 | ||
111 | -func (m *Order) OrderBonusReceive() float64 { | ||
112 | - return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0)) | ||
113 | -} | ||
114 | - | ||
115 | -//订单未收分红 | ||
116 | -func (m *Order) OrderBonusWait() float64 { | ||
117 | - bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive() | ||
118 | - if bonusWait < 0 { | ||
119 | - return 0 | ||
120 | - } | ||
121 | - return bonusWait | ||
122 | -} | ||
123 | - | ||
124 | -//分红支出 | ||
125 | -func (m *Order) OrderBonusOutstanding() float64 { | ||
126 | - if m.OrderAmount <= m.OrderActualAmount { | ||
127 | - return 0 | ||
128 | - } | ||
129 | - return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0)) | ||
130 | -} | ||
131 | - | ||
132 | -//订单被取消金额 | ||
133 | -func (m *Order) OrderAmountCancel() float64 { | ||
134 | - if m.OrderAmount <= m.OrderActualAmount { | ||
135 | - return 0 | ||
136 | - } | ||
137 | - return utils.Decimal((m.OrderAmount - m.OrderActualAmount)) | ||
138 | -} | ||
139 | - | ||
140 | -type OrderFindOneQuery struct { | ||
141 | - OrderId int64 | ||
142 | -} | ||
143 | - | ||
144 | -type OrderFindQuery struct { | ||
145 | - PartnerId int64 | ||
146 | - OrderCode string | ||
147 | - DeliveryCode string | ||
148 | - Offset int | ||
149 | - Limit int | ||
150 | - OrderType int | ||
151 | -} | ||
152 | - | ||
153 | -type OrderRepository interface { | ||
154 | - Save(order Order) error | ||
155 | - FindOne(qureyOptions OrderFindOneQuery) (*Order, error) | ||
156 | - Find(queryOptions OrderFindQuery) ([]Order, error) | ||
157 | - CountAll(queryOption OrderFindQuery) (int, error) | ||
158 | - Remove(id int64) error | ||
159 | -} |
pkg/domain/order_payment.go
已删除
100644 → 0
1 | -package domain | ||
2 | - | ||
3 | -import "time" | ||
4 | - | ||
5 | -const ( | ||
6 | - BonusWaitPay = iota + 1 //等待支付分红 | ||
7 | - BonusPaid //已经支付分红 | ||
8 | -) | ||
9 | - | ||
10 | -type OrderPayment struct { | ||
11 | - //编号 | ||
12 | - Id int64 `json:"id"` | ||
13 | - //订单编号 | ||
14 | - OrderId int64 `json:"orderId"` | ||
15 | - //合伙人编号 | ||
16 | - PartnerId int64 `json:"partnerId"` | ||
17 | - //支付货款 | ||
18 | - PaymentAmount float64 `json:"paymentAmount"` | ||
19 | - //分红金额 | ||
20 | - BonusAmount float64 `json:"bonusAmount"` | ||
21 | - //分红状态 1.等待支付分红 2.已支付分红 | ||
22 | - BonusStatus int `json:"bonusStatus"` | ||
23 | - //创建时间 | ||
24 | - CreateAt time.Time `json:"createAt"` | ||
25 | - //更新时间 | ||
26 | - UpdateAt time.Time `json:"updateAt"` | ||
27 | - | ||
28 | - //扩展 | ||
29 | - PartnerBonusPercent float64 `json:"-"` | ||
30 | -} | ||
31 | - | ||
32 | -func (m *OrderPayment) Identify() interface{} { | ||
33 | - if m.Id == 0 { | ||
34 | - return nil | ||
35 | - } | ||
36 | - return m.Id | ||
37 | -} | ||
38 | - | ||
39 | -func (m *OrderPayment) Update(data map[string]interface{}) error { | ||
40 | - if m.BonusStatus != BonusWaitPay { | ||
41 | - return nil | ||
42 | - } | ||
43 | - if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 { | ||
44 | - m.PaymentAmount = paymentAmount.(float64) | ||
45 | - } | ||
46 | - if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 { | ||
47 | - m.BonusAmount = bonusAmount.(float64) | ||
48 | - } | ||
49 | - if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 { | ||
50 | - m.BonusStatus = bonusStatus.(int) | ||
51 | - } | ||
52 | - m.UpdateAt = time.Now() | ||
53 | - return nil | ||
54 | -} | ||
55 | - | ||
56 | -type OrderPaymentFindOneQuery struct { | ||
57 | - Id int64 | ||
58 | - OrderId int64 | ||
59 | - PaymentId int | ||
60 | -} | ||
61 | -type OrderPaymentQuery struct { | ||
62 | - Offset int | ||
63 | - Limit int | ||
64 | - | ||
65 | - OrderId int64 | ||
66 | - //PartnerCategory []int //合伙人类型 | ||
67 | - //RegionInfo *RegionInfo //区域 | ||
68 | - //PartnerName string //合伙人姓名 | ||
69 | -} | ||
70 | - | ||
71 | -type OrderPaymentRepository interface { | ||
72 | - Save(dm *OrderPayment) (*OrderPayment, error) | ||
73 | - FindOne(queryOptions OrderPaymentFindOneQuery) (*OrderPayment, error) | ||
74 | - Find(queryOptions OrderPaymentQuery) ([]*OrderPayment, error) | ||
75 | - CountAll(queryOptions OrderPaymentQuery) (int, error) | ||
76 | -} |
pkg/infrastructure/dao/pg_order_dao.go
已删除
100644 → 0
1 | -package dao | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | -) | ||
9 | - | ||
10 | -type OrderDao struct { | ||
11 | - transactionContext *transaction.TransactionContext | ||
12 | -} | ||
13 | - | ||
14 | -func (dao *OrderDao) Update(options map[string]interface{}) (err error) { | ||
15 | - tx := dao.transactionContext.PgTx | ||
16 | - order := new(models.Order) | ||
17 | - q := tx.Model(order) | ||
18 | - if v, ok := options["orderPaymentAmount"]; ok { | ||
19 | - q.Set("order_payment_amount = ?", v) | ||
20 | - } | ||
21 | - if v, ok := options["bonusStatus"]; ok { | ||
22 | - q.Set("bonus_status = ?", v) | ||
23 | - } | ||
24 | - if v, ok := options["id"]; ok { | ||
25 | - q.Where("id = ?", v) | ||
26 | - } | ||
27 | - _, err = q.Update() | ||
28 | - return | ||
29 | -} | ||
30 | - | ||
31 | -func (dao *OrderDao) OrderCodeIsExist(code string, notId int64) (bool, error) { | ||
32 | - tx := dao.transactionContext.PgDd | ||
33 | - ok, err := tx.Model(new(models.Order)). | ||
34 | - Where("order_code=?", code). | ||
35 | - Where("id<>?", notId). | ||
36 | - Exists() | ||
37 | - return ok, err | ||
38 | -} | ||
39 | - | ||
40 | -func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) { | ||
41 | - tx := dao.transactionContext.PgTx | ||
42 | - order := new(models.Order) | ||
43 | - | ||
44 | - data = make(map[string]interface{}) | ||
45 | - q := tx.Model(order) | ||
46 | - q.Column("partner_id", "partner_bonus_percent", "order_payment_amount", "buyer") | ||
47 | - q.Where("id = ?", id) | ||
48 | - err = q.Select() | ||
49 | - if err == nil { | ||
50 | - data["PartnerId"] = order.PartnerId | ||
51 | - data["PartnerBonusPercent"] = order.PartnerBonusPercent | ||
52 | - data["OrderPaymentAmount"] = order.OrderPaymentAmount | ||
53 | - data["Buyer"] = order.Buyer | ||
54 | - } | ||
55 | - return | ||
56 | -} | ||
57 | - | ||
58 | -func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count int, orders []*models.Order, err error) { | ||
59 | - tx := dao.transactionContext.PgTx | ||
60 | - //Order:=new(models.Order) | ||
61 | - q := tx.Model(&orders) | ||
62 | - q.ColumnExpr(`"order".*`, `partner_info.partner_name`) | ||
63 | - q.Relation("PartnerInfo") | ||
64 | - if v, ok := options["orderCode"]; ok && len(v.(string)) > 0 { | ||
65 | - q.Where(`"order".order_code like ?`, fmt.Sprintf("%%%v%%", v)) | ||
66 | - } | ||
67 | - if v, ok := options["orderType"]; ok { | ||
68 | - q.Where(`"order".order_type=?`, v) | ||
69 | - } | ||
70 | - if v, ok := options["partnerId"]; ok && v.(int) > 0 { | ||
71 | - q.Where(`"order".partner_id =?`, v) | ||
72 | - } | ||
73 | - if v, ok := options["offset"]; ok { | ||
74 | - q.Offset(v.(int)) | ||
75 | - } | ||
76 | - if v, ok := options["limit"]; ok { | ||
77 | - q.Limit(v.(int)) | ||
78 | - } | ||
79 | - q.Order(`order.id DESC`) | ||
80 | - count, err = q.SelectAndCount() | ||
81 | - return | ||
82 | -} | ||
83 | - | ||
84 | -func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | ||
85 | - if transactionContext == nil { | ||
86 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
87 | - } else { | ||
88 | - return &OrderDao{ | ||
89 | - transactionContext: transactionContext, | ||
90 | - }, nil | ||
91 | - } | ||
92 | -} |
1 | -package dao | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
6 | - | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | -) | ||
9 | - | ||
10 | -type OrderPayment struct { | ||
11 | - transactionContext *transaction.TransactionContext | ||
12 | -} | ||
13 | - | ||
14 | -//删除数据 | ||
15 | -func (o *OrderPayment) Remove(orderId int64, status int, idList []int) error { | ||
16 | - if len(idList) == 0 { | ||
17 | - return nil | ||
18 | - } | ||
19 | - tx := o.transactionContext.PgTx | ||
20 | - m := new(models.OrderPayment) | ||
21 | - q := tx.Model(m).Where("order_id=?", orderId). | ||
22 | - WhereIn("id not in(?)", idList) | ||
23 | - _, err := q.Delete() | ||
24 | - return err | ||
25 | -} | ||
26 | - | ||
27 | -func NewOrderPayment(transactionContext *transaction.TransactionContext) (*OrderPayment, error) { | ||
28 | - if transactionContext == nil { | ||
29 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
30 | - } else { | ||
31 | - return &OrderPayment{ | ||
32 | - transactionContext: transactionContext, | ||
33 | - }, nil | ||
34 | - } | ||
35 | -} |
1 | -package repository | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | -) | ||
9 | - | ||
10 | -type OrderPaymentRepository struct { | ||
11 | - transactionContext *transaction.TransactionContext | ||
12 | -} | ||
13 | - | ||
14 | -func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
15 | - var ( | ||
16 | - err error | ||
17 | - tx = repository.transactionContext.PgTx | ||
18 | - ) | ||
19 | - m := &models.OrderPayment{ | ||
20 | - Id: dm.Id, | ||
21 | - OrderId: dm.OrderId, | ||
22 | - PartnerId: dm.PartnerId, | ||
23 | - PaymentAmount: dm.PaymentAmount, | ||
24 | - BonusAmount: dm.BonusAmount, | ||
25 | - BonusStatus: dm.BonusStatus, | ||
26 | - CreateAt: dm.CreateAt, | ||
27 | - UpdateAt: dm.UpdateAt, | ||
28 | - } | ||
29 | - if m.Id == 0 { | ||
30 | - err = tx.Insert(m) | ||
31 | - dm.Id = m.Id | ||
32 | - if err != nil { | ||
33 | - return nil, err | ||
34 | - } | ||
35 | - } else { | ||
36 | - err = tx.Update(m) | ||
37 | - if err != nil { | ||
38 | - return nil, err | ||
39 | - } | ||
40 | - } | ||
41 | - return dm, nil | ||
42 | -} | ||
43 | - | ||
44 | -func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
45 | - var ( | ||
46 | - tx = repository.transactionContext.PgTx | ||
47 | - OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)} | ||
48 | - ) | ||
49 | - if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil { | ||
50 | - return OrderPayment, err | ||
51 | - } | ||
52 | - return OrderPayment, nil | ||
53 | -} | ||
54 | - | ||
55 | -func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPaymentFindOneQuery) (*domain.OrderPayment, error) { | ||
56 | - tx := repository.transactionContext.PgTx | ||
57 | - OrderPaymentModel := new(models.OrderPayment) | ||
58 | - query := tx.Model(OrderPaymentModel) | ||
59 | - | ||
60 | - if queryOptions.OrderId > 0 { | ||
61 | - query.Where("order_payment.order_id = ?", queryOptions.OrderId) | ||
62 | - } | ||
63 | - if queryOptions.PaymentId > 0 { | ||
64 | - query.Where("order_payment.id = ?", queryOptions.PaymentId) | ||
65 | - } | ||
66 | - if err := query.First(); err != nil { | ||
67 | - return nil, err | ||
68 | - } | ||
69 | - if OrderPaymentModel.Id == 0 { | ||
70 | - return nil, nil | ||
71 | - } | ||
72 | - return repository.transformPgModelToDomainModel(OrderPaymentModel) | ||
73 | -} | ||
74 | - | ||
75 | -func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQuery) ([]*domain.OrderPayment, error) { | ||
76 | - tx := repository.transactionContext.PgTx | ||
77 | - var OrderPaymentModels []*models.OrderPayment | ||
78 | - query := tx.Model(&OrderPaymentModels) | ||
79 | - query.Where("order_id=?", queryOptions.OrderId) | ||
80 | - query.Order("id ASC") | ||
81 | - var ( | ||
82 | - err error | ||
83 | - rsp = make([]*domain.OrderPayment, 0) | ||
84 | - ) | ||
85 | - err = query.Select() | ||
86 | - if err != nil { | ||
87 | - return rsp, err | ||
88 | - } | ||
89 | - for i := range OrderPaymentModels { | ||
90 | - dm, err := repository.transformPgModelToDomainModel(OrderPaymentModels[i]) | ||
91 | - if err != nil { | ||
92 | - return rsp, err | ||
93 | - } | ||
94 | - rsp = append(rsp, dm) | ||
95 | - } | ||
96 | - return rsp, nil | ||
97 | -} | ||
98 | - | ||
99 | -func (repository OrderPaymentRepository) CountAll(queryOption domain.OrderPaymentQuery) (int, error) { | ||
100 | - db := repository.transactionContext.PgDd | ||
101 | - partnerModels := models.PartnerInfo{} | ||
102 | - query := db.Model(&partnerModels) | ||
103 | - //if len(queryOption.PartnerName) > 0 { | ||
104 | - // query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | ||
105 | - //} | ||
106 | - //if queryOption.RegionInfo != nil { | ||
107 | - // query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") | ||
108 | - //} | ||
109 | - //if len(queryOption.PartnerCategory) > 0 { | ||
110 | - // query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) | ||
111 | - //} | ||
112 | - cnt, err := query.Count() | ||
113 | - return cnt, err | ||
114 | -} | ||
115 | - | ||
116 | -func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *models.OrderPayment) (*domain.OrderPayment, error) { | ||
117 | - m := &domain.OrderPayment{ | ||
118 | - Id: dm.Id, | ||
119 | - OrderId: dm.OrderId, | ||
120 | - PartnerId: dm.PartnerId, | ||
121 | - PaymentAmount: dm.PaymentAmount, | ||
122 | - BonusAmount: dm.BonusAmount, | ||
123 | - BonusStatus: dm.BonusStatus, | ||
124 | - CreateAt: dm.CreateAt, | ||
125 | - UpdateAt: dm.UpdateAt, | ||
126 | - } | ||
127 | - return m, nil | ||
128 | -} | ||
129 | - | ||
130 | -func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) { | ||
131 | - if transactionContext == nil { | ||
132 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
133 | - } | ||
134 | - return &OrderPaymentRepository{transactionContext: transactionContext}, nil | ||
135 | -} |
1 | -package repository | ||
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - | ||
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
8 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
9 | -) | ||
10 | - | ||
11 | -type OrderRepository struct { | ||
12 | - transactionContext *transaction.TransactionContext | ||
13 | -} | ||
14 | - | ||
15 | -var ( | ||
16 | - _ domain.OrderRepository = (*OrderRepository)(nil) | ||
17 | -) | ||
18 | - | ||
19 | -func NewOrderRepository(transactionContext *transaction.TransactionContext) (*OrderRepository, error) { | ||
20 | - if transactionContext == nil { | ||
21 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
22 | - } | ||
23 | - return &OrderRepository{transactionContext: transactionContext}, nil | ||
24 | -} | ||
25 | - | ||
26 | -func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *models.Order) (domain.Order, error) { | ||
27 | - result := domain.Order{ | ||
28 | - Id: orderModel.Id, | ||
29 | - OrderType: orderModel.OrderType, | ||
30 | - OrderCode: orderModel.OrderCode, | ||
31 | - OrderName: orderModel.OrderName, | ||
32 | - OrderStatus: orderModel.OrderStatus, | ||
33 | - OrderCount: orderModel.OrderCount, | ||
34 | - OrderActualCount: orderModel.OrderActualCount, | ||
35 | - OrderAmount: orderModel.OrderAmount, | ||
36 | - OrderActualAmount: orderModel.OrderActualAmount, | ||
37 | - OrderPaymentAmount: orderModel.OrderPaymentAmount, | ||
38 | - OrderRegionInfo: orderModel.OrderRegionInfo, | ||
39 | - Buyer: orderModel.Buyer, | ||
40 | - PartnerInfo: domain.Partner{ | ||
41 | - Id: orderModel.PartnerId, | ||
42 | - }, | ||
43 | - PartnerBonusPercent: orderModel.PartnerBonusPercent, | ||
44 | - SalesmanBonusPercent: orderModel.SalesmanBonusPercent, | ||
45 | - LastViewTime: orderModel.LastViewTime, | ||
46 | - UpdateAt: orderModel.UpdateAt, | ||
47 | - CreateAt: orderModel.CreateAt, | ||
48 | - Reason: orderModel.Reason, | ||
49 | - } | ||
50 | - return result, nil | ||
51 | -} | ||
52 | - | ||
53 | -func (repository OrderRepository) Save(orderInfo domain.Order) error { | ||
54 | - var ( | ||
55 | - err error | ||
56 | - tx = repository.transactionContext.PgTx | ||
57 | - ) | ||
58 | - m := &models.Order{ | ||
59 | - Id: orderInfo.Id, | ||
60 | - OrderType: orderInfo.OrderType, | ||
61 | - OrderCode: orderInfo.OrderCode, | ||
62 | - OrderName: orderInfo.OrderName, | ||
63 | - OrderStatus: orderInfo.OrderStatus, | ||
64 | - OrderCount: orderInfo.OrderCount, | ||
65 | - OrderActualCount: orderInfo.OrderActualCount, | ||
66 | - OrderAmount: orderInfo.OrderAmount, | ||
67 | - OrderActualAmount: orderInfo.OrderActualAmount, | ||
68 | - OrderPaymentAmount: orderInfo.OrderPaymentAmount, | ||
69 | - OrderRegionInfo: orderInfo.OrderRegionInfo, | ||
70 | - Buyer: orderInfo.Buyer, | ||
71 | - PartnerId: orderInfo.PartnerInfo.Id, | ||
72 | - PartnerBonusPercent: orderInfo.PartnerBonusPercent, | ||
73 | - SalesmanBonusPercent: orderInfo.SalesmanBonusPercent, | ||
74 | - BonusStatus: 1, | ||
75 | - Reason: orderInfo.Reason, | ||
76 | - } | ||
77 | - if m.Id == 0 { | ||
78 | - err = tx.Insert(m) | ||
79 | - orderInfo.Id = m.Id | ||
80 | - } else { | ||
81 | - _, err = tx.Model(m).WherePK(). | ||
82 | - Column("order_type", "order_code", "order_name", "order_status", "order_count", | ||
83 | - "order_actual_count", "order_amount", "order_actual_amount", "order_payment_amount", | ||
84 | - "order_region_info", "buyer", "partner_id", "partner_bonus_percent", "salesman_bonus_percent", | ||
85 | - "update_at", "reason"). | ||
86 | - Update() | ||
87 | - } | ||
88 | - return err | ||
89 | -} | ||
90 | - | ||
91 | -func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]domain.Order, error) { | ||
92 | - db := repository.transactionContext.PgDd | ||
93 | - orderModels := []models.Order{} | ||
94 | - query := db.Model(&orderModels) | ||
95 | - if queryOption.PartnerId > 0 { | ||
96 | - query = query.Where("partner_id=?", queryOption.PartnerId) | ||
97 | - } | ||
98 | - if len(queryOption.OrderCode) > 0 { | ||
99 | - query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%") | ||
100 | - } | ||
101 | - if queryOption.OrderType > 0 { | ||
102 | - query = query.Where("order_type=?", queryOption.OrderType) | ||
103 | - } | ||
104 | - if queryOption.Offset > -1 { | ||
105 | - query = query.Offset(queryOption.Offset) | ||
106 | - } | ||
107 | - if queryOption.Limit > 0 { | ||
108 | - query = query.Limit(queryOption.Limit) | ||
109 | - } else { | ||
110 | - query = query.Limit(20) | ||
111 | - } | ||
112 | - var ( | ||
113 | - err error | ||
114 | - ordersReturn = make([]domain.Order, 0) | ||
115 | - ) | ||
116 | - query = query.Order("order.id DESC") | ||
117 | - err = query.Select() | ||
118 | - if err != nil { | ||
119 | - return ordersReturn, err | ||
120 | - } | ||
121 | - for i := range orderModels { | ||
122 | - domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i]) | ||
123 | - if err != nil { | ||
124 | - return ordersReturn, err | ||
125 | - } | ||
126 | - ordersReturn = append(ordersReturn, domainOrder) | ||
127 | - } | ||
128 | - return ordersReturn, nil | ||
129 | -} | ||
130 | - | ||
131 | -func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (int, error) { | ||
132 | - db := repository.transactionContext.PgDd | ||
133 | - orderModels := []models.Order{} | ||
134 | - query := db.Model(&orderModels) | ||
135 | - if queryOption.PartnerId > 0 { | ||
136 | - query = query.Where("partner_id=?", queryOption.PartnerId) | ||
137 | - } | ||
138 | - if len(queryOption.OrderCode) > 0 { | ||
139 | - query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%") | ||
140 | - } | ||
141 | - if queryOption.OrderType > 0 { | ||
142 | - query = query.Where("order_type=?", queryOption.OrderType) | ||
143 | - } | ||
144 | - var ( | ||
145 | - err error | ||
146 | - ) | ||
147 | - cnt, err := query.Count() | ||
148 | - if err != nil { | ||
149 | - return cnt, err | ||
150 | - } | ||
151 | - return cnt, nil | ||
152 | -} | ||
153 | - | ||
154 | -func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) { | ||
155 | - var ( | ||
156 | - err error | ||
157 | - tx = repository.transactionContext.PgDd | ||
158 | - ) | ||
159 | - m := new(models.Order) | ||
160 | - err = tx.Model(m). | ||
161 | - Where("id=?", qureyOptions.OrderId). | ||
162 | - First() | ||
163 | - if err != nil { | ||
164 | - return nil, err | ||
165 | - } | ||
166 | - result, err := repository.transformPgModelToDomainModel(m) | ||
167 | - return &result, err | ||
168 | -} | ||
169 | - | ||
170 | -func (repository OrderRepository) Remove(id int64) error { | ||
171 | - var ( | ||
172 | - err error | ||
173 | - tx = repository.transactionContext.PgTx | ||
174 | - ) | ||
175 | - m := &models.Order{ | ||
176 | - Id: id, | ||
177 | - } | ||
178 | - _, err = tx.Model(m).WherePK().Delete() | ||
179 | - return err | ||
180 | -} |
1 | -package controllers | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "github.com/astaxie/beego/logs" | ||
7 | - OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
8 | - OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
9 | - OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service" | ||
10 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils" | ||
11 | - | ||
12 | - OrderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query" | ||
13 | - OrderSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service" | ||
14 | - | ||
15 | - PartnerInfoQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query" | ||
16 | - PartnerInfoSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service" | ||
17 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
18 | - "strconv" | ||
19 | -) | ||
20 | - | ||
21 | -type DividendsController struct { | ||
22 | - BaseController | ||
23 | -} | ||
24 | - | ||
25 | -////Prepare 重写 BaseController 的Prepare方法 | ||
26 | -func (c *DividendsController) Prepare() { | ||
27 | - c.BaseController.Prepare() | ||
28 | - if ok := c.ValidJWTToken(); !ok { | ||
29 | - return | ||
30 | - } | ||
31 | - if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok { | ||
32 | - return | ||
33 | - } | ||
34 | -} | ||
35 | - | ||
36 | -//Edit 编辑分红支付 | ||
37 | -func (c *DividendsController) Edit() { | ||
38 | - //用与适配前端定义的数据结构 | ||
39 | - type DividendPaymentItem struct { | ||
40 | - PaymentForGoods float64 `json:"paymentForGoods"` | ||
41 | - StateOfPayment int `json:"stateOfPayment"` | ||
42 | - Id int `json:"id"` | ||
43 | - } | ||
44 | - type Parameter struct { | ||
45 | - Id string `json:"id"` //订单编号 | ||
46 | - DividendPayment []DividendPaymentItem `json:"dividendPayment"` | ||
47 | - } | ||
48 | - var ( | ||
49 | - param Parameter | ||
50 | - err error | ||
51 | - ) | ||
52 | - if err = c.BindJsonData(¶m); err != nil { | ||
53 | - logs.Error(err) | ||
54 | - c.ResponseError(errors.New("json数据解析失败")) | ||
55 | - return | ||
56 | - } | ||
57 | - if len(param.Id) == 0 { | ||
58 | - c.ResponseError(errors.New("id is empty")) | ||
59 | - return | ||
60 | - } | ||
61 | - orderId, _ := strconv.ParseInt(param.Id, 10, 64) | ||
62 | - cmd := OrderPaymentCmd.CreateOrderPaymentCommand{ | ||
63 | - OrderId: orderId, | ||
64 | - DivdendPaymentItem: make([]OrderPaymentCmd.DivdendPyamentItem, 0), | ||
65 | - } | ||
66 | - | ||
67 | - //编辑 | ||
68 | - for i := range param.DividendPayment { | ||
69 | - item := param.DividendPayment[i] | ||
70 | - paymentItem := OrderPaymentCmd.DivdendPyamentItem{} | ||
71 | - paymentItem.PaymentForGoods = item.PaymentForGoods | ||
72 | - paymentItem.StateOfPayment = item.StateOfPayment | ||
73 | - paymentItem.PaymentSn = i + 1 | ||
74 | - paymentItem.PaymentId = item.Id | ||
75 | - if paymentItem.StateOfPayment == domain.BonusPaid { | ||
76 | - cmd.TotalPaymentAmount += paymentItem.PaymentForGoods | ||
77 | - } | ||
78 | - cmd.DivdendPaymentItem = append(cmd.DivdendPaymentItem, paymentItem) | ||
79 | - } | ||
80 | - serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
81 | - _, err = serve.CreateOrderPayment(&cmd) | ||
82 | - if err != nil { | ||
83 | - c.ResponseError(err) | ||
84 | - return | ||
85 | - } | ||
86 | - c.ResponseData(nil) | ||
87 | - return | ||
88 | -} | ||
89 | - | ||
90 | -//Edit 分红支付详情 | ||
91 | -func (c *DividendsController) Detail() { | ||
92 | - type Parameter struct { | ||
93 | - Id string `json:"id"` //订单编号 | ||
94 | - } | ||
95 | - var ( | ||
96 | - param Parameter | ||
97 | - err error | ||
98 | - order *domain.Order | ||
99 | - partner *domain.PartnerInfo | ||
100 | - ) | ||
101 | - if err = c.BindJsonData(¶m); err != nil { | ||
102 | - logs.Error(err) | ||
103 | - c.ResponseError(errors.New("json数据解析失败")) | ||
104 | - return | ||
105 | - } | ||
106 | - | ||
107 | - cmd := OrderPaymentQuery.GetOrderPaymentQuery{} | ||
108 | - cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64) | ||
109 | - | ||
110 | - var ( | ||
111 | - OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil) | ||
112 | - OrderSvr = OrderSvr.NewOrderService(nil) | ||
113 | - PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil) | ||
114 | - ) | ||
115 | - var data []*domain.OrderPayment | ||
116 | - data, err = OrderPaymentSvr.ListOrderPayment(&cmd) | ||
117 | - if err != nil { | ||
118 | - c.ResponseError(err) | ||
119 | - return | ||
120 | - } | ||
121 | - if order, err = OrderSvr.GetOrder(OrderQuery.GetOrderQuery{OrderId: cmd.OrderId}); err != nil { | ||
122 | - c.ResponseError(err) | ||
123 | - return | ||
124 | - } | ||
125 | - if partner, err = PartnerInfoSvr.GetPartnerInfo(PartnerInfoQuery.GetPartnerInfoQuery{Id: order.PartnerInfo.Id}); err != nil { | ||
126 | - c.ResponseError(err) | ||
127 | - return | ||
128 | - } | ||
129 | - | ||
130 | - type DividendPayment struct { | ||
131 | - PaymentForGoods float64 `json:"paymentForGoods"` | ||
132 | - UpdateTime string `json:"updateTime"` | ||
133 | - StateOfPayment int `json:"stateOfPayment"` | ||
134 | - Dividend float64 `json:"dividend"` | ||
135 | - DividendProportion float64 `json:"dividendProportion"` | ||
136 | - Id int64 `json:"id"` | ||
137 | - } | ||
138 | - type Order struct { | ||
139 | - OrderNumber string `json:"orderNumber"` //订单号 | ||
140 | - OrderState int `json:"orderState"` //订单状态 | ||
141 | - CreateTime string `json:"createTime"` //订单创建时间 | ||
142 | - OrderName string `json:"orderName"` //订单名称 | ||
143 | - OrderNum string `json:"orderNum"` //订单数量 | ||
144 | - OrderAmount string `json:"orderAmount"` //订单金额 | ||
145 | - Id string `json:"id"` //订单编号 | ||
146 | - } | ||
147 | - type Partner struct { | ||
148 | - PartnerName string `json:"partnerName"` //合伙人姓名 | ||
149 | - DividendProportion float64 `json:"dividendProportion"` //分红比例 | ||
150 | - DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红 | ||
151 | - DividendSpending float64 `json:"dividendSpending"` //分红支出 | ||
152 | - ReceiveDividends float64 `json:"receiveDividends"` //实收分红 | ||
153 | - NotReceivedDividends float64 `json:"notReceivedDividends"` //未收分红 | ||
154 | - RceivedDividends float64 `json:"receivedDividends"` //已收分红 | ||
155 | - } | ||
156 | - type Commission struct { | ||
157 | - SalesmanName string `json:"salesmanName"` //业务员名称 | ||
158 | - CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例 | ||
159 | - ExpectedCommission float64 `json:"expectedCommission"` //业务员预计抽成 | ||
160 | - } | ||
161 | - type Response struct { | ||
162 | - DividendPayment []DividendPayment `json:"dividendPayment"` | ||
163 | - Order Order `json:"order"` | ||
164 | - Partner Partner `json:"partner"` | ||
165 | - Commission Commission `json:"commission"` | ||
166 | - } | ||
167 | - rsp := Response{DividendPayment: make([]DividendPayment, 0)} | ||
168 | - for i := range data { | ||
169 | - item := data[i] | ||
170 | - payment := DividendPayment{ | ||
171 | - PaymentForGoods: item.PaymentAmount, | ||
172 | - UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"), | ||
173 | - StateOfPayment: item.BonusStatus, | ||
174 | - Dividend: utils.Decimal(item.PaymentAmount * (order.PartnerBonusPercent / 100.0)), | ||
175 | - DividendProportion: order.PartnerBonusPercent, | ||
176 | - Id: item.Id, | ||
177 | - } | ||
178 | - rsp.DividendPayment = append(rsp.DividendPayment, payment) | ||
179 | - } | ||
180 | - rsp.Order = Order{ | ||
181 | - OrderNumber: order.OrderCode, | ||
182 | - OrderState: order.OrderStatus, | ||
183 | - CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
184 | - OrderName: order.OrderName, | ||
185 | - OrderNum: fmt.Sprintf("%v", order.OrderActualCount), | ||
186 | - OrderAmount: fmt.Sprintf("%v", order.OrderActualAmount), | ||
187 | - Id: fmt.Sprintf("%v", order.Id), | ||
188 | - } | ||
189 | - rsp.Partner = Partner{ | ||
190 | - PartnerName: partner.Partner.PartnerName, | ||
191 | - DividendProportion: order.PartnerBonusPercent, | ||
192 | - DividendsReceivable: order.OrderTotalBonus() + order.OrderBonusOutstanding(), //应收分红 = 实收分红+分红支出 | ||
193 | - DividendSpending: order.OrderBonusOutstanding(), //分红支出 | ||
194 | - ReceiveDividends: order.OrderTotalBonus(), //实收分红 = 实际金额 * 比例 | ||
195 | - NotReceivedDividends: order.OrderBonusWait(), //未收分红 | ||
196 | - RceivedDividends: order.OrderBonusReceive(), //已收分红 | ||
197 | - } | ||
198 | - rsp.Commission = Commission{ | ||
199 | - CommissionProportion: order.SalesmanBonusPercent, | ||
200 | - ExpectedCommission: utils.Decimal(order.OrderActualAmount * (order.SalesmanBonusPercent / 100)), | ||
201 | - } | ||
202 | - if len(partner.Salesman) > 0 { | ||
203 | - rsp.Commission.SalesmanName = partner.Salesman[0].Name | ||
204 | - } | ||
205 | - | ||
206 | - c.ResponseData(rsp) | ||
207 | - return | ||
208 | -} | ||
209 | - | ||
210 | -//分红管理 | ||
211 | -func (c *DividendsController) List() { | ||
212 | - var ( | ||
213 | - param OrderPaymentQuery.ListDividendOrdersQuery | ||
214 | - err error | ||
215 | - count int | ||
216 | - ) | ||
217 | - if err = c.BindJsonData(¶m); err != nil { | ||
218 | - logs.Error(err) | ||
219 | - c.ResponseError(errors.New("json数据解析失败")) | ||
220 | - return | ||
221 | - } | ||
222 | - | ||
223 | - if param.PageSize == 0 { | ||
224 | - param.PageSize = 20 | ||
225 | - } | ||
226 | - if param.PageNumber == 0 { | ||
227 | - param.PageNumber = 1 | ||
228 | - } | ||
229 | - serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
230 | - var data interface{} | ||
231 | - count, data, err = serve.ListDividendOrders(¶m) | ||
232 | - if err != nil { | ||
233 | - c.ResponseError(err) | ||
234 | - return | ||
235 | - } | ||
236 | - c.ResponsePageList(data, count, param.PageNumber) | ||
237 | - return | ||
238 | -} |
1 | -package controllers | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "strconv" | ||
6 | - | ||
7 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/logs" | ||
10 | - orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command" | ||
11 | - orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query" | ||
12 | - orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service" | ||
13 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
14 | -) | ||
15 | - | ||
16 | -type OrderController struct { | ||
17 | - BaseController | ||
18 | -} | ||
19 | - | ||
20 | -////Prepare 重写 BaseController 的Prepare方法 | ||
21 | -func (c *OrderController) Prepare() { | ||
22 | - c.BaseController.Prepare() | ||
23 | - if ok := c.ValidJWTToken(); !ok { | ||
24 | - return | ||
25 | - } | ||
26 | - if ok := c.ValidAdminPermission(domain.PERMISSION_ORDER); !ok { | ||
27 | - return | ||
28 | - } | ||
29 | -} | ||
30 | - | ||
31 | -type orderDetail struct { | ||
32 | - //买家姓名 | ||
33 | - Buyer string `json:"buyer"` | ||
34 | - //买家联系方式 | ||
35 | - BuyerPhone string `json:"buyerPhone"` | ||
36 | - //收货地址 | ||
37 | - Address string `json:"address"` | ||
38 | - //对应合伙人 id | ||
39 | - Partner int64 `json:"partner"` | ||
40 | - //合伙人抽成比例 | ||
41 | - PartnerRatio float64 `json:"partnerRatio"` | ||
42 | - //业务员抽成比例 | ||
43 | - SalesmanRatio float64 `json:"salesmanRatio"` | ||
44 | - //订单号 | ||
45 | - OrderId string `json:"orderId"` | ||
46 | - //订单名称 | ||
47 | - OrderName string `json:"orderName"` | ||
48 | - //订单数量 | ||
49 | - OrderNum int `json:"orderNum"` | ||
50 | - //订单金额 | ||
51 | - OrderPrice float64 `json:"orderPrice"` | ||
52 | - //订单区域 | ||
53 | - OrderDist string `json:"orderDist"` | ||
54 | - //id | ||
55 | - Id int64 `json:"id"` | ||
56 | - //订单状态 | ||
57 | - OrderStatue int `json:"orderStatue"` | ||
58 | - //理由 | ||
59 | - Reason string `json:"reason"` | ||
60 | -} | ||
61 | - | ||
62 | -//UpdateOrderPurpose 更新意向订单 | ||
63 | -func (c *OrderController) UpdateOrderPurpose() { | ||
64 | - //用与适配前端定义的数据结构 | ||
65 | - var ( | ||
66 | - param orderDetail | ||
67 | - err error | ||
68 | - ) | ||
69 | - if err = c.BindJsonData(¶m); err != nil { | ||
70 | - logs.Error(err) | ||
71 | - c.ResponseError(errors.New("json数据解析失败")) | ||
72 | - return | ||
73 | - } | ||
74 | - if param.Id == 0 { | ||
75 | - err = c.addOrderPurpose(param) | ||
76 | - } else { | ||
77 | - err = c.editOrderPurpose(param) | ||
78 | - } | ||
79 | - if err != nil { | ||
80 | - c.ResponseError(err) | ||
81 | - } | ||
82 | - c.ResponseData(nil) | ||
83 | - return | ||
84 | -} | ||
85 | - | ||
86 | -func (c *OrderController) addOrderPurpose(param orderDetail) error { | ||
87 | - orderSrv := orderService.NewOrderService(nil) | ||
88 | - Createcmd := orderCmd.CreateOrderCommand{ | ||
89 | - //订单区域 | ||
90 | - OrderRegion: param.OrderDist, | ||
91 | - //订单编号 | ||
92 | - OrderCode: param.OrderId, | ||
93 | - //订单名称 | ||
94 | - OrderName: param.OrderName, | ||
95 | - //数量 | ||
96 | - OrderCount: param.OrderNum, | ||
97 | - OrderActualCount: param.OrderNum, | ||
98 | - //订单金额 | ||
99 | - OrderAmount: param.OrderPrice, | ||
100 | - OrderActualAmount: param.OrderPrice, | ||
101 | - //买家 | ||
102 | - BuyerName: param.Buyer, | ||
103 | - //买家电话 | ||
104 | - BuyerPhone: param.BuyerPhone, | ||
105 | - //地址 | ||
106 | - BuyerAddress: param.Address, | ||
107 | - //合伙人数据 | ||
108 | - PartnerId: param.Partner, | ||
109 | - //合伙人分红百分比 | ||
110 | - PartnerBonusPercent: param.PartnerRatio, | ||
111 | - //业务员分红百分比 | ||
112 | - SalesmanBonusPercent: param.SalesmanRatio, | ||
113 | - //订单类型 | ||
114 | - OrderType: domain.OrderIntention, | ||
115 | - OrderStatus: domain.OrderStatusReserve, | ||
116 | - } | ||
117 | - err := orderSrv.CreateOrder(Createcmd) | ||
118 | - return err | ||
119 | -} | ||
120 | - | ||
121 | -func (c *OrderController) editOrderPurpose(param orderDetail) error { | ||
122 | - updateCmd := orderCmd.UpdateOrderCommand{ | ||
123 | - Id: param.Id, | ||
124 | - //订单区域 | ||
125 | - OrderRegion: param.OrderDist, | ||
126 | - //订单编号 | ||
127 | - OrderCode: param.OrderId, | ||
128 | - //订单名称 | ||
129 | - OrderName: param.OrderName, | ||
130 | - //数量 | ||
131 | - OrderCount: param.OrderNum, | ||
132 | - //订单金额 | ||
133 | - OrderAmount: param.OrderPrice, | ||
134 | - //买家电话 | ||
135 | - BuyerPhone: param.BuyerPhone, | ||
136 | - //地址 | ||
137 | - BuyerAddress: param.Address, | ||
138 | - //合伙人分红百分比 | ||
139 | - PartnerBonusPercent: param.PartnerRatio, | ||
140 | - //业务员分红百分比 | ||
141 | - SalesmanBonusPercent: param.SalesmanRatio, | ||
142 | - | ||
143 | - OrderStatus: domain.OrderStatusReserve, | ||
144 | - | ||
145 | - OrderType: domain.OrderIntention, | ||
146 | - } | ||
147 | - orderSrv := orderService.NewOrderService(nil) | ||
148 | - err := orderSrv.UpdateOrderPurpose(updateCmd) | ||
149 | - return err | ||
150 | -} | ||
151 | - | ||
152 | -//GetOrderPurpose 获取意向订单 | ||
153 | -func (c *OrderController) GetOrderPurpose() { | ||
154 | - type Parameter struct { | ||
155 | - Id string `json:"id"` | ||
156 | - } | ||
157 | - var ( | ||
158 | - param Parameter | ||
159 | - err error | ||
160 | - ) | ||
161 | - if err = c.BindJsonData(¶m); err != nil { | ||
162 | - logs.Error(err) | ||
163 | - c.ResponseError(errors.New("json数据解析失败")) | ||
164 | - return | ||
165 | - } | ||
166 | - orderid, _ := strconv.ParseInt(param.Id, 10, 64) | ||
167 | - orderSrv := orderService.NewOrderService(nil) | ||
168 | - orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{ | ||
169 | - OrderId: orderid, | ||
170 | - }) | ||
171 | - if err != nil { | ||
172 | - c.ResponseError(err) | ||
173 | - return | ||
174 | - } | ||
175 | - rsp := map[string]interface{}{ | ||
176 | - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
177 | - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"), | ||
178 | - "buyer": orderinfo.Buyer.BuyerName, | ||
179 | - "buyerPhone": orderinfo.Buyer.ContactInfo, | ||
180 | - "address": orderinfo.Buyer.ShippingAddress, | ||
181 | - "id": orderinfo.Id, | ||
182 | - "partner": orderinfo.PartnerInfo.Id, | ||
183 | - "partnerRatio": orderinfo.PartnerBonusPercent, | ||
184 | - "salesmanRatio": orderinfo.SalesmanBonusPercent, | ||
185 | - "orderId": orderinfo.OrderCode, | ||
186 | - "orderName": orderinfo.OrderName, | ||
187 | - "orderNum": orderinfo.OrderCount, | ||
188 | - "orderPrice": orderinfo.OrderAmount, | ||
189 | - "orderDist": orderinfo.OrderRegionInfo.RegionName, | ||
190 | - "orderStatue": orderinfo.OrderStatus, | ||
191 | - } | ||
192 | - c.ResponseData(rsp) | ||
193 | -} | ||
194 | - | ||
195 | -//PageListOrderPurpose 分页获取意向订单列表 | ||
196 | -func (c *OrderController) PageListOrderPurpose() { | ||
197 | - type Parameter struct { | ||
198 | - SearchText string `json:"searchText"` | ||
199 | - Partner int64 `json:"partner"` | ||
200 | - PageSize int `json:"pageSize"` | ||
201 | - PageNumber int `json:"pageNumber"` | ||
202 | - } | ||
203 | - var ( | ||
204 | - param Parameter | ||
205 | - err error | ||
206 | - ) | ||
207 | - if err = c.BindJsonData(¶m); err != nil { | ||
208 | - logs.Error(err) | ||
209 | - c.ResponseError(errors.New("json数据解析失败")) | ||
210 | - return | ||
211 | - } | ||
212 | - if param.PageNumber == 0 { | ||
213 | - param.PageNumber = 1 | ||
214 | - } | ||
215 | - if param.PageSize == 0 { | ||
216 | - param.PageSize = 20 | ||
217 | - } | ||
218 | - | ||
219 | - orderSrv := orderService.NewOrderService(nil) | ||
220 | - orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{ | ||
221 | - PartnerId: param.Partner, | ||
222 | - OrderCode: param.SearchText, | ||
223 | - OrderType: domain.OrderIntention, | ||
224 | - Limit: param.PageSize, | ||
225 | - Offset: (param.PageNumber - 1) * param.PageSize, | ||
226 | - }) | ||
227 | - if err != nil { | ||
228 | - c.ResponseError(err) | ||
229 | - return | ||
230 | - } | ||
231 | - rsp := []map[string]interface{}{} | ||
232 | - for i := range orderinfos { | ||
233 | - orderinfo := orderinfos[i] | ||
234 | - m := map[string]interface{}{ | ||
235 | - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
236 | - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"), | ||
237 | - "buyer": orderinfo.Buyer.BuyerName, | ||
238 | - "id": orderinfo.Id, | ||
239 | - "orderId": orderinfo.OrderCode, | ||
240 | - "partner": orderinfo.PartnerInfo.PartnerName, | ||
241 | - "partnerRatio": orderinfo.PartnerBonusPercent, | ||
242 | - "orderName": orderinfo.OrderName, | ||
243 | - "orderNum": orderinfo.OrderCount, | ||
244 | - "orderPrice": orderinfo.OrderAmount, | ||
245 | - "orderDist": orderinfo.OrderRegionInfo.RegionName, | ||
246 | - "orderStatue": orderinfo.OrderStatus, | ||
247 | - } | ||
248 | - rsp = append(rsp, m) | ||
249 | - } | ||
250 | - c.ResponsePageList(rsp, cnt, param.PageNumber) | ||
251 | -} | ||
252 | - | ||
253 | -//RemoveOrderPurpose 删除意向订单 | ||
254 | -func (c *OrderController) RemoveOrderPurpose() { | ||
255 | - type Parameter struct { | ||
256 | - Id int64 `json:"id"` | ||
257 | - } | ||
258 | - var ( | ||
259 | - param Parameter | ||
260 | - err error | ||
261 | - ) | ||
262 | - if err = c.BindJsonData(¶m); err != nil { | ||
263 | - logs.Error(err) | ||
264 | - c.ResponseError(errors.New("json数据解析失败")) | ||
265 | - return | ||
266 | - } | ||
267 | - orderSrv := orderService.NewOrderService(nil) | ||
268 | - err = orderSrv.RemoveOrder(param.Id) | ||
269 | - if err != nil { | ||
270 | - c.ResponseError(err) | ||
271 | - return | ||
272 | - } | ||
273 | - c.ResponseData(nil) | ||
274 | -} | ||
275 | - | ||
276 | -//PageListOrderReal 分页获取实发订单列表 | ||
277 | -func (c *OrderController) PageListOrderReal() { | ||
278 | - type Parameter struct { | ||
279 | - SearchText string `json:"searchText"` | ||
280 | - Partner int64 `json:"partner"` | ||
281 | - PageSize int `json:"pageSize"` | ||
282 | - PageNumber int `json:"pageNumber"` | ||
283 | - } | ||
284 | - var ( | ||
285 | - param Parameter | ||
286 | - err error | ||
287 | - ) | ||
288 | - if err = c.BindJsonData(¶m); err != nil { | ||
289 | - logs.Error(err) | ||
290 | - c.ResponseError(errors.New("json数据解析失败")) | ||
291 | - return | ||
292 | - } | ||
293 | - if param.PageNumber == 0 { | ||
294 | - param.PageNumber = 1 | ||
295 | - } | ||
296 | - if param.PageSize == 0 { | ||
297 | - param.PageSize = 20 | ||
298 | - } | ||
299 | - | ||
300 | - orderSrv := orderService.NewOrderService(nil) | ||
301 | - orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{ | ||
302 | - PartnerId: param.Partner, | ||
303 | - OrderCode: param.SearchText, | ||
304 | - OrderType: domain.OrderReal, | ||
305 | - Limit: param.PageSize, | ||
306 | - Offset: (param.PageNumber - 1) * param.PageSize, | ||
307 | - }) | ||
308 | - if err != nil { | ||
309 | - c.ResponseError(err) | ||
310 | - return | ||
311 | - } | ||
312 | - rsp := []map[string]interface{}{} | ||
313 | - for i := range orderinfos { | ||
314 | - orderinfo := orderinfos[i] | ||
315 | - m := map[string]interface{}{ | ||
316 | - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
317 | - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"), | ||
318 | - "buyer": orderinfo.Buyer.BuyerName, | ||
319 | - "id": orderinfo.Id, | ||
320 | - "orderId": orderinfo.OrderCode, | ||
321 | - "partner": orderinfo.PartnerInfo.PartnerName, | ||
322 | - "partnerRatio": orderinfo.PartnerBonusPercent, | ||
323 | - "orderName": orderinfo.OrderName, | ||
324 | - "orderNum": orderinfo.OrderCount, | ||
325 | - "orderPrice": orderinfo.OrderAmount, | ||
326 | - "orderActualNum": orderinfo.OrderActualCount, | ||
327 | - "orderActualPrice": orderinfo.OrderActualAmount, | ||
328 | - "orderDist": orderinfo.OrderRegionInfo.RegionName, | ||
329 | - "orderStatue": orderinfo.OrderStatus, | ||
330 | - } | ||
331 | - rsp = append(rsp, m) | ||
332 | - } | ||
333 | - c.ResponsePageList(rsp, cnt, param.PageNumber) | ||
334 | -} | ||
335 | - | ||
336 | -//UpdateOrderPurpose 意向订单转实发单 | ||
337 | -func (c *OrderController) OrderPurposeToReal() { | ||
338 | - //用与适配前端定义的数据结构 | ||
339 | - var ( | ||
340 | - param orderDetail | ||
341 | - err error | ||
342 | - ) | ||
343 | - if err = c.BindJsonData(¶m); err != nil { | ||
344 | - logs.Error(err) | ||
345 | - c.ResponseError(errors.New("json数据解析失败")) | ||
346 | - return | ||
347 | - } | ||
348 | - orderSrv := orderService.NewOrderService(nil) | ||
349 | - if param.Id > 0 { | ||
350 | - err = orderSrv.UpdateOrderPurpose(orderCmd.UpdateOrderCommand{ | ||
351 | - Id: param.Id, | ||
352 | - OrderCode: param.OrderId, | ||
353 | - OrderName: param.OrderName, | ||
354 | - OrderCount: param.OrderNum, | ||
355 | - OrderAmount: param.OrderPrice, | ||
356 | - BuyerPhone: param.BuyerPhone, | ||
357 | - BuyerAddress: param.Address, | ||
358 | - OrderRegion: param.OrderDist, | ||
359 | - PartnerBonusPercent: param.PartnerRatio, | ||
360 | - SalesmanBonusPercent: param.SalesmanRatio, | ||
361 | - OrderStatus: param.OrderStatue, | ||
362 | - OrderType: domain.OrderReal, | ||
363 | - }) | ||
364 | - } else { | ||
365 | - err = c.addOrderReal(param) | ||
366 | - } | ||
367 | - if err != nil { | ||
368 | - c.ResponseError(err) | ||
369 | - return | ||
370 | - } | ||
371 | - c.ResponseData(nil) | ||
372 | - return | ||
373 | -} | ||
374 | - | ||
375 | -//GetOrderReal 获取实发单详情 | ||
376 | -func (c *OrderController) GetOrderReal() { | ||
377 | - type Parameter struct { | ||
378 | - Id string `json:"id"` | ||
379 | - } | ||
380 | - var ( | ||
381 | - param Parameter | ||
382 | - err error | ||
383 | - ) | ||
384 | - if err = c.BindJsonData(¶m); err != nil { | ||
385 | - logs.Error(err) | ||
386 | - c.ResponseError(errors.New("json数据解析失败")) | ||
387 | - return | ||
388 | - } | ||
389 | - orderid, _ := strconv.ParseInt(param.Id, 10, 64) | ||
390 | - orderSrv := orderService.NewOrderService(nil) | ||
391 | - orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{ | ||
392 | - OrderId: orderid, | ||
393 | - }) | ||
394 | - if err != nil { | ||
395 | - c.ResponseError(err) | ||
396 | - return | ||
397 | - } | ||
398 | - rsp := map[string]interface{}{ | ||
399 | - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"), | ||
400 | - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"), | ||
401 | - "buyer": orderinfo.Buyer.BuyerName, | ||
402 | - "buyerPhone": orderinfo.Buyer.ContactInfo, | ||
403 | - "address": orderinfo.Buyer.ShippingAddress, | ||
404 | - "id": orderinfo.Id, | ||
405 | - "partner": orderinfo.PartnerInfo.Id, | ||
406 | - "partnerRatio": orderinfo.PartnerBonusPercent, | ||
407 | - "salesmanRatio": orderinfo.SalesmanBonusPercent, | ||
408 | - "orderId": orderinfo.OrderCode, | ||
409 | - "orderName": orderinfo.OrderName, | ||
410 | - "orderNum": orderinfo.OrderActualCount, | ||
411 | - "orderPrice": orderinfo.OrderActualAmount, | ||
412 | - "orderDist": orderinfo.OrderRegionInfo.RegionName, | ||
413 | - "orderStatue": orderinfo.OrderStatus, | ||
414 | - "reason": orderinfo.Reason, | ||
415 | - } | ||
416 | - c.ResponseData(rsp) | ||
417 | -} | ||
418 | - | ||
419 | -//UpdateOrderReal 更新实发订单数据 | ||
420 | -func (c *OrderController) UpdateOrderReal() { | ||
421 | - //用与适配前端定义的数据结构 | ||
422 | - var ( | ||
423 | - param orderDetail | ||
424 | - err error | ||
425 | - ) | ||
426 | - if err = c.BindJsonData(¶m); err != nil { | ||
427 | - logs.Error(err) | ||
428 | - c.ResponseError(errors.New("json数据解析失败")) | ||
429 | - return | ||
430 | - } | ||
431 | - if param.Id == 0 { | ||
432 | - err = c.addOrderReal(param) | ||
433 | - } else { | ||
434 | - err = c.editOrderReal(param) | ||
435 | - } | ||
436 | - if err != nil { | ||
437 | - c.ResponseError(err) | ||
438 | - } | ||
439 | - c.ResponseData(nil) | ||
440 | - return | ||
441 | -} | ||
442 | - | ||
443 | -//addOrderReal 添加实发订单 | ||
444 | -func (c *OrderController) addOrderReal(param orderDetail) error { | ||
445 | - orderSrv := orderService.NewOrderService(nil) | ||
446 | - if !(param.OrderStatue == domain.OrderStatusDeliverAll || | ||
447 | - param.OrderStatue == domain.OrderStatusDeliverSome) { | ||
448 | - return lib.ThrowError(lib.ARG_ERROR, "订单状态错误") | ||
449 | - } | ||
450 | - Createcmd := orderCmd.CreateOrderCommand{ | ||
451 | - //订单区域 | ||
452 | - OrderRegion: param.OrderDist, | ||
453 | - //订单编号 | ||
454 | - OrderCode: param.OrderId, | ||
455 | - //订单名称 | ||
456 | - OrderName: param.OrderName, | ||
457 | - //数量 | ||
458 | - OrderCount: param.OrderNum, | ||
459 | - OrderActualCount: param.OrderNum, | ||
460 | - //订单金额 | ||
461 | - OrderAmount: param.OrderPrice, | ||
462 | - OrderActualAmount: param.OrderPrice, | ||
463 | - //买家 | ||
464 | - BuyerName: param.Buyer, | ||
465 | - //买家电话 | ||
466 | - BuyerPhone: param.BuyerPhone, | ||
467 | - //地址 | ||
468 | - BuyerAddress: param.Address, | ||
469 | - //合伙人数据 | ||
470 | - PartnerId: param.Partner, | ||
471 | - //合伙人分红百分比 | ||
472 | - PartnerBonusPercent: param.PartnerRatio, | ||
473 | - //业务员分红百分比 | ||
474 | - SalesmanBonusPercent: param.SalesmanRatio, | ||
475 | - //订单类型 | ||
476 | - OrderType: domain.OrderReal, | ||
477 | - //状态 | ||
478 | - OrderStatus: param.OrderStatue, | ||
479 | - } | ||
480 | - err := orderSrv.CreateOrder(Createcmd) | ||
481 | - return err | ||
482 | -} | ||
483 | - | ||
484 | -//editOrderReal 更新实发订单 | ||
485 | -func (c *OrderController) editOrderReal(param orderDetail) error { | ||
486 | - updateCmd := orderCmd.UpdateOrderRealCommand{ | ||
487 | - Id: param.Id, | ||
488 | - //订单区域 | ||
489 | - OrderRegion: param.OrderDist, | ||
490 | - //订单编号 | ||
491 | - OrderCode: param.OrderId, | ||
492 | - //订单名称 | ||
493 | - OrderName: param.OrderName, | ||
494 | - //数量 | ||
495 | - OrderActualCount: param.OrderNum, | ||
496 | - //订单金额 | ||
497 | - OrderActualAmount: param.OrderPrice, | ||
498 | - //买家电话 | ||
499 | - BuyerPhone: param.BuyerPhone, | ||
500 | - //地址 | ||
501 | - BuyerAddress: param.Address, | ||
502 | - //合伙人分红百分比 | ||
503 | - PartnerBonusPercent: param.PartnerRatio, | ||
504 | - //业务员分红百分比 | ||
505 | - SalesmanBonusPercent: param.SalesmanRatio, | ||
506 | - //状态 | ||
507 | - OrderStatus: param.OrderStatue, | ||
508 | - //理由 | ||
509 | - Reason: param.Reason, | ||
510 | - } | ||
511 | - orderSrv := orderService.NewOrderService(nil) | ||
512 | - err := orderSrv.UpdateOrderReal(updateCmd) | ||
513 | - return err | ||
514 | -} |
-
请 注册 或 登录 后发表评论