...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -162,6 +163,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -173,6 +175,25 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//检查order_code是否重复
|
|
|
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
|
|
|
}
|
|
|
//检查delivery_code是否重复
|
|
|
if len(cmd.DeliveryCode) > 0 {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
|
|
}
|
|
|
}
|
|
|
newOrder := &domain.OrderBase{
|
|
|
OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
|
|
|
DeliveryCode: cmd.DeliveryCode,
|
...
|
...
|
@@ -302,6 +323,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
oldOrderGoods []domain.OrderGood
|
|
|
newOrderGoods []domain.OrderGood
|
|
|
delGoods []int64
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -324,6 +346,25 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
if oldOrderData.OrderType != cmd.OrderType {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("操作失败,待更新的订单的类型已变更"))
|
|
|
}
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//检查order_code是否重复
|
|
|
if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.Id); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
|
|
|
}
|
|
|
//检查delivery_code是否重复
|
|
|
if len(cmd.DeliveryCode) > 0 {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.Id); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
|
|
}
|
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.Id,
|
...
|
...
|
@@ -418,7 +459,9 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error |
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderData *domain.OrderBase
|
|
|
oldOrderGoods []domain.OrderGood
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -436,6 +479,20 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error |
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
|
|
}
|
|
|
if oldOrderData.OrderType != domain.OrderIntention {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
|
|
|
}
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//检查delivery_code是否重复
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.OrderId); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.OrderId,
|
...
|
...
|
|