作者 陈志颖

fix:修复订单产品更新问题

... ... @@ -243,6 +243,29 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
log.Logger.Info("待更新的分红订单产品", map[string]interface{}{
"orderGoodModelsToUpdate": orderGoodModelsToUpdate,
})
for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate {
for j, orderGood := range dividendsOrder.Goods {
if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
orderGoodModelsToUpdate[i] = &models.OrderGood{
OrderGoodId: dividendsOrder.Goods[j].OrderGoodId,
OrderGoodAmount: dividendsOrder.Goods[j].OrderGoodAmount,
OrderGoodName: dividendsOrder.Goods[j].OrderGoodName,
OrderGoodPrice: dividendsOrder.Goods[j].OrderGoodPrice,
OrderGoodQuantity: dividendsOrder.Goods[j].OrderGoodQuantity,
DividendsOrderNumber: dividendsOrder.Goods[j].DividendsOrderNumber,
DividendsReturnedOrderNumber: dividendsOrder.Goods[j].DividendsReturnedOrderNumber,
CooperationContractNumber: dividendsOrder.Goods[j].CooperationContractNumber,
OrgId: dividendsOrder.Goods[j].OrgId,
CompanyId: dividendsOrder.Goods[j].CompanyId,
OrderGoodExpense: dividendsOrder.Goods[j].OrderGoodExpense,
OrderGoodDividendsStatus: dividendsOrder.Goods[j].OrderGoodDividendsStatus,
CreatedAt: orderGoodModelsToUpdate[i].CreatedAt,
DeletedAt: orderGoodModelsToUpdate[i].DeletedAt,
UpdatedAt: time.Now(),
}
}
}
}
if len(orderGoodModelsToUpdate) > 0 {
if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
... ... @@ -246,6 +247,32 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
}
}
}
log.Logger.Info("待更新的分红退货单产品", map[string]interface{}{
"orderGoodModelsToUpdate": orderGoodModelsToUpdate,
})
for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate {
for j, orderGood := range dividendsReturnedOrder.Goods {
if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
orderGoodModelsToUpdate[i] = &models.OrderGood{
OrderGoodId: dividendsReturnedOrder.Goods[j].OrderGoodId,
OrderGoodAmount: dividendsReturnedOrder.Goods[j].OrderGoodAmount,
OrderGoodName: dividendsReturnedOrder.Goods[j].OrderGoodName,
OrderGoodPrice: dividendsReturnedOrder.Goods[j].OrderGoodPrice,
OrderGoodQuantity: dividendsReturnedOrder.Goods[j].OrderGoodQuantity,
DividendsOrderNumber: dividendsReturnedOrder.Goods[j].DividendsOrderNumber,
DividendsReturnedOrderNumber: dividendsReturnedOrder.Goods[j].DividendsReturnedOrderNumber,
CooperationContractNumber: dividendsReturnedOrder.Goods[j].CooperationContractNumber,
OrgId: dividendsReturnedOrder.Goods[j].OrgId,
CompanyId: dividendsReturnedOrder.Goods[j].CompanyId,
OrderGoodExpense: dividendsReturnedOrder.Goods[j].OrderGoodExpense,
OrderGoodDividendsStatus: dividendsReturnedOrder.Goods[j].OrderGoodDividendsStatus,
CreatedAt: orderGoodModelsToUpdate[i].CreatedAt,
DeletedAt: orderGoodModelsToUpdate[i].DeletedAt,
UpdatedAt: time.Now(),
}
}
}
}
if len(orderGoodModelsToUpdate) > 0 {
if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
... ...