作者 yangfu

合并分支 '6-order-domain-service' 到 'dev'

add  some order operate

Closes #6

查看合并请求 !16
... ... @@ -2,42 +2,16 @@ package command
import (
"fmt"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CancelOrderCommand struct {
// 订单ID
OrderId int64 `json:"orderId" valid:"Required"`
// 订单编号
OrderNo string `json:"orderNo" valid:"Required"`
// 公司id
CompanyId int64 `json:"companyId" valid:"Required"`
// 是否是公司负责人
IsPrincipal bool `json:"isPrincipal" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
// 用户账号
UserAccount string `json:"userAccount" valid:"Required"`
// 用户头像URL
UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`
// 用户名称
UserName string `json:"userName" valid:"Required"`
// 邮件地址
Email string `json:"email" valid:"Required"`
// 性别
Gender int `json:"gender" valid:"Required"`
// 入职时间
EntryTime time.Time `json:"entryTime" valid:"Required"`
// 分机
Extension string `json:"extension" valid:"Required"`
// 工作地
Workplace string `json:"workplace" valid:"Required"`
// 私人电话
PrivateNumber string `json:"privateNumber" valid:"Required"`
// 工号
JobNumber string `json:"jobNumber" valid:"Required"`
// 货品Id
//GoodId int64 `json:"goodId"`
// 取消理由
Reason string `json:"reason"`
}
func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -2,40 +2,14 @@ package command
import (
"fmt"
"time"
"github.com/beego/beego/v2/core/validation"
)
type ReceiveGoodsCommand struct {
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 是否是公司负责人
IsPrincipal bool `json:"isPrincipal" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
// 用户账号
UserAccount string `json:"userAccount" valid:"Required"`
// 用户头像URL
UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`
// 用户名称
UserName string `json:"userName" valid:"Required"`
// 邮件地址
Email string `json:"email" valid:"Required"`
// 性别
Gender int `json:"gender" valid:"Required"`
// 入职时间
EntryTime time.Time `json:"entryTime" valid:"Required"`
// 分机
Extension string `json:"extension" valid:"Required"`
// 工作地
Workplace string `json:"workplace" valid:"Required"`
// 私人电话
PrivateNumber string `json:"privateNumber" valid:"Required"`
// 工号
JobNumber string `json:"jobNumber" valid:"Required"`
// 公司id
CompanyId int64 `json:"companyId" valid:"Required"`
OrderId int64 `json:"orderId" valid:"Required"`
// 商品列表
OrderGoods []int64 `json:"orderGoods" valid:"Required"`
}
func (receiveGoodsCommand *ReceiveGoodsCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,9 +9,7 @@ type ReturnGoodsCommand struct {
// 订单ID
OrderId int64 `json:"orderId" valid:"Required"`
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
OrderGoods []int `json:"orderGoods" valid:"Required"`
}
func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -200,10 +200,17 @@ func (orderService *OrderService) ReceiveGoods(receivingCommand *command.Receive
defer func() {
_ = transactionContext.RollbackTransaction()
}()
shippingService, err := factory.CreateReceivingService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
order, err := shippingService.Receiving(int64(receivingCommand.OrderId), receivingCommand.OrderGoods)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return order, nil
}
// 移除订单增删改查
... ... @@ -261,10 +268,19 @@ func (orderService *OrderService) ReturnGoods(returnGoodsCommand *command.Return
defer func() {
_ = transactionContext.RollbackTransaction()
}()
returnGoodsService, err := factory.CreateReturnGoodsService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
order, err := returnGoodsService.Return(int64(returnGoodsCommand.OrderId))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return order, nil
}
// 订单发货服务
... ... @@ -282,10 +298,18 @@ func (orderService *OrderService) ShippingGoods(shippingGoodsCommand *command.Sh
defer func() {
_ = transactionContext.RollbackTransaction()
}()
shippingService, err := factory.CreateShippingService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
order, err := shippingService.Shipping(int64(shippingGoodsCommand.OrderId))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return order, nil
}
// 更新订单增删改查
... ...
... ... @@ -7,5 +7,5 @@ import (
type ReceivingGoodsService interface {
coreDomain.DomainEventPublisher
Receiving(orderId int64) (*domain.Order, error)
Receiving(orderId int64, orderGoods []int64) (*domain.Order, error)
}
... ...
... ... @@ -15,7 +15,7 @@ type ReceivingGoodsService struct {
transactionContext *pgTransaction.TransactionContext
}
func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) {
func (service *ReceivingGoodsService) Receiving(orderId int64, orderGoods []int64) (*domain.Order, error) {
var orderRepository domain.OrderRepository
if value, err := repository.NewOrderRepository(service.transactionContext); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -68,3 +68,27 @@ func (controller *OrderController) Shipping() {
data, err := orderService.ShippingGoods(shippingCmd)
controller.Response(data, err)
}
func (controller *OrderController) ReceiveGoods() {
orderService := service.NewOrderService(nil)
createOrderCommand := &command.ReceiveGoodsCommand{}
_ = controller.Unmarshal(createOrderCommand)
data, err := orderService.ReceiveGoods(createOrderCommand)
controller.Response(data, err)
}
func (controller *OrderController) CancelOrder() {
orderService := service.NewOrderService(nil)
createOrderCommand := &command.CancelOrderCommand{}
_ = controller.Unmarshal(createOrderCommand)
data, err := orderService.CancelOrder(createOrderCommand)
controller.Response(data, err)
}
func (controller *OrderController) ReturnGoods() {
orderService := service.NewOrderService(nil)
createOrderCommand := &command.ReturnGoodsCommand{}
_ = controller.Unmarshal(createOrderCommand)
data, err := orderService.ReturnGoods(createOrderCommand)
controller.Response(data, err)
}
... ...
... ... @@ -11,4 +11,8 @@ func init() {
web.Router("/orders/:orderId", &controllers.OrderController{}, "Get:GetOrder")
web.Router("/orders/:orderId", &controllers.OrderController{}, "Delete:RemoveOrder")
web.Router("/orders/", &controllers.OrderController{}, "Get:ListOrder")
web.Router("/orders/shipping", &controllers.OrderController{}, "Post:Shipping")
web.Router("/orders/receiveGoods", &controllers.OrderController{}, "Post:ReceiveGoods")
web.Router("/orders/returnGoods", &controllers.OrderController{}, "Post:ReturnGoods")
web.Router("/orders/cancel", &controllers.OrderController{}, "Post:CancelOrder")
}
... ...