...
|
...
|
@@ -608,6 +608,8 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 分红订单仓储初始化
|
|
|
var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -616,23 +618,67 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD |
|
|
} else {
|
|
|
dividendsOrderRepository = value
|
|
|
}
|
|
|
|
|
|
// 订单时间转换
|
|
|
orderTimeInt, err := strconv.ParseInt(updateDividendsOrderCommand.OrderTime, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
|
|
|
}
|
|
|
orderTime := utils.TransformTimestampToTime(orderTimeInt)
|
|
|
|
|
|
// 获取分红订单
|
|
|
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 新增订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsOrderAmount float64
|
|
|
for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
|
|
|
// 产品ID类型转换
|
|
|
orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
|
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
}
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: orderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodName: orderGood.OrderGoodName,
|
|
|
OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
|
|
DividendsOrderNumber: dividendsOrder.DividendsOrderNumber,
|
|
|
DividendsReturnedOrderNumber: "",
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderGoodExpense: orderGood.OrderGoodExpense,
|
|
|
OrgId: updateDividendsOrderCommand.OrgId,
|
|
|
CompanyId: updateDividendsOrderCommand.CompanyId,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Now(),
|
|
|
})
|
|
|
// 计算分红订单金额
|
|
|
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
|
|
|
}
|
|
|
|
|
|
if dividendsOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
|
|
|
}
|
|
|
if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsOrder, err := dividendsOrderRepository.Save(dividendsOrder); err != nil {
|
|
|
|
|
|
dividendsOrder.OrderTime = orderTime
|
|
|
dividendsOrder.DividendsOrderAmount = dividendsOrderAmount
|
|
|
dividendsOrder.Goods = orderGoods
|
|
|
|
|
|
// 保存订单更新
|
|
|
if dividendsOrderSaved, err := dividendsOrderRepository.Save(dividendsOrder); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsOrder, nil
|
|
|
return dividendsOrderSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|