| | |
| | | return int(total), err |
| | | } |
| | | |
| | | func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm) (err error) { |
| | | func (slf *PurchaseService) SavePurchaseProductConfirm(list []*purchase.PurchaseProductConfirm, first bool) (err error) { |
| | | if len(list) == 0 { |
| | | return errors.New("产品列表不能为空") |
| | | } |
| | |
| | | } |
| | | |
| | | m := make(map[string]interface{}) |
| | | now := int64(0) |
| | | yu := int64(0) |
| | | for _, confirm := range list { |
| | | if !confirm.NowReceiveAmount.IsZero() { |
| | | now = confirm.NowReceiveAmount.IntPart() |
| | | } |
| | | if !confirm.SurplusReceiveAmount.IsZero() { |
| | | yu = confirm.SurplusReceiveAmount.IntPart() |
| | | } |
| | | confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) |
| | | confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) |
| | | } |
| | | if now == 0 && yu > 0 { |
| | | newList := make([]*purchase.PurchaseProductConfirm, 0) |
| | | if first { |
| | | m["status"] = purchase.OrderStatusWaitReceive |
| | | } |
| | | if now > 0 && yu > 0 { |
| | | m["status"] = purchase.OrderStatusPartReceive |
| | | } |
| | | if now > 0 && yu == 0 { |
| | | m["status"] = purchase.OrderStatusWaitQuality |
| | | newList = list |
| | | } else { |
| | | yu := int64(0) |
| | | for _, confirm := range list { |
| | | confirm.OverReceiveAmount = confirm.OverReceiveAmount.Add(confirm.NowReceiveAmount) |
| | | confirm.NotReceiveAmount = confirm.Amount.Sub(confirm.OverReceiveAmount) |
| | | if !confirm.SurplusReceiveAmount.IsZero() { |
| | | yu = confirm.SurplusReceiveAmount.IntPart() |
| | | } |
| | | //过滤本次收货数量为0的数据 |
| | | if !confirm.NowReceiveAmount.IsZero() { |
| | | newList = append(newList, confirm) |
| | | } |
| | | } |
| | | if yu > 0 { |
| | | m["status"] = purchase.OrderStatusPartReceive |
| | | } |
| | | if yu == 0 { |
| | | m["status"] = purchase.OrderStatusWaitQuality |
| | | } |
| | | } |
| | | |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | |
| | | return err |
| | | } |
| | | |
| | | err = tx.Create(list).Error |
| | | err = tx.Create(newList).Error |
| | | if err != nil { |
| | | return err |
| | | } |