作者 tangxvhui

清理 无效的旧代码

@@ -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 -  
33 -func (command UpdateOrderCommand) ValidateCommand() error {  
34 - if command.Id == 0 {  
35 - return lib.ThrowError(lib.ARG_ERROR, "订单id错误")  
36 - }  
37 - if len(command.BuyerPhone) == 0 {  
38 - return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")  
39 - }  
40 - if len(command.BuyerAddress) == 0 {  
41 - return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")  
42 - }  
43 - if len(command.OrderCode) == 0 {  
44 - return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")  
45 - }  
46 - if len(command.OrderRegion) == 0 {  
47 - return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")  
48 - }  
49 - if !(command.OrderStatus == domain.OrderStatusDeliverSome ||  
50 - command.OrderStatus == domain.OrderStatusDeliverAll ||  
51 - command.OrderStatus == domain.OrderStatusReserve) {  
52 - return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")  
53 - }  
54 - return nil  
55 -}  
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 -}  
1 -package query  
2 -  
3 -//GetOrderQuery 获取订单详情  
4 -type GetOrderQuery struct {  
5 - OrderId int64 `json:"orderId"`  
6 -}  
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 -}  
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 - }  
267 -  
268 - err = orderData.Update(updateMap)  
269 - if err != nil {  
270 - return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())  
271 - }  
272 - err = orderRepository.Save(orderData)  
273 - if err != nil {  
274 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
275 - }  
276 - err = transactionContext.CommitTransaction()  
277 - if err != nil {  
278 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
279 - }  
280 - return nil  
281 -}  
282 -  
283 -//RemoveOrder 删除意向单  
284 -func (service OrderService) RemoveOrder(id int64) error {  
285 - //实际业务  
286 - transactionContext, err := factory.CreateTransactionContext(nil)  
287 - if err != nil {  
288 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
289 - }  
290 - if err = transactionContext.StartTransaction(); err != nil {  
291 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
292 - }  
293 - defer func() {  
294 - transactionContext.RollbackTransaction()  
295 - }()  
296 - var (  
297 - orderRepository domain.OrderRepository  
298 - order *domain.Order  
299 - )  
300 - if value, err := factory.CreateOrderRepository(map[string]interface{}{  
301 - "transactionContext": transactionContext,  
302 - }); err != nil {  
303 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
304 - } else {  
305 - orderRepository = value  
306 - }  
307 - order, err = orderRepository.FindOne(domain.OrderFindOneQuery{  
308 - OrderId: id,  
309 - })  
310 - if err != nil {  
311 - return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())  
312 - }  
313 - if order.OrderType != domain.OrderIntention {  
314 - return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")  
315 - }  
316 - err = orderRepository.Remove(order.Id)  
317 - if err != nil {  
318 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
319 - }  
320 - err = transactionContext.CommitTransaction()  
321 - if err != nil {  
322 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
323 - }  
324 - return nil  
325 -}  
326 -  
327 -//UpdateOrderReal 更新为实发单  
328 -func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {  
329 - var (  
330 - transactionContext, _ = factory.CreateTransactionContext(nil)  
331 - err error  
332 - )  
333 - if err = command.ValidateCommand(); err != nil {  
334 - return lib.ThrowError(lib.ARG_ERROR, err.Error())  
335 - }  
336 - if err = transactionContext.StartTransaction(); err != nil {  
337 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
338 - }  
339 - defer func() {  
340 - transactionContext.RollbackTransaction()  
341 - }()  
342 - orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})  
343 - ok, err := orderDao.OrderCodeIsExist(command.OrderCode, command.Id)  
344 - if err != nil {  
345 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
346 - }  
347 - if ok {  
348 - return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")  
349 - }  
350 - var (  
351 - orderRepository domain.OrderRepository  
352 - orderData *domain.Order  
353 - )  
354 - if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{  
355 - "transactionContext": transactionContext,  
356 - }); err != nil {  
357 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
358 - }  
359 - orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{  
360 - OrderId: command.Id,  
361 - })  
362 - if err != nil {  
363 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
364 - }  
365 - err = orderData.Update(map[string]interface{}{  
366 - //订单编号  
367 - "orderCode": command.OrderCode,  
368 - "oderName": command.OrderName,  
369 - "orderActualCount": command.OrderActualCount,  
370 - "orderActualAmount": command.OrderActualAmount,  
371 - "buyer": domain.Buyer{  
372 - BuyerName: orderData.Buyer.BuyerName,  
373 - ContactInfo: command.BuyerPhone,  
374 - ShippingAddress: command.BuyerAddress,  
375 - },  
376 - "orderRegion": domain.RegionInfo{  
377 - RegionName: command.OrderRegion,  
378 - },  
379 - "partnerBonusPercent": command.PartnerBonusPercent,  
380 - "salesmanBonusPercent": command.SalesmanBonusPercent,  
381 - "orderStatus": command.OrderStatus,  
382 - "orderType": domain.OrderReal,  
383 - "reason": command.Reason,  
384 - })  
385 - if err != nil {  
386 - return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())  
387 - }  
388 - err = orderRepository.Save(orderData)  
389 - if err != nil {  
390 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
391 - }  
392 - err = transactionContext.CommitTransaction()  
393 - if err != nil {  
394 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
395 - }  
396 - return nil  
397 -}  
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 query  
2 -  
3 -type GetOrderPaymentQuery struct {  
4 - // 合伙人类别  
5 - OrderId int64 `json:"orderId"`  
6 -}  
7 -  
8 -func (q *GetOrderPaymentQuery) ValidateQuery() error {  
9 -  
10 - return nil  
11 -}  
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 -}  
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 -}  
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 -}  
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(&param); 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(&param); 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(&param); 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(&param)  
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(&param); 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 - orderSrv := orderService.NewOrderService(nil)  
146 - err := orderSrv.UpdateOrderPurpose(updateCmd)  
147 - return err  
148 -}  
149 -  
150 -//GetOrderPurpose 获取意向订单  
151 -func (c *OrderController) GetOrderPurpose() {  
152 - type Parameter struct {  
153 - Id string `json:"id"`  
154 - }  
155 - var (  
156 - param Parameter  
157 - err error  
158 - )  
159 - if err = c.BindJsonData(&param); err != nil {  
160 - logs.Error(err)  
161 - c.ResponseError(errors.New("json数据解析失败"))  
162 - return  
163 - }  
164 - orderid, _ := strconv.ParseInt(param.Id, 10, 64)  
165 - orderSrv := orderService.NewOrderService(nil)  
166 - orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{  
167 - OrderId: orderid,  
168 - })  
169 - if err != nil {  
170 - c.ResponseError(err)  
171 - return  
172 - }  
173 - rsp := map[string]interface{}{  
174 - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),  
175 - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),  
176 - "buyer": orderinfo.Buyer.BuyerName,  
177 - "buyerPhone": orderinfo.Buyer.ContactInfo,  
178 - "address": orderinfo.Buyer.ShippingAddress,  
179 - "id": orderinfo.Id,  
180 - "partner": orderinfo.PartnerInfo.Id,  
181 - "partnerRatio": orderinfo.PartnerBonusPercent,  
182 - "salesmanRatio": orderinfo.SalesmanBonusPercent,  
183 - "orderId": orderinfo.OrderCode,  
184 - "orderName": orderinfo.OrderName,  
185 - "orderNum": orderinfo.OrderCount,  
186 - "orderPrice": orderinfo.OrderAmount,  
187 - "orderDist": orderinfo.OrderRegionInfo.RegionName,  
188 - "orderStatue": orderinfo.OrderStatus,  
189 - }  
190 - c.ResponseData(rsp)  
191 -}  
192 -  
193 -//PageListOrderPurpose 分页获取意向订单列表  
194 -func (c *OrderController) PageListOrderPurpose() {  
195 - type Parameter struct {  
196 - SearchText string `json:"searchText"`  
197 - Partner int64 `json:"partner"`  
198 - PageSize int `json:"pageSize"`  
199 - PageNumber int `json:"pageNumber"`  
200 - }  
201 - var (  
202 - param Parameter  
203 - err error  
204 - )  
205 - if err = c.BindJsonData(&param); err != nil {  
206 - logs.Error(err)  
207 - c.ResponseError(errors.New("json数据解析失败"))  
208 - return  
209 - }  
210 - if param.PageNumber == 0 {  
211 - param.PageNumber = 1  
212 - }  
213 - if param.PageSize == 0 {  
214 - param.PageSize = 20  
215 - }  
216 -  
217 - orderSrv := orderService.NewOrderService(nil)  
218 - orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{  
219 - PartnerId: param.Partner,  
220 - OrderCode: param.SearchText,  
221 - OrderType: domain.OrderIntention,  
222 - Limit: param.PageSize,  
223 - Offset: (param.PageNumber - 1) * param.PageSize,  
224 - })  
225 - if err != nil {  
226 - c.ResponseError(err)  
227 - return  
228 - }  
229 - rsp := []map[string]interface{}{}  
230 - for i := range orderinfos {  
231 - orderinfo := orderinfos[i]  
232 - m := map[string]interface{}{  
233 - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),  
234 - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),  
235 - "buyer": orderinfo.Buyer.BuyerName,  
236 - "id": orderinfo.Id,  
237 - "orderId": orderinfo.OrderCode,  
238 - "partner": orderinfo.PartnerInfo.PartnerName,  
239 - "partnerRatio": orderinfo.PartnerBonusPercent,  
240 - "orderName": orderinfo.OrderName,  
241 - "orderNum": orderinfo.OrderCount,  
242 - "orderPrice": orderinfo.OrderAmount,  
243 - "orderDist": orderinfo.OrderRegionInfo.RegionName,  
244 - "orderStatue": orderinfo.OrderStatus,  
245 - }  
246 - rsp = append(rsp, m)  
247 - }  
248 - c.ResponsePageList(rsp, cnt, param.PageNumber)  
249 -}  
250 -  
251 -//RemoveOrderPurpose 删除意向订单  
252 -func (c *OrderController) RemoveOrderPurpose() {  
253 - type Parameter struct {  
254 - Id int64 `json:"id"`  
255 - }  
256 - var (  
257 - param Parameter  
258 - err error  
259 - )  
260 - if err = c.BindJsonData(&param); err != nil {  
261 - logs.Error(err)  
262 - c.ResponseError(errors.New("json数据解析失败"))  
263 - return  
264 - }  
265 - orderSrv := orderService.NewOrderService(nil)  
266 - err = orderSrv.RemoveOrder(param.Id)  
267 - if err != nil {  
268 - c.ResponseError(err)  
269 - return  
270 - }  
271 - c.ResponseData(nil)  
272 -}  
273 -  
274 -//PageListOrderReal 分页获取实发订单列表  
275 -func (c *OrderController) PageListOrderReal() {  
276 - type Parameter struct {  
277 - SearchText string `json:"searchText"`  
278 - Partner int64 `json:"partner"`  
279 - PageSize int `json:"pageSize"`  
280 - PageNumber int `json:"pageNumber"`  
281 - }  
282 - var (  
283 - param Parameter  
284 - err error  
285 - )  
286 - if err = c.BindJsonData(&param); err != nil {  
287 - logs.Error(err)  
288 - c.ResponseError(errors.New("json数据解析失败"))  
289 - return  
290 - }  
291 - if param.PageNumber == 0 {  
292 - param.PageNumber = 1  
293 - }  
294 - if param.PageSize == 0 {  
295 - param.PageSize = 20  
296 - }  
297 -  
298 - orderSrv := orderService.NewOrderService(nil)  
299 - orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{  
300 - PartnerId: param.Partner,  
301 - OrderCode: param.SearchText,  
302 - OrderType: domain.OrderReal,  
303 - Limit: param.PageSize,  
304 - Offset: (param.PageNumber - 1) * param.PageSize,  
305 - })  
306 - if err != nil {  
307 - c.ResponseError(err)  
308 - return  
309 - }  
310 - rsp := []map[string]interface{}{}  
311 - for i := range orderinfos {  
312 - orderinfo := orderinfos[i]  
313 - m := map[string]interface{}{  
314 - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),  
315 - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),  
316 - "buyer": orderinfo.Buyer.BuyerName,  
317 - "id": orderinfo.Id,  
318 - "orderId": orderinfo.OrderCode,  
319 - "partner": orderinfo.PartnerInfo.PartnerName,  
320 - "partnerRatio": orderinfo.PartnerBonusPercent,  
321 - "orderName": orderinfo.OrderName,  
322 - "orderNum": orderinfo.OrderCount,  
323 - "orderPrice": orderinfo.OrderAmount,  
324 - "orderActualNum": orderinfo.OrderActualCount,  
325 - "orderActualPrice": orderinfo.OrderActualAmount,  
326 - "orderDist": orderinfo.OrderRegionInfo.RegionName,  
327 - "orderStatue": orderinfo.OrderStatus,  
328 - }  
329 - rsp = append(rsp, m)  
330 - }  
331 - c.ResponsePageList(rsp, cnt, param.PageNumber)  
332 -}  
333 -  
334 -//UpdateOrderPurpose 意向订单转实发单  
335 -func (c *OrderController) OrderPurposeToReal() {  
336 - //用与适配前端定义的数据结构  
337 - var (  
338 - param orderDetail  
339 - err error  
340 - )  
341 - if err = c.BindJsonData(&param); err != nil {  
342 - logs.Error(err)  
343 - c.ResponseError(errors.New("json数据解析失败"))  
344 - return  
345 - }  
346 - orderSrv := orderService.NewOrderService(nil)  
347 - if param.Id > 0 {  
348 - err = orderSrv.UpdateOrderPurpose(orderCmd.UpdateOrderCommand{  
349 - Id: param.Id,  
350 - OrderCode: param.OrderId,  
351 - OrderName: param.OrderName,  
352 - OrderCount: param.OrderNum,  
353 - OrderAmount: param.OrderPrice,  
354 - BuyerPhone: param.BuyerPhone,  
355 - BuyerAddress: param.Address,  
356 - OrderRegion: param.OrderDist,  
357 - PartnerBonusPercent: param.PartnerRatio,  
358 - SalesmanBonusPercent: param.SalesmanRatio,  
359 - OrderStatus: param.OrderStatue,  
360 - })  
361 - } else {  
362 - err = c.addOrderReal(param)  
363 - }  
364 - if err != nil {  
365 - c.ResponseError(err)  
366 - return  
367 - }  
368 - c.ResponseData(nil)  
369 - return  
370 -}  
371 -  
372 -//GetOrderReal 获取实发单详情  
373 -func (c *OrderController) GetOrderReal() {  
374 - type Parameter struct {  
375 - Id string `json:"id"`  
376 - }  
377 - var (  
378 - param Parameter  
379 - err error  
380 - )  
381 - if err = c.BindJsonData(&param); err != nil {  
382 - logs.Error(err)  
383 - c.ResponseError(errors.New("json数据解析失败"))  
384 - return  
385 - }  
386 - orderid, _ := strconv.ParseInt(param.Id, 10, 64)  
387 - orderSrv := orderService.NewOrderService(nil)  
388 - orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{  
389 - OrderId: orderid,  
390 - })  
391 - if err != nil {  
392 - c.ResponseError(err)  
393 - return  
394 - }  
395 - rsp := map[string]interface{}{  
396 - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),  
397 - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),  
398 - "buyer": orderinfo.Buyer.BuyerName,  
399 - "buyerPhone": orderinfo.Buyer.ContactInfo,  
400 - "address": orderinfo.Buyer.ShippingAddress,  
401 - "id": orderinfo.Id,  
402 - "partner": orderinfo.PartnerInfo.Id,  
403 - "partnerRatio": orderinfo.PartnerBonusPercent,  
404 - "salesmanRatio": orderinfo.SalesmanBonusPercent,  
405 - "orderId": orderinfo.OrderCode,  
406 - "orderName": orderinfo.OrderName,  
407 - "orderNum": orderinfo.OrderActualCount,  
408 - "orderPrice": orderinfo.OrderActualAmount,  
409 - "orderDist": orderinfo.OrderRegionInfo.RegionName,  
410 - "orderStatue": orderinfo.OrderStatus,  
411 - "reason": orderinfo.Reason,  
412 - }  
413 - c.ResponseData(rsp)  
414 -}  
415 -  
416 -//UpdateOrderReal 更新实发订单数据  
417 -func (c *OrderController) UpdateOrderReal() {  
418 - //用与适配前端定义的数据结构  
419 - var (  
420 - param orderDetail  
421 - err error  
422 - )  
423 - if err = c.BindJsonData(&param); err != nil {  
424 - logs.Error(err)  
425 - c.ResponseError(errors.New("json数据解析失败"))  
426 - return  
427 - }  
428 - if param.Id == 0 {  
429 - err = c.addOrderReal(param)  
430 - } else {  
431 - err = c.editOrderReal(param)  
432 - }  
433 - if err != nil {  
434 - c.ResponseError(err)  
435 - }  
436 - c.ResponseData(nil)  
437 - return  
438 -}  
439 -  
440 -//addOrderReal 添加实发订单  
441 -func (c *OrderController) addOrderReal(param orderDetail) error {  
442 - orderSrv := orderService.NewOrderService(nil)  
443 - if !(param.OrderStatue == domain.OrderStatusDeliverAll ||  
444 - param.OrderStatue == domain.OrderStatusDeliverSome) {  
445 - return lib.ThrowError(lib.ARG_ERROR, "订单状态错误")  
446 - }  
447 - Createcmd := orderCmd.CreateOrderCommand{  
448 - //订单区域  
449 - OrderRegion: param.OrderDist,  
450 - //订单编号  
451 - OrderCode: param.OrderId,  
452 - //订单名称  
453 - OrderName: param.OrderName,  
454 - //数量  
455 - OrderCount: param.OrderNum,  
456 - OrderActualCount: param.OrderNum,  
457 - //订单金额  
458 - OrderAmount: param.OrderPrice,  
459 - OrderActualAmount: param.OrderPrice,  
460 - //买家  
461 - BuyerName: param.Buyer,  
462 - //买家电话  
463 - BuyerPhone: param.BuyerPhone,  
464 - //地址  
465 - BuyerAddress: param.Address,  
466 - //合伙人数据  
467 - PartnerId: param.Partner,  
468 - //合伙人分红百分比  
469 - PartnerBonusPercent: param.PartnerRatio,  
470 - //业务员分红百分比  
471 - SalesmanBonusPercent: param.SalesmanRatio,  
472 - //订单类型  
473 - OrderType: domain.OrderReal,  
474 - //状态  
475 - OrderStatus: param.OrderStatue,  
476 - }  
477 - err := orderSrv.CreateOrder(Createcmd)  
478 - return err  
479 -}  
480 -  
481 -//editOrderReal 更新实发订单  
482 -func (c *OrderController) editOrderReal(param orderDetail) error {  
483 - updateCmd := orderCmd.UpdateOrderRealCommand{  
484 - Id: param.Id,  
485 - //订单区域  
486 - OrderRegion: param.OrderDist,  
487 - //订单编号  
488 - OrderCode: param.OrderId,  
489 - //订单名称  
490 - OrderName: param.OrderName,  
491 - //数量  
492 - OrderActualCount: param.OrderNum,  
493 - //订单金额  
494 - OrderActualAmount: param.OrderPrice,  
495 - //买家电话  
496 - BuyerPhone: param.BuyerPhone,  
497 - //地址  
498 - BuyerAddress: param.Address,  
499 - //合伙人分红百分比  
500 - PartnerBonusPercent: param.PartnerRatio,  
501 - //业务员分红百分比  
502 - SalesmanBonusPercent: param.SalesmanRatio,  
503 - //状态  
504 - OrderStatus: param.OrderStatue,  
505 - //理由  
506 - Reason: param.Reason,  
507 - }  
508 - orderSrv := orderService.NewOrderService(nil)  
509 - err := orderSrv.UpdateOrderReal(updateCmd)  
510 - return err  
511 -}