作者 yangfu

add some order operate

@@ -2,42 +2,16 @@ package command @@ -2,42 +2,16 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "time"  
6 -  
7 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
8 ) 6 )
9 7
10 type CancelOrderCommand struct { 8 type CancelOrderCommand struct {
11 // 订单ID 9 // 订单ID
12 OrderId int64 `json:"orderId" valid:"Required"` 10 OrderId int64 `json:"orderId" valid:"Required"`
13 - // 订单编号  
14 - OrderNo string `json:"orderNo" valid:"Required"`  
15 - // 公司id  
16 - CompanyId int64 `json:"companyId" valid:"Required"`  
17 - // 是否是公司负责人  
18 - IsPrincipal bool `json:"isPrincipal" valid:"Required"`  
19 - // 统一用户id  
20 - Uid int64 `json:"uid" valid:"Required"`  
21 - // 用户账号  
22 - UserAccount string `json:"userAccount" valid:"Required"`  
23 - // 用户头像URL  
24 - UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`  
25 - // 用户名称  
26 - UserName string `json:"userName" valid:"Required"`  
27 - // 邮件地址  
28 - Email string `json:"email" valid:"Required"`  
29 - // 性别  
30 - Gender int `json:"gender" valid:"Required"`  
31 - // 入职时间  
32 - EntryTime time.Time `json:"entryTime" valid:"Required"`  
33 - // 分机  
34 - Extension string `json:"extension" valid:"Required"`  
35 - // 工作地  
36 - Workplace string `json:"workplace" valid:"Required"`  
37 - // 私人电话  
38 - PrivateNumber string `json:"privateNumber" valid:"Required"`  
39 - // 工号  
40 - JobNumber string `json:"jobNumber" valid:"Required"` 11 + // 货品Id
  12 + //GoodId int64 `json:"goodId"`
  13 + // 取消理由
  14 + Reason string `json:"reason"`
41 } 15 }
42 16
43 func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) { 17 func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) {
@@ -2,40 +2,14 @@ package command @@ -2,40 +2,14 @@ package command
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "time"  
6 -  
7 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
8 ) 6 )
9 7
10 type ReceiveGoodsCommand struct { 8 type ReceiveGoodsCommand struct {
11 // 订单号 9 // 订单号
12 - OrderNo string `json:"orderNo" valid:"Required"`  
13 - // 是否是公司负责人  
14 - IsPrincipal bool `json:"isPrincipal" valid:"Required"`  
15 - // 统一用户id  
16 - Uid int64 `json:"uid" valid:"Required"`  
17 - // 用户账号  
18 - UserAccount string `json:"userAccount" valid:"Required"`  
19 - // 用户头像URL  
20 - UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`  
21 - // 用户名称  
22 - UserName string `json:"userName" valid:"Required"`  
23 - // 邮件地址  
24 - Email string `json:"email" valid:"Required"`  
25 - // 性别  
26 - Gender int `json:"gender" valid:"Required"`  
27 - // 入职时间  
28 - EntryTime time.Time `json:"entryTime" valid:"Required"`  
29 - // 分机  
30 - Extension string `json:"extension" valid:"Required"`  
31 - // 工作地  
32 - Workplace string `json:"workplace" valid:"Required"`  
33 - // 私人电话  
34 - PrivateNumber string `json:"privateNumber" valid:"Required"`  
35 - // 工号  
36 - JobNumber string `json:"jobNumber" valid:"Required"`  
37 - // 公司id  
38 - CompanyId int64 `json:"companyId" valid:"Required"` 10 + OrderId int64 `json:"orderId" valid:"Required"`
  11 + // 商品列表
  12 + OrderGoods []int64 `json:"orderGoods" valid:"Required"`
39 } 13 }
40 14
41 func (receiveGoodsCommand *ReceiveGoodsCommand) Valid(validation *validation.Validation) { 15 func (receiveGoodsCommand *ReceiveGoodsCommand) Valid(validation *validation.Validation) {
@@ -9,9 +9,7 @@ type ReturnGoodsCommand struct { @@ -9,9 +9,7 @@ type ReturnGoodsCommand struct {
9 // 订单ID 9 // 订单ID
10 OrderId int64 `json:"orderId" valid:"Required"` 10 OrderId int64 `json:"orderId" valid:"Required"`
11 // 订单号 11 // 订单号
12 - OrderNo string `json:"orderNo" valid:"Required"`  
13 - // 统一用户id  
14 - Uid int64 `json:"uid" valid:"Required"` 12 + OrderGoods []int `json:"orderGoods" valid:"Required"`
15 } 13 }
16 14
17 func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) { 15 func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
@@ -200,10 +200,17 @@ func (orderService *OrderService) ReceiveGoods(receivingCommand *command.Receive @@ -200,10 +200,17 @@ func (orderService *OrderService) ReceiveGoods(receivingCommand *command.Receive
200 defer func() { 200 defer func() {
201 _ = transactionContext.RollbackTransaction() 201 _ = transactionContext.RollbackTransaction()
202 }() 202 }()
  203 + shippingService, err := factory.CreateReceivingService(map[string]interface{}{
  204 + "transactionContext": transactionContext,
  205 + })
  206 + if err != nil {
  207 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  208 + }
  209 + order, err := shippingService.Receiving(int64(receivingCommand.OrderId), receivingCommand.OrderGoods)
203 if err := transactionContext.CommitTransaction(); err != nil { 210 if err := transactionContext.CommitTransaction(); err != nil {
204 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 211 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
205 } 212 }
206 - return nil, nil 213 + return order, nil
207 } 214 }
208 215
209 // 移除订单增删改查 216 // 移除订单增删改查
@@ -261,10 +268,19 @@ func (orderService *OrderService) ReturnGoods(returnGoodsCommand *command.Return @@ -261,10 +268,19 @@ func (orderService *OrderService) ReturnGoods(returnGoodsCommand *command.Return
261 defer func() { 268 defer func() {
262 _ = transactionContext.RollbackTransaction() 269 _ = transactionContext.RollbackTransaction()
263 }() 270 }()
  271 +
  272 + returnGoodsService, err := factory.CreateReturnGoodsService(map[string]interface{}{
  273 + "transactionContext": transactionContext,
  274 + })
  275 + if err != nil {
  276 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  277 + }
  278 + order, err := returnGoodsService.Return(int64(returnGoodsCommand.OrderId))
  279 +
264 if err := transactionContext.CommitTransaction(); err != nil { 280 if err := transactionContext.CommitTransaction(); err != nil {
265 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 281 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
266 } 282 }
267 - return nil, nil 283 + return order, nil
268 } 284 }
269 285
270 // 订单发货服务 286 // 订单发货服务
@@ -282,10 +298,18 @@ func (orderService *OrderService) ShippingGoods(shippingGoodsCommand *command.Sh @@ -282,10 +298,18 @@ func (orderService *OrderService) ShippingGoods(shippingGoodsCommand *command.Sh
282 defer func() { 298 defer func() {
283 _ = transactionContext.RollbackTransaction() 299 _ = transactionContext.RollbackTransaction()
284 }() 300 }()
  301 +
  302 + shippingService, err := factory.CreateShippingService(map[string]interface{}{
  303 + "transactionContext": transactionContext,
  304 + })
  305 + if err != nil {
  306 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  307 + }
  308 + order, err := shippingService.Shipping(int64(shippingGoodsCommand.OrderId))
285 if err := transactionContext.CommitTransaction(); err != nil { 309 if err := transactionContext.CommitTransaction(); err != nil {
286 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 310 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
287 } 311 }
288 - return nil, nil 312 + return order, nil
289 } 313 }
290 314
291 // 更新订单增删改查 315 // 更新订单增删改查
@@ -7,5 +7,5 @@ import ( @@ -7,5 +7,5 @@ import (
7 7
8 type ReceivingGoodsService interface { 8 type ReceivingGoodsService interface {
9 coreDomain.DomainEventPublisher 9 coreDomain.DomainEventPublisher
10 - Receiving(orderId int64) (*domain.Order, error) 10 + Receiving(orderId int64, orderGoods []int64) (*domain.Order, error)
11 } 11 }
@@ -15,7 +15,7 @@ type ReceivingGoodsService struct { @@ -15,7 +15,7 @@ type ReceivingGoodsService struct {
15 transactionContext *pgTransaction.TransactionContext 15 transactionContext *pgTransaction.TransactionContext
16 } 16 }
17 17
18 -func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) { 18 +func (service *ReceivingGoodsService) Receiving(orderId int64, orderGoods []int64) (*domain.Order, error) {
19 var orderRepository domain.OrderRepository 19 var orderRepository domain.OrderRepository
20 if value, err := repository.NewOrderRepository(service.transactionContext); err != nil { 20 if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
21 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 21 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -68,3 +68,27 @@ func (controller *OrderController) Shipping() { @@ -68,3 +68,27 @@ func (controller *OrderController) Shipping() {
68 data, err := orderService.ShippingGoods(shippingCmd) 68 data, err := orderService.ShippingGoods(shippingCmd)
69 controller.Response(data, err) 69 controller.Response(data, err)
70 } 70 }
  71 +
  72 +func (controller *OrderController) ReceiveGoods() {
  73 + orderService := service.NewOrderService(nil)
  74 + createOrderCommand := &command.ReceiveGoodsCommand{}
  75 + _ = controller.Unmarshal(createOrderCommand)
  76 + data, err := orderService.ReceiveGoods(createOrderCommand)
  77 + controller.Response(data, err)
  78 +}
  79 +
  80 +func (controller *OrderController) CancelOrder() {
  81 + orderService := service.NewOrderService(nil)
  82 + createOrderCommand := &command.CancelOrderCommand{}
  83 + _ = controller.Unmarshal(createOrderCommand)
  84 + data, err := orderService.CancelOrder(createOrderCommand)
  85 + controller.Response(data, err)
  86 +}
  87 +
  88 +func (controller *OrderController) ReturnGoods() {
  89 + orderService := service.NewOrderService(nil)
  90 + createOrderCommand := &command.ReturnGoodsCommand{}
  91 + _ = controller.Unmarshal(createOrderCommand)
  92 + data, err := orderService.ReturnGoods(createOrderCommand)
  93 + controller.Response(data, err)
  94 +}
@@ -11,4 +11,8 @@ func init() { @@ -11,4 +11,8 @@ func init() {
11 web.Router("/orders/:orderId", &controllers.OrderController{}, "Get:GetOrder") 11 web.Router("/orders/:orderId", &controllers.OrderController{}, "Get:GetOrder")
12 web.Router("/orders/:orderId", &controllers.OrderController{}, "Delete:RemoveOrder") 12 web.Router("/orders/:orderId", &controllers.OrderController{}, "Delete:RemoveOrder")
13 web.Router("/orders/", &controllers.OrderController{}, "Get:ListOrder") 13 web.Router("/orders/", &controllers.OrderController{}, "Get:ListOrder")
  14 + web.Router("/orders/shipping", &controllers.OrderController{}, "Post:Shipping")
  15 + web.Router("/orders/receiveGoods", &controllers.OrderController{}, "Post:ReceiveGoods")
  16 + web.Router("/orders/returnGoods", &controllers.OrderController{}, "Post:ReturnGoods")
  17 + web.Router("/orders/cancel", &controllers.OrderController{}, "Post:CancelOrder")
14 } 18 }