...
|
...
|
@@ -46,6 +46,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder |
|
|
Limit: listOrderQuery.Limit,
|
|
|
OrderType: listOrderQuery.OrderType,
|
|
|
DeliveryCode: listOrderQuery.DeliveryCode,
|
|
|
CompanyId: listOrderQuery.CompanyId,
|
|
|
}
|
|
|
orders, cnt, err = orderRepository.Find(query)
|
|
|
if err != nil {
|
...
|
...
|
@@ -79,7 +80,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
}
|
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
order *domain.OrderBase
|
|
|
)
|
...
|
...
|
@@ -89,14 +90,12 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
orderBaseRepository = value
|
|
|
}
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -107,7 +106,8 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: getOrderQuery.OrderId,
|
|
|
OrderId: getOrderQuery.OrderId,
|
|
|
CompanyId: getOrderQuery.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
|
...
|
...
|
@@ -117,13 +117,17 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
goods []domain.OrderGood
|
|
|
)
|
|
|
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerId})
|
|
|
partnerData, err = partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: order.PartnerId,
|
|
|
CompanyId: getOrderQuery.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
|
|
|
}
|
|
|
order.PartnerInfo = partnerData.Partner
|
|
|
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: order.Id,
|
|
|
OrderId: order.Id,
|
|
|
CompanyId: getOrderQuery.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单中的商品列表失败:%s", err))
|
...
|
...
|
@@ -188,7 +192,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
// }
|
|
|
//检查delivery_code是否重复
|
|
|
if len(cmd.DeliveryCode) > 0 {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode); err != nil {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
...
|
...
|
@@ -206,6 +210,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
PartnerId: cmd.PartnerId,
|
|
|
PartnerInfo: partnerData.Partner,
|
|
|
SalesmanBonusPercent: cmd.SalesmanBonusPercent,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
}
|
|
|
var orderGoods []domain.OrderGood
|
|
|
for _, good := range cmd.Goods {
|
...
|
...
|
@@ -216,6 +221,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
m.Price = good.Price
|
|
|
m.PartnerBonusPercent = good.PartnerBonusPercent
|
|
|
m.Remark = good.Remark
|
|
|
m.CompanyId = cmd.CompanyId
|
|
|
err = m.Compute()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
|
...
|
...
|
@@ -251,7 +257,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
}
|
|
|
|
|
|
//DeleteOrder 删除订单
|
|
|
func (service OrderInfoService) DeleteOrder(orderId int64) error {
|
|
|
func (service OrderInfoService) DeleteOrder(orderId int64, companyId int64) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
...
|
...
|
@@ -276,11 +282,11 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error { |
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderBaseRepository.Remove(orderId)
|
|
|
err = orderBaseRepository.Remove(orderId, companyId)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单数据失败:%s", err))
|
|
|
}
|
|
|
err = orderGoodRepository.Remove(orderId)
|
|
|
err = orderGoodRepository.Remove(orderId, companyId)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中商品数据失败:%s", err))
|
|
|
}
|
...
|
...
|
@@ -312,7 +318,9 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var partnerData *domain.PartnerInfo
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId})
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: cmd.PartnerId, CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
|
|
|
}
|
...
|
...
|
@@ -337,7 +345,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
OrderId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
...
|
...
|
@@ -359,7 +368,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
// }
|
|
|
//检查delivery_code是否重复
|
|
|
if len(cmd.DeliveryCode) > 0 {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.Id); err != nil {
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
...
|
...
|
@@ -367,7 +376,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
OrderId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
|
...
|
...
|
@@ -380,6 +390,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
m.Price = good.Price
|
|
|
m.PartnerBonusPercent = good.PartnerBonusPercent
|
|
|
m.Remark = good.Remark
|
|
|
m.CompanyId = cmd.CompanyId
|
|
|
err = m.Compute()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
|
...
|
...
|
@@ -414,7 +425,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
oldOrderData.Goods = newOrderGoods
|
|
|
//删不需要的订单总不需要的商品
|
|
|
delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
|
|
|
err = orderGoodRepository.Remove(oldOrderData.Id, delGoods...)
|
|
|
err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
|
|
|
}
|
...
|
...
|
@@ -474,7 +485,8 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error |
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.OrderId,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
OrderId: cmd.OrderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
...
|
...
|
@@ -495,7 +507,8 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error |
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.OrderId,
|
|
|
OrderId: cmd.OrderId,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
|
...
|
...
|
@@ -567,7 +580,8 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) |
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.OrderId,
|
|
|
OrderId: cmd.OrderId,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
...
|
...
|
@@ -617,7 +631,8 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err |
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
OrderId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
...
|
...
|
|