作者 陈志颖

fix:退货单产品更新错误

@@ -1271,18 +1271,26 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide @@ -1271,18 +1271,26 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
1271 var orderGoods []*domain.OrderGood 1271 var orderGoods []*domain.OrderGood
1272 var dividendsReturnedOrderAmount float64 1272 var dividendsReturnedOrderAmount float64
1273 for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods { 1273 for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods {
  1274 +
1274 // 产品ID类型转换 1275 // 产品ID类型转换
1275 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64) 1276 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
1276 if err3 != nil { 1277 if err3 != nil {
1277 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) 1278 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
1278 } 1279 }
1279 1280
  1281 + orderGoodFound := &domain.OrderGood{}
  1282 +
1280 // 获取产品 1283 // 获取产品
1281 - orderGoodFound, err4 := orderGoodRepository.FindOne(map[string]interface{}{  
1282 - "orderGoodId": orderGoodId,  
1283 - })  
1284 - if err4 != nil {  
1285 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) 1284 + if orderGood.OrderGoodId != "" {
  1285 + orderGoodFetched, err4 := orderGoodRepository.FindOne(map[string]interface{}{
  1286 + "orderGoodId": orderGoodId,
  1287 + })
  1288 + if err4 != nil {
  1289 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
  1290 + }
  1291 + orderGoodFound = orderGoodFetched
  1292 + } else {
  1293 + orderGoodFound.OrderGoodDividendsStatus = int32(1)
1286 } 1294 }
1287 1295
1288 // 退货产品金额计算 1296 // 退货产品金额计算
@@ -53,7 +53,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -53,7 +53,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
53 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id") 53 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id")
54 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 54 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
55 tx := repository.transactionContext.PgTx 55 tx := repository.transactionContext.PgTx
56 - if dividendsReturnedOrder.Identify() == nil { 56 + if dividendsReturnedOrder.Identify() == nil { // 新增分红退货单
57 dividendsReturnedOrderId, err := repository.nextIdentify() 57 dividendsReturnedOrderId, err := repository.nextIdentify()
58 if err != nil { 58 if err != nil {
59 return dividendsReturnedOrder, err 59 return dividendsReturnedOrder, err
@@ -137,7 +137,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -137,7 +137,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
137 if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil { 137 if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
138 return nil, err 138 return nil, err
139 } 139 }
140 - } else { 140 + } else { // 编辑分红退货单
141 if _, err := tx.QueryOne( 141 if _, err := tx.QueryOne(
142 pg.Scan( 142 pg.Scan(
143 &dividendsReturnedOrder.DividendsReturnedOrderId, 143 &dividendsReturnedOrder.DividendsReturnedOrderId,
@@ -200,8 +200,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -200,8 +200,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
200 200
201 // 待更新分红退货单产品 201 // 待更新分红退货单产品
202 var orderGoodsToUpdate []*domain.OrderGood 202 var orderGoodsToUpdate []*domain.OrderGood
  203 +
203 // 待添加分红退货单产品 204 // 待添加分红退货单产品
204 var orderGoodsToAdd []*domain.OrderGood 205 var orderGoodsToAdd []*domain.OrderGood
  206 +
205 for _, good := range dividendsReturnedOrder.Goods { 207 for _, good := range dividendsReturnedOrder.Goods {
206 if good.OrderGoodId != 0 { 208 if good.OrderGoodId != 0 {
207 orderGoodsToUpdate = append(orderGoodsToUpdate, good) 209 orderGoodsToUpdate = append(orderGoodsToUpdate, good)
@@ -305,7 +307,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -305,7 +307,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
305 } 307 }
306 } 308 }
307 if len(orderGoodModelsToDelete) > 0 { 309 if len(orderGoodModelsToDelete) > 0 {
308 - if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil { 310 + if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil {
309 return nil, err 311 return nil, err
310 } 312 }
311 } 313 }