正在显示
20 个修改的文件
包含
242 行增加
和
75 行删除
@@ -22,6 +22,14 @@ func CreateReceivingService(options map[string]interface{}) (service.ReceivingGo | @@ -22,6 +22,14 @@ func CreateReceivingService(options map[string]interface{}) (service.ReceivingGo | ||
22 | return domainService.NewReceivingGoodsService(transactionContext) | 22 | return domainService.NewReceivingGoodsService(transactionContext) |
23 | } | 23 | } |
24 | 24 | ||
25 | +func CreateCreateOrderService(options map[string]interface{}) (service.CreateOrderService, error) { | ||
26 | + var transactionContext *pgTransaction.TransactionContext | ||
27 | + if value, ok := options["transactionContext"]; ok { | ||
28 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
29 | + } | ||
30 | + return domainService.NewCreateOrderService(transactionContext) | ||
31 | +} | ||
32 | + | ||
25 | func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) { | 33 | func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) { |
26 | var transactionContext *pgTransaction.TransactionContext | 34 | var transactionContext *pgTransaction.TransactionContext |
27 | if value, ok := options["transactionContext"]; ok { | 35 | if value, ok := options["transactionContext"]; ok { |
@@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
5 | 6 | ||
6 | "github.com/beego/beego/v2/core/validation" | 7 | "github.com/beego/beego/v2/core/validation" |
7 | ) | 8 | ) |
@@ -31,6 +32,12 @@ type CreateOrderCommand struct { | @@ -31,6 +32,12 @@ type CreateOrderCommand struct { | ||
31 | OrderStatus int `json:"orderStatus"` | 32 | OrderStatus int `json:"orderStatus"` |
32 | // 订单类型 | 33 | // 订单类型 |
33 | OrderType int `json:"orderType"` | 34 | OrderType int `json:"orderType"` |
35 | + // 订单商品 | ||
36 | + OrderGoods []*domain.Good `json:"orderGoods"` | ||
37 | + // 合伙人分红比例 | ||
38 | + PartnerBonusPercent float64 `json:"partnerBonusPercent"` | ||
39 | + // 业务员抽成比例 | ||
40 | + SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` | ||
34 | } | 41 | } |
35 | 42 | ||
36 | func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { | 43 | func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) { |
@@ -12,7 +12,7 @@ type RemoveOrderCommand struct { | @@ -12,7 +12,7 @@ type RemoveOrderCommand struct { | ||
12 | } | 12 | } |
13 | 13 | ||
14 | func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) { | 14 | func (removeOrderCommand *RemoveOrderCommand) Valid(validation *validation.Validation) { |
15 | - validation.SetError("CustomValid", "未实现的自定义认证") | 15 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
16 | } | 16 | } |
17 | 17 | ||
18 | func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error { | 18 | func (removeOrderCommand *RemoveOrderCommand) ValidateCommand() error { |
@@ -12,11 +12,11 @@ type UpdateOrderCommand struct { | @@ -12,11 +12,11 @@ type UpdateOrderCommand struct { | ||
12 | // 发货地址 | 12 | // 发货地址 |
13 | BuyerName string `json:"buyerName"` | 13 | BuyerName string `json:"buyerName"` |
14 | // 订单商品总数 | 14 | // 订单商品总数 |
15 | - OrderNum string `json:"orderNum"` | 15 | + OrderNum int `json:"orderNum"` |
16 | // 订单总价 | 16 | // 订单总价 |
17 | TotalPrice float64 `json:"totalPrice"` | 17 | TotalPrice float64 `json:"totalPrice"` |
18 | // 收货地址 | 18 | // 收货地址 |
19 | - ShippingAddress string `json:"shippingAddress" valid:"omitempty"` | 19 | + ShippingAddress string `json:"shippingAddress,omitempty"` |
20 | } | 20 | } |
21 | 21 | ||
22 | func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { | 22 | func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) { |
@@ -12,7 +12,7 @@ type GetOrderQuery struct { | @@ -12,7 +12,7 @@ type GetOrderQuery struct { | ||
12 | } | 12 | } |
13 | 13 | ||
14 | func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) { | 14 | func (getOrderQuery *GetOrderQuery) Valid(validation *validation.Validation) { |
15 | - validation.SetError("CustomValid", "未实现的自定义认证") | 15 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
16 | } | 16 | } |
17 | 17 | ||
18 | func (getOrderQuery *GetOrderQuery) ValidateQuery() error { | 18 | func (getOrderQuery *GetOrderQuery) ValidateQuery() error { |
@@ -8,13 +8,13 @@ import ( | @@ -8,13 +8,13 @@ import ( | ||
8 | 8 | ||
9 | type ListOrderQuery struct { | 9 | type ListOrderQuery struct { |
10 | // 查询偏离量 | 10 | // 查询偏离量 |
11 | - Offset int `json:"offset" valid:"Required"` | 11 | + Offset int `json:"offset"` |
12 | // 查询限制 | 12 | // 查询限制 |
13 | Limit int `json:"limit" valid:"Required"` | 13 | Limit int `json:"limit" valid:"Required"` |
14 | } | 14 | } |
15 | 15 | ||
16 | func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) { | 16 | func (listOrderQuery *ListOrderQuery) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (listOrderQuery *ListOrderQuery) ValidateQuery() error { | 20 | func (listOrderQuery *ListOrderQuery) ValidateQuery() error { |
@@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
9 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query" | 9 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/order/query" |
10 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" |
11 | "strconv" | 11 | "strconv" |
12 | + "time" | ||
12 | ) | 13 | ) |
13 | 14 | ||
14 | // 订单基础服务 | 15 | // 订单基础服务 |
@@ -52,23 +53,36 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create | @@ -52,23 +53,36 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create | ||
52 | _ = transactionContext.RollbackTransaction() | 53 | _ = transactionContext.RollbackTransaction() |
53 | }() | 54 | }() |
54 | newOrder := &domain.Order{ | 55 | newOrder := &domain.Order{ |
55 | - OrderNo: createOrderCommand.OrderNo, | ||
56 | - CompanyId: createOrderCommand.CompanyId, | 56 | + OrderNo: createOrderCommand.OrderNo, |
57 | + CompanyId: createOrderCommand.CompanyId, | ||
58 | + PartnerId: createOrderCommand.PartnerId, | ||
59 | + IsDisable: false, | ||
60 | + OrderGoods: createOrderCommand.OrderGoods, | ||
61 | + OrderDividend: &domain.Dividend{ | ||
62 | + PartnerBonusPercent: createOrderCommand.PartnerBonusPercent, | ||
63 | + SalesmanBonusPercent: createOrderCommand.SalesmanBonusPercent, | ||
64 | + }, | ||
57 | Buyer: &domain.BuyerInfo{ | 65 | Buyer: &domain.BuyerInfo{ |
58 | - BuyerName: createOrderCommand.BuyerName, | 66 | + BuyerName: createOrderCommand.BuyerName, |
67 | + ContactInfo: createOrderCommand.ContactInfo, | ||
68 | + ShippingAddress: createOrderCommand.ShippingAddress, | ||
69 | + Remarks: createOrderCommand.Remarks, | ||
59 | }, | 70 | }, |
60 | - TotalPrice: createOrderCommand.TotalPrice, | 71 | + TotalPrice: createOrderCommand.TotalPrice, |
72 | + CreateAt: time.Now(), | ||
73 | + OrderStatus: domain.ORDER_STATUS_UNSHIPPED, | ||
74 | + OrderType: createOrderCommand.OrderType, | ||
75 | + CurrentStatus: &domain.UnShippedStatus{}, | ||
61 | } | 76 | } |
62 | - var orderRepository domain.OrderRepository | ||
63 | - if value, err := factory.CreateOrderRepository(map[string]interface{}{ | 77 | + createOrderService, err := factory.CreateCreateOrderService(map[string]interface{}{ |
64 | "transactionContext": transactionContext, | 78 | "transactionContext": transactionContext, |
65 | - }); err != nil { | ||
66 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
67 | - } else { | ||
68 | - orderRepository = value | 79 | + }) |
80 | + if err != nil { | ||
81 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
69 | } | 82 | } |
70 | - if order, err := orderRepository.Save(newOrder); err != nil { | ||
71 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 83 | + order, err := createOrderService.Create(newOrder) |
84 | + if err != nil { | ||
85 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | } else { | 86 | } else { |
73 | if err := transactionContext.CommitTransaction(); err != nil { | 87 | if err := transactionContext.CommitTransaction(); err != nil { |
74 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 88 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -188,15 +188,9 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | @@ -188,15 +188,9 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) | ||
188 | if remarks, ok := data["remarks"]; ok { | 188 | if remarks, ok := data["remarks"]; ok { |
189 | order.Remarks = remarks.(string) | 189 | order.Remarks = remarks.(string) |
190 | } | 190 | } |
191 | - if createAt, ok := data["createAt"]; ok { | ||
192 | - order.CreateAt = createAt.(time.Time) | ||
193 | - } | ||
194 | - if updateAt, ok := data["updateAt"]; ok { | ||
195 | - order.UpdateAt = updateAt.(time.Time) | ||
196 | - } | ||
197 | - if deleteAt, ok := data["deleteAt"]; ok { | ||
198 | - order.DeleteAt = deleteAt.(time.Time) | ||
199 | - } | 191 | + order.UpdateAt = time.Now() |
192 | + | ||
193 | + order.ComputeDividend() | ||
200 | return nil | 194 | return nil |
201 | } | 195 | } |
202 | 196 | ||
@@ -227,6 +221,11 @@ func (status *UnShippedStatus) Receive(order *Order) error { | @@ -227,6 +221,11 @@ func (status *UnShippedStatus) Receive(order *Order) error { | ||
227 | return fmt.Errorf("待发货订单不能收货") | 221 | return fmt.Errorf("待发货订单不能收货") |
228 | } | 222 | } |
229 | 223 | ||
224 | +// 待收货订单不能关闭 | ||
225 | +func (status *UnShippedStatus) Close(order *Order) error { | ||
226 | + return fmt.Errorf("待收货订单不能关闭") | ||
227 | +} | ||
228 | + | ||
230 | // 待收货状态 | 229 | // 待收货状态 |
231 | type TransitStatus struct{} | 230 | type TransitStatus struct{} |
232 | 231 | ||
@@ -510,3 +509,70 @@ func (order *Order) Cancel() error { | @@ -510,3 +509,70 @@ func (order *Order) Cancel() error { | ||
510 | func (order *Order) Close() error { | 509 | func (order *Order) Close() error { |
511 | return order.CurrentStatus.Close(order) | 510 | return order.CurrentStatus.Close(order) |
512 | } | 511 | } |
512 | + | ||
513 | +func (order *Order) RefreshOrderDetail() { | ||
514 | + | ||
515 | +} | ||
516 | +func (order *Order) ComputeDividend() { | ||
517 | + order.computeGoodsDividend() | ||
518 | + order.computeOrderDividend() | ||
519 | +} | ||
520 | +func (order *Order) computeOrderDividend() { | ||
521 | + var totalPlanBonus float64 | ||
522 | + // 调整后分红 | ||
523 | + var totalUseBonus float64 | ||
524 | + // 已收分红 | ||
525 | + var totalBonusHas float64 | ||
526 | + // 未收分红 | ||
527 | + var totalBonusNot float64 | ||
528 | + // 分红支出 | ||
529 | + var totalBonusExpense float64 | ||
530 | + for _, v := range order.OrderGoods { | ||
531 | + totalPlanBonus += v.GoodDividend.PlanBonus | ||
532 | + totalUseBonus += v.GoodDividend.UseBonus | ||
533 | + totalBonusHas += v.GoodDividend.BonusHas | ||
534 | + totalBonusNot += v.GoodDividend.BonusNot | ||
535 | + totalBonusExpense += v.GoodDividend.BonusExpense | ||
536 | + } | ||
537 | + order.OrderDividend.PlanBonus = totalPlanBonus | ||
538 | + order.OrderDividend.UseBonus = totalUseBonus | ||
539 | + order.OrderDividend.BonusHas = totalBonusHas | ||
540 | + order.OrderDividend.BonusNot = totalBonusNot | ||
541 | + order.OrderDividend.BonusExpense = totalBonusExpense | ||
542 | +} | ||
543 | +func (order *Order) computeGoodsDividend() { | ||
544 | + for i := range order.OrderGoods { | ||
545 | + good := order.OrderGoods[i] | ||
546 | + bonus := good.GoodTotalPrice * float64(good.GoodNum) * (order.OrderDividend.PartnerBonusPercent / 100) | ||
547 | + if good.GoodDividend == nil { | ||
548 | + good.GoodDividend = &Dividend{ | ||
549 | + PlanBonus: bonus, | ||
550 | + UseBonus: -1, | ||
551 | + BonusHas: 0, | ||
552 | + BonusNot: bonus, | ||
553 | + BonusExpense: 0, | ||
554 | + BonusStatus: Dividend_Unpaid, | ||
555 | + } | ||
556 | + } else { | ||
557 | + /* 计算预计分红、调整后分红 */ | ||
558 | + if bonus != good.GoodDividend.PlanBonus { | ||
559 | + if order.OrderStatus == ORDER_STATUS_UNSHIPPED { | ||
560 | + good.GoodDividend.PlanBonus = bonus | ||
561 | + good.GoodDividend.BonusNot = bonus | ||
562 | + } else { | ||
563 | + expense := good.GoodDividend.PlanBonus - bonus | ||
564 | + if expense <= 0 { | ||
565 | + expense = 0 | ||
566 | + } | ||
567 | + good.GoodDividend.UseBonus = bonus | ||
568 | + good.GoodDividend.BonusNot = bonus | ||
569 | + good.GoodDividend.BonusExpense = expense | ||
570 | + } | ||
571 | + } | ||
572 | + /*计算未支付分红*/ | ||
573 | + if good.GoodDividend.BonusHas > 0 { | ||
574 | + good.GoodDividend.BonusNot = good.GoodDividend.PlanBonus - good.GoodDividend.BonusHas | ||
575 | + } | ||
576 | + } | ||
577 | + } | ||
578 | +} |
pkg/domain/service/create_order.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +type CreateOrderService interface { | ||
9 | + coreDomain.DomainEventPublisher | ||
10 | + Create(newOrder *domain.Order) (*domain.Order, error) | ||
11 | +} |
@@ -141,10 +141,10 @@ func CheckPartnerUserType(dm *User) (*User, error) { | @@ -141,10 +141,10 @@ func CheckPartnerUserType(dm *User) (*User, error) { | ||
141 | if dm.PartnerInfo.PartnerName == "" { | 141 | if dm.PartnerInfo.PartnerName == "" { |
142 | return nil, fmt.Errorf("合伙人姓名不能为空") | 142 | return nil, fmt.Errorf("合伙人姓名不能为空") |
143 | } | 143 | } |
144 | - if len(dm.PartnerInfo.PartnerCategorys) == 0 { | 144 | + if len(dm.PartnerInfo.PartnerCategories) == 0 { |
145 | return nil, fmt.Errorf("合伙人类别不能为空") | 145 | return nil, fmt.Errorf("合伙人类别不能为空") |
146 | } | 146 | } |
147 | - if len(dm.PartnerInfo.Salesmans) == 0 { | 147 | + if len(dm.PartnerInfo.Salesmen) == 0 { |
148 | return nil, fmt.Errorf("合伙人查看合伙人账号不能为空") | 148 | return nil, fmt.Errorf("合伙人查看合伙人账号不能为空") |
149 | } | 149 | } |
150 | return dm, nil | 150 | return dm, nil |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository" | ||
10 | +) | ||
11 | + | ||
12 | +type CreateOrderService struct { | ||
13 | + coreDomain.BaseEventPublisher | ||
14 | + transactionContext *pgTransaction.TransactionContext | ||
15 | +} | ||
16 | + | ||
17 | +func (service *CreateOrderService) Create(newOrder *domain.Order) (*domain.Order, error) { | ||
18 | + var orderRepository domain.OrderRepository | ||
19 | + if value, err := repository.NewOrderRepository(service.transactionContext); err != nil { | ||
20 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
21 | + } else { | ||
22 | + orderRepository = value | ||
23 | + } | ||
24 | + if err := newOrder.Update(nil); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if order, err := orderRepository.Save(newOrder); err != nil { | ||
28 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
29 | + } else { | ||
30 | + return order, nil | ||
31 | + } | ||
32 | + return nil, nil | ||
33 | +} | ||
34 | + | ||
35 | +func NewCreateOrderService(transactionContext *pgTransaction.TransactionContext) (*CreateOrderService, error) { | ||
36 | + if transactionContext == nil { | ||
37 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
38 | + } else { | ||
39 | + return &CreateOrderService{ | ||
40 | + transactionContext: transactionContext, | ||
41 | + }, nil | ||
42 | + } | ||
43 | +} |
@@ -6,7 +6,7 @@ import ( | @@ -6,7 +6,7 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type Order struct { | 8 | type Order struct { |
9 | - tableName string `pg:"orders,alias:order"` | 9 | + tableName string `pg:"orders,alias:orders"` |
10 | // 订单id | 10 | // 订单id |
11 | OrderId int64 `pg:",pk"` | 11 | OrderId int64 `pg:",pk"` |
12 | // 买家信息 | 12 | // 买家信息 |
@@ -6,6 +6,15 @@ import ( | @@ -6,6 +6,15 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) { | 8 | func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain.Order, error) { |
9 | + var currentStatus domain.OrderStatus | ||
10 | + switch orderModel.OrderStatus { | ||
11 | + case domain.ORDER_STATUS_UNSHIPPED: | ||
12 | + currentStatus = &domain.UnShippedStatus{} | ||
13 | + case domain.ORDER_STATUS_SHIPPING: | ||
14 | + currentStatus = &domain.TransitStatus{} | ||
15 | + default: | ||
16 | + currentStatus = &domain.UnShippedStatus{} | ||
17 | + } | ||
9 | return &domain.Order{ | 18 | return &domain.Order{ |
10 | OrderId: orderModel.OrderId, | 19 | OrderId: orderModel.OrderId, |
11 | Buyer: orderModel.Buyer, | 20 | Buyer: orderModel.Buyer, |
@@ -27,5 +36,6 @@ func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain. | @@ -27,5 +36,6 @@ func TransformToOrderDomainModelFromPgModels(orderModel *models.Order) (*domain. | ||
27 | CreateAt: orderModel.CreateAt, | 36 | CreateAt: orderModel.CreateAt, |
28 | UpdateAt: orderModel.UpdateAt, | 37 | UpdateAt: orderModel.UpdateAt, |
29 | DeleteAt: orderModel.DeleteAt, | 38 | DeleteAt: orderModel.DeleteAt, |
39 | + CurrentStatus: currentStatus, | ||
30 | }, nil | 40 | }, nil |
31 | } | 41 | } |
@@ -72,7 +72,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | @@ -72,7 +72,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | ||
72 | &order.OrderDetail, | 72 | &order.OrderDetail, |
73 | &order.OrderDividend, | 73 | &order.OrderDividend, |
74 | &order.OrderDividendStatus, | 74 | &order.OrderDividendStatus, |
75 | - pg.Array(&order.OrderGoods), | 75 | + &order.OrderGoods, |
76 | &order.OrderSource, | 76 | &order.OrderSource, |
77 | &order.OrderType, | 77 | &order.OrderType, |
78 | &order.OrderStatus, | 78 | &order.OrderStatus, |
@@ -94,7 +94,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | @@ -94,7 +94,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | ||
94 | order.OrderDetail, | 94 | order.OrderDetail, |
95 | order.OrderDividend, | 95 | order.OrderDividend, |
96 | order.OrderDividendStatus, | 96 | order.OrderDividendStatus, |
97 | - pg.Array(order.OrderGoods), | 97 | + order.OrderGoods, |
98 | order.OrderSource, | 98 | order.OrderSource, |
99 | order.OrderType, | 99 | order.OrderType, |
100 | order.OrderStatus, | 100 | order.OrderStatus, |
@@ -120,7 +120,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | @@ -120,7 +120,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | ||
120 | &order.OrderDetail, | 120 | &order.OrderDetail, |
121 | &order.OrderDividend, | 121 | &order.OrderDividend, |
122 | &order.OrderDividendStatus, | 122 | &order.OrderDividendStatus, |
123 | - pg.Array(&order.OrderGoods), | 123 | + &order.OrderGoods, |
124 | &order.OrderSource, | 124 | &order.OrderSource, |
125 | &order.OrderType, | 125 | &order.OrderType, |
126 | &order.OrderStatus, | 126 | &order.OrderStatus, |
@@ -132,7 +132,6 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | @@ -132,7 +132,6 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | ||
132 | &order.DeleteAt, | 132 | &order.DeleteAt, |
133 | ), | 133 | ), |
134 | fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | 134 | fmt.Sprintf("UPDATE orders SET %s WHERE order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), |
135 | - order.OrderId, | ||
136 | order.Buyer, | 135 | order.Buyer, |
137 | order.CompanyId, | 136 | order.CompanyId, |
138 | order.PartnerId, | 137 | order.PartnerId, |
@@ -142,7 +141,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | @@ -142,7 +141,7 @@ func (repository *OrderRepository) Save(order *domain.Order) (*domain.Order, err | ||
142 | order.OrderDetail, | 141 | order.OrderDetail, |
143 | order.OrderDividend, | 142 | order.OrderDividend, |
144 | order.OrderDividendStatus, | 143 | order.OrderDividendStatus, |
145 | - pg.Array(order.OrderGoods), | 144 | + order.OrderGoods, |
146 | order.OrderSource, | 145 | order.OrderSource, |
147 | order.OrderType, | 146 | order.OrderType, |
148 | order.OrderStatus, | 147 | order.OrderStatus, |
@@ -172,7 +171,7 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) | @@ -172,7 +171,7 @@ func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) | ||
172 | tx := repository.transactionContext.PgTx | 171 | tx := repository.transactionContext.PgTx |
173 | orderModel := new(models.Order) | 172 | orderModel := new(models.Order) |
174 | query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions) | 173 | query := sqlbuilder.BuildQuery(tx.Model(orderModel), queryOptions) |
175 | - query.SetWhereByQueryOption("order.order_id = ?", "orderId") | 174 | + query.SetWhereByQueryOption("orders.order_id = ?", "orderId") |
176 | if err := query.First(); err != nil { | 175 | if err := query.First(); err != nil { |
177 | if err.Error() == "pg: no rows in result set" { | 176 | if err.Error() == "pg: no rows in result set" { |
178 | return nil, fmt.Errorf("没有此资源") | 177 | return nil, fmt.Errorf("没有此资源") |
1 | package order | 1 | package order |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
4 | "net/http" | 5 | "net/http" |
5 | 6 | ||
6 | "github.com/gavv/httpexpect" | 7 | "github.com/gavv/httpexpect" |
7 | . "github.com/onsi/ginkgo" | 8 | . "github.com/onsi/ginkgo" |
8 | . "github.com/onsi/gomega" | 9 | . "github.com/onsi/gomega" |
9 | - pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | ||
10 | ) | 10 | ) |
11 | 11 | ||
12 | -var _ = FDescribe("创建订单增删改查", func() { | 12 | +var _ = Describe("创建订单增删改查", func() { |
13 | Describe("提交数据创建订单增删改查", func() { | 13 | Describe("提交数据创建订单增删改查", func() { |
14 | Context("提交正确的新订单实体数据", func() { | 14 | Context("提交正确的新订单实体数据", func() { |
15 | It("返回订单实体数据", func() { | 15 | It("返回订单实体数据", func() { |
16 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 16 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
17 | + orderGoods := []map[string]interface{}{ | ||
18 | + {"goodNum": 10, "goodName": "banana", "goodTotalPrice": 3.5, "remarks": "单位:斤"}, | ||
19 | + {"goodNum": 20, "goodName": "apple", "goodTotalPrice": 5.5, "remarks": "单位:斤"}, | ||
20 | + } | ||
17 | body := map[string]interface{}{ | 21 | body := map[string]interface{}{ |
18 | - "orderNo": "string", | ||
19 | - "companyId": 1, | ||
20 | - "buyerName": "string", | ||
21 | - "contactInfo": "string", | ||
22 | - "shippingAddress": "string", | ||
23 | - "orderNum": 10, | ||
24 | - "totalPrice": 10, | ||
25 | - "partnerId": "1213", | 22 | + "orderNo": "string", |
23 | + "companyId": 1, | ||
24 | + "buyerName": "string", | ||
25 | + "contactInfo": "string", | ||
26 | + "shippingAddress": "string", | ||
27 | + "orderNum": 10, | ||
28 | + "totalPrice": 10, | ||
29 | + "partnerId": "1213", | ||
30 | + "partnerBonusPercent": 15, | ||
31 | + "orderGoods": orderGoods, | ||
26 | } | 32 | } |
27 | httpExpect.POST("/orders/"). | 33 | httpExpect.POST("/orders/"). |
28 | WithJSON(body). | 34 | WithJSON(body). |
@@ -10,27 +10,21 @@ import ( | @@ -10,27 +10,21 @@ import ( | ||
10 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" | 10 | pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg" |
11 | ) | 11 | ) |
12 | 12 | ||
13 | -var _ = FDescribe("返回订单增删改查", func() { | 13 | +var _ = Describe("返回订单增删改查", func() { |
14 | var orderId int64 | 14 | var orderId int64 |
15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
16 | - // 新增合伙人测试数据 | ||
17 | - _, err1 := pG.DB.QueryOne( | ||
18 | - pg.Scan(), | ||
19 | - "", | ||
20 | - "") | ||
21 | - Expect(err1).NotTo(HaveOccurred()) | ||
22 | // 新增订单测试数据 | 16 | // 新增订单测试数据 |
23 | _, err2 := pG.DB.QueryOne( | 17 | _, err2 := pG.DB.QueryOne( |
24 | pg.Scan(&orderId), | 18 | pg.Scan(&orderId), |
25 | - "INSERT INTO orders ( buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
26 | - "testBuyer", 1, "testPartnerId", "testDeliveryCode", false, "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | 19 | + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id", |
20 | + 1) | ||
27 | Expect(err2).NotTo(HaveOccurred()) | 21 | Expect(err2).NotTo(HaveOccurred()) |
28 | }) | 22 | }) |
29 | Describe("根据orderId参数返回订单实体", func() { | 23 | Describe("根据orderId参数返回订单实体", func() { |
30 | Context("传入有效的orderId", func() { | 24 | Context("传入有效的orderId", func() { |
31 | It("返回订单实体数据", func() { | 25 | It("返回订单实体数据", func() { |
32 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
33 | - httpExpect.GET("/orders/{orderId}"). | 27 | + httpExpect.GET("/orders/1"). |
34 | Expect(). | 28 | Expect(). |
35 | Status(http.StatusOK). | 29 | Status(http.StatusOK). |
36 | JSON(). | 30 | JSON(). |
@@ -13,19 +13,20 @@ import ( | @@ -13,19 +13,20 @@ import ( | ||
13 | var _ = Describe("返回订单增删改查列表", func() { | 13 | var _ = Describe("返回订单增删改查列表", func() { |
14 | var orderId int64 | 14 | var orderId int64 |
15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
16 | - _, err := pG.DB.QueryOne( | 16 | + // 新增订单测试数据 |
17 | + _, err2 := pG.DB.QueryOne( | ||
17 | pg.Scan(&orderId), | 18 | pg.Scan(&orderId), |
18 | - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | - Expect(err).NotTo(HaveOccurred()) | 19 | + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id", |
20 | + 1) | ||
21 | + Expect(err2).NotTo(HaveOccurred()) | ||
21 | }) | 22 | }) |
22 | Describe("根据参数返回订单实体列表", func() { | 23 | Describe("根据参数返回订单实体列表", func() { |
23 | Context("传入有效的参数", func() { | 24 | Context("传入有效的参数", func() { |
24 | It("返回订单实体数据列表", func() { | 25 | It("返回订单实体数据列表", func() { |
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | httpExpect.GET("/orders/"). | 27 | httpExpect.GET("/orders/"). |
27 | - WithQuery("offset", "int"). | ||
28 | - WithQuery("limit", "int"). | 28 | + WithQuery("offset", 0). |
29 | + WithQuery("limit", 10). | ||
29 | Expect(). | 30 | Expect(). |
30 | Status(http.StatusOK). | 31 | Status(http.StatusOK). |
31 | JSON(). | 32 | JSON(). |
@@ -13,24 +13,24 @@ import ( | @@ -13,24 +13,24 @@ import ( | ||
13 | var _ = Describe("移除订单增删改查", func() { | 13 | var _ = Describe("移除订单增删改查", func() { |
14 | var orderId int64 | 14 | var orderId int64 |
15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
16 | - _, err := pG.DB.QueryOne( | 16 | + // 新增订单测试数据 |
17 | + _, err2 := pG.DB.QueryOne( | ||
17 | pg.Scan(&orderId), | 18 | pg.Scan(&orderId), |
18 | - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | - Expect(err).NotTo(HaveOccurred()) | 19 | + "INSERT INTO orders (order_id) VALUES (?) RETURNING order_id", |
20 | + 1) | ||
21 | + Expect(err2).NotTo(HaveOccurred()) | ||
21 | }) | 22 | }) |
22 | Describe("根据参数移除订单增删改查", func() { | 23 | Describe("根据参数移除订单增删改查", func() { |
23 | Context("传入有效的orderId", func() { | 24 | Context("传入有效的orderId", func() { |
24 | It("返回被移除订单实体的数据", func() { | 25 | It("返回被移除订单实体的数据", func() { |
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | - httpExpect.DELETE("/orders/{orderId}"). | 27 | + httpExpect.DELETE("/orders/1"). |
27 | Expect(). | 28 | Expect(). |
28 | Status(http.StatusOK). | 29 | Status(http.StatusOK). |
29 | JSON(). | 30 | JSON(). |
30 | Object(). | 31 | Object(). |
31 | ContainsKey("code").ValueEqual("code", 0). | 32 | ContainsKey("code").ValueEqual("code", 0). |
32 | - ContainsKey("msg").ValueEqual("msg", "ok"). | ||
33 | - ContainsKey("data").Value("data").Object() | 33 | + ContainsKey("msg").ValueEqual("msg", "ok") |
34 | }) | 34 | }) |
35 | }) | 35 | }) |
36 | }) | 36 | }) |
@@ -13,18 +13,21 @@ import ( | @@ -13,18 +13,21 @@ import ( | ||
13 | var _ = Describe("更新订单增删改查", func() { | 13 | var _ = Describe("更新订单增删改查", func() { |
14 | var orderId int64 | 14 | var orderId int64 |
15 | BeforeEach(func() { | 15 | BeforeEach(func() { |
16 | - _, err := pG.DB.QueryOne( | 16 | + // 新增订单测试数据 |
17 | + _, err2 := pG.DB.QueryOne( | ||
17 | pg.Scan(&orderId), | 18 | pg.Scan(&orderId), |
18 | - "INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id", | ||
19 | - "testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt") | ||
20 | - Expect(err).NotTo(HaveOccurred()) | 19 | + "INSERT INTO orders (order_id,company_id,partner_id,buyer,order_dividend,order_detail) VALUES (?,?,?,?,?,?) RETURNING order_id", |
20 | + 1, 1, 1, "{}", "{}", "{}") | ||
21 | + Expect(err2).NotTo(HaveOccurred()) | ||
21 | }) | 22 | }) |
22 | Describe("提交数据更新订单增删改查", func() { | 23 | Describe("提交数据更新订单增删改查", func() { |
23 | Context("提交正确的订单实体数据", func() { | 24 | Context("提交正确的订单实体数据", func() { |
24 | It("返回更新后的订单实体数据", func() { | 25 | It("返回更新后的订单实体数据", func() { |
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 26 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | - body := map[string]interface{}{} | ||
27 | - httpExpect.PUT("/orders/{orderId}"). | 27 | + body := map[string]interface{}{ |
28 | + "shippingAddress": "fuzhou", | ||
29 | + } | ||
30 | + httpExpect.PUT("/orders/1"). | ||
28 | WithJSON(body). | 31 | WithJSON(body). |
29 | Expect(). | 32 | Expect(). |
30 | Status(http.StatusOK). | 33 | Status(http.StatusOK). |
-
请 注册 或 登录 后发表评论