...
|
...
|
@@ -11,6 +11,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -543,6 +544,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 分红退货单仓储初始化
|
|
|
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
|
|
|
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -551,6 +554,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
} else {
|
|
|
dividendsReturnedOrderRepository = value
|
|
|
}
|
|
|
|
|
|
// 退货单时间转换
|
|
|
dividendsReturnedDateInt, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.DividendsReturnedDate, 10, 64)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
|
|
|
}
|
|
|
dividendsReturnedDate := utils.TransformTimestampToTime(dividendsReturnedDateInt)
|
|
|
|
|
|
// 获取分红退货单
|
|
|
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -558,16 +570,51 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
if dividendsReturnedOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId)))
|
|
|
}
|
|
|
|
|
|
// 获取订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsReturnedOrderAmount float64
|
|
|
for _, orderGood := range updateDividendsReturnedOrderCommand.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: "",
|
|
|
DividendsReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
|
|
|
CooperationContractNumber: orderGood.CooperationContractNumber,
|
|
|
OrderGoodExpense: orderGood.OrderGoodExpense,
|
|
|
OrgId: updateDividendsReturnedOrderCommand.OrgId,
|
|
|
CompanyId: updateDividendsReturnedOrderCommand.CompanyId,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Now(),
|
|
|
})
|
|
|
// 计算分红退货单金额
|
|
|
dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
|
|
|
}
|
|
|
|
|
|
if err := dividendsReturnedOrder.Update(tool_funs.SimpleStructToMap(updateDividendsReturnedOrderCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsReturnedOrder, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil {
|
|
|
|
|
|
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate
|
|
|
dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderAmount
|
|
|
dividendsReturnedOrder.Goods = orderGoods
|
|
|
|
|
|
// 保存分红退货单更新
|
|
|
if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); 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 dividendsReturnedOrder, nil
|
|
|
return dividendsReturnedOrderSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|