...
|
...
|
@@ -20,7 +20,7 @@ func NewOrderInfoService(option map[string]interface{}) *OrderInfoService { |
|
|
}
|
|
|
|
|
|
// PageListOrderBase 获取订单列表
|
|
|
func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderQuery) ([]domain.OrderBase, int, error) {
|
|
|
func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderBaseQuery) ([]domain.OrderBase, int, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -37,7 +37,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder |
|
|
} else {
|
|
|
orderRepository = value
|
|
|
}
|
|
|
query := domain.OrderFindQuery{
|
|
|
query := domain.OrderBaseFindQuery{
|
|
|
PartnerId: listOrderQuery.PartnerId,
|
|
|
OrderCode: listOrderQuery.OrderCode,
|
|
|
Offset: listOrderQuery.Offset,
|
...
|
...
|
@@ -103,11 +103,11 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
order, err = orderBaseRepository.FindOne(domain.OrderFindOneQuery{
|
|
|
order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: getOrderQuery.OrderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
|
|
|
}
|
|
|
var (
|
|
|
partnerData *domain.PartnerInfo
|
...
|
...
|
@@ -115,7 +115,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
)
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
|
|
|
}
|
|
|
order.PartnerInfo = partnerData.Partner
|
|
|
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
...
|
...
|
@@ -193,7 +193,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
var orderGoods []domain.OrderGood
|
|
|
for _, good := range cmd.Goods {
|
|
|
m := domain.NewOrderGood()
|
|
|
m.OrderId = newOrder.Id
|
|
|
m.OrderId = 0
|
|
|
m.GoodName = good.GoodName
|
|
|
m.PlanGoodNumber = good.PlanGoodNumber
|
|
|
m.Price = good.Price
|
...
|
...
|
@@ -214,6 +214,9 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( |
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
|
|
|
}
|
|
|
for i := range newOrder.Goods {
|
|
|
newOrder.Goods[i].OrderId = newOrder.Id
|
|
|
}
|
|
|
err = orderGoodRepository.Save(orderGoods)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
|
...
|
...
|
@@ -266,3 +269,135 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error { |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//发货
|
|
|
|
|
|
//编辑订单
|
|
|
func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) (*domain.OrderBase, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// orderDao, _ := factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
// ok, err := orderDao.OrderCodeIsExist(command.OrderCode, 0)
|
|
|
// if err != nil {
|
|
|
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// if ok {
|
|
|
// return lib.ThrowError(lib.BUSINESS_ERROR, "订单编号已存在")
|
|
|
// }
|
|
|
var PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var partnerData *domain.PartnerInfo
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
|
|
|
}
|
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderData *domain.OrderBase
|
|
|
oldOrderGoods []domain.OrderGood
|
|
|
newOrderGoods []domain.OrderGood
|
|
|
delGoods []int64
|
|
|
)
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
|
|
|
}
|
|
|
for _, good := range cmd.Goods {
|
|
|
m := domain.NewOrderGood()
|
|
|
m.OrderId = oldOrderData.Id
|
|
|
m.GoodName = good.GoodName
|
|
|
m.PlanGoodNumber = good.PlanGoodNumber
|
|
|
m.Price = good.Price
|
|
|
m.PartnerBonusPercent = good.PartnerBonusPercent
|
|
|
m.Remark = good.Remark
|
|
|
err = m.Compute()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
|
|
|
}
|
|
|
newOrderGoods = append(newOrderGoods, m)
|
|
|
}
|
|
|
oldOrderData.OrderCode = cmd.OrderCode
|
|
|
oldOrderData.DeliveryCode = cmd.DeliveryCode
|
|
|
oldOrderData.Buyer.BuyerName = cmd.BuyerName
|
|
|
oldOrderData.RegionInfo.RegionName = cmd.OrderRegion
|
|
|
oldOrderData.PartnerId = cmd.PartnerId
|
|
|
oldOrderData.PartnerInfo = partnerData.Partner
|
|
|
oldOrderData.SalesmanBonusPercent = cmd.SalesmanBonusPercent
|
|
|
oldOrderData.Goods = newOrderGoods
|
|
|
err = oldOrderData.Compute()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
|
|
|
}
|
|
|
|
|
|
err = orderBaseRepository.Save(oldOrderData)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
|
|
|
}
|
|
|
err = orderGoodRepository.Save(newOrderGoods)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
|
|
|
}
|
|
|
oldOrderData.Goods = newOrderGoods
|
|
|
//删不需要的订单总不需要的商品
|
|
|
delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
|
|
|
err = orderGoodRepository.Remove(oldOrderData.Id, delGoods...)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return oldOrderData, nil
|
|
|
}
|
|
|
|
|
|
//新旧商品列表对比
|
|
|
func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood, oldGoods []domain.OrderGood) (goodIds []int64) {
|
|
|
for _, old := range oldGoods {
|
|
|
var hasIn bool
|
|
|
for _, new := range newGoods {
|
|
|
if old.Id == new.Id {
|
|
|
hasIn = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !hasIn {
|
|
|
goodIds = append(goodIds, old.Id)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|