作者 陈志颖

fix:退货单产品更新错误

... ... @@ -1271,18 +1271,26 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
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())
}
orderGoodFound := &domain.OrderGood{}
// 获取产品
orderGoodFound, err4 := orderGoodRepository.FindOne(map[string]interface{}{
"orderGoodId": orderGoodId,
})
if err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
if orderGood.OrderGoodId != "" {
orderGoodFetched, err4 := orderGoodRepository.FindOne(map[string]interface{}{
"orderGoodId": orderGoodId,
})
if err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
}
orderGoodFound = orderGoodFetched
} else {
orderGoodFound.OrderGoodDividendsStatus = int32(1)
}
// 退货产品金额计算
... ...
... ... @@ -53,7 +53,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsReturnedOrder.Identify() == nil {
if dividendsReturnedOrder.Identify() == nil { // 新增分红退货单
dividendsReturnedOrderId, err := repository.nextIdentify()
if err != nil {
return dividendsReturnedOrder, err
... ... @@ -137,7 +137,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
return nil, err
}
} else {
} else { // 编辑分红退货单
if _, err := tx.QueryOne(
pg.Scan(
&dividendsReturnedOrder.DividendsReturnedOrderId,
... ... @@ -200,8 +200,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
// 待更新分红退货单产品
var orderGoodsToUpdate []*domain.OrderGood
// 待添加分红退货单产品
var orderGoodsToAdd []*domain.OrderGood
for _, good := range dividendsReturnedOrder.Goods {
if good.OrderGoodId != 0 {
orderGoodsToUpdate = append(orderGoodsToUpdate, good)
... ... @@ -305,7 +307,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
}
}
if len(orderGoodModelsToDelete) > 0 {
if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil {
if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil {
return nil, err
}
}
... ...