作者 陈志颖

fix:分红订单计算

@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "fmt" 6 "fmt"
7 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
8 "github.com/linmadan/egglib-go/utils/tool_funs" 8 "github.com/linmadan/egglib-go/utils/tool_funs"
  9 + "github.com/shopspring/decimal"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
@@ -121,9 +122,10 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -121,9 +122,10 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
121 var orderGoods []*domain.OrderGood 122 var orderGoods []*domain.OrderGood
122 var dividendsOrderAmount float64 123 var dividendsOrderAmount float64
123 for _, orderGood := range createDividendsOrderCommand.OrderGoods { 124 for _, orderGood := range createDividendsOrderCommand.OrderGoods {
  125 + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
124 orderGoods = append(orderGoods, &domain.OrderGood{ 126 orderGoods = append(orderGoods, &domain.OrderGood{
125 OrderGoodId: 0, 127 OrderGoodId: 0,
126 - OrderGoodAmount: orderGood.OrderGoodAmount, 128 + OrderGoodAmount: orderGoodAmount,
127 OrderGoodName: orderGood.OrderGoodName, 129 OrderGoodName: orderGood.OrderGoodName,
128 OrderGoodPrice: orderGood.OrderGoodPrice, 130 OrderGoodPrice: orderGood.OrderGoodPrice,
129 OrderGoodQuantity: orderGood.OrderGoodQuantity, 131 OrderGoodQuantity: orderGood.OrderGoodQuantity,
@@ -139,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -139,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
139 UpdatedAt: time.Time{}, 141 UpdatedAt: time.Time{},
140 }) 142 })
141 // 计算分红订单金额 143 // 计算分红订单金额
142 - dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount 144 + dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
143 } 145 }
144 146
145 // 订单时间转换 147 // 订单时间转换
@@ -621,7 +623,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -621,7 +623,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
621 623
622 // 批量创建分红订单 624 // 批量创建分红订单
623 for _, dividendsOrder := range createDividendsOrderCommands { 625 for _, dividendsOrder := range createDividendsOrderCommands {
624 - // 生成分红订单号 626 + // TODO 表为空时生成分红订单号
625 dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber() 627 dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
626 if err != nil { 628 if err != nil {
627 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 629 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -667,9 +669,11 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -667,9 +669,11 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
667 } 669 }
668 } 670 }
669 671
  672 + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
  673 +
670 orderGoods = append(orderGoods, &domain.OrderGood{ 674 orderGoods = append(orderGoods, &domain.OrderGood{
671 OrderGoodId: 0, 675 OrderGoodId: 0,
672 - OrderGoodAmount: orderGood.OrderGoodAmount, 676 + OrderGoodAmount: orderGoodAmount,
673 OrderGoodName: orderGood.OrderGoodName, 677 OrderGoodName: orderGood.OrderGoodName,
674 OrderGoodPrice: orderGood.OrderGoodPrice, 678 OrderGoodPrice: orderGood.OrderGoodPrice,
675 OrderGoodQuantity: orderGood.OrderGoodQuantity, 679 OrderGoodQuantity: orderGood.OrderGoodQuantity,
@@ -685,7 +689,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -685,7 +689,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
685 }) 689 })
686 690
687 // 计算分红订单金额 691 // 计算分红订单金额
688 - dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodPrice*float64(orderGood.OrderGoodQuantity) 692 + dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
689 } 693 }
690 if len(orderGoodErrMap) > 0 { 694 if len(orderGoodErrMap) > 0 {
691 row := &domain.ImportInfo{ 695 row := &domain.ImportInfo{
@@ -758,7 +762,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -758,7 +762,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
758 for _, errorData := range errorDataList { 762 for _, errorData := range errorDataList {
759 if len(errorData.GoodLine) == 0 { // 订单错误 763 if len(errorData.GoodLine) == 0 { // 订单错误
760 for _, line := range errorData.LineNumbers { 764 for _, line := range errorData.LineNumbers {
761 - //s := strconv.Itoa(line + 1)  
762 tmpRow := &domain.FailInfo{ 765 tmpRow := &domain.FailInfo{
763 FailReason: "订单数据新增错误:" + errorData.Error.Error(), 766 FailReason: "订单数据新增错误:" + errorData.Error.Error(),
764 } 767 }
@@ -767,7 +770,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -767,7 +770,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
767 } 770 }
768 } else if len(errorData.GoodLine) > 0 { // 订单产品错误 771 } else if len(errorData.GoodLine) > 0 { // 订单产品错误
769 for line := range errorData.GoodLine { 772 for line := range errorData.GoodLine {
770 - //s := strconv.Itoa(line + 1)  
771 tmpRow := &domain.FailInfo{ 773 tmpRow := &domain.FailInfo{
772 FailReason: "订单数据新增错误:" + errorData.Error.Error(), 774 FailReason: "订单数据新增错误:" + errorData.Error.Error(),
773 } 775 }
1 package transform 1 package transform
2 2
3 import ( 3 import (
  4 + "github.com/shopspring/decimal"
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
6 ) 7 )
@@ -8,9 +9,10 @@ import ( @@ -8,9 +9,10 @@ import (
8 func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder, goods []*models.OrderGood) (*domain.DividendsOrder, error) { 9 func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder, goods []*models.OrderGood) (*domain.DividendsOrder, error) {
9 var orderGoods []*domain.OrderGood 10 var orderGoods []*domain.OrderGood
10 for _, good := range goods { 11 for _, good := range goods {
  12 + orderGoodAmount, _ := decimal.NewFromFloatWithExponent(good.OrderGoodAmount, -2).Float64()
11 orderGoods = append(orderGoods, &domain.OrderGood{ 13 orderGoods = append(orderGoods, &domain.OrderGood{
12 OrderGoodId: good.OrderGoodId, 14 OrderGoodId: good.OrderGoodId,
13 - OrderGoodAmount: good.OrderGoodAmount, 15 + OrderGoodAmount: orderGoodAmount,
14 OrderGoodName: good.OrderGoodName, 16 OrderGoodName: good.OrderGoodName,
15 OrderGoodPrice: good.OrderGoodPrice, 17 OrderGoodPrice: good.OrderGoodPrice,
16 OrderGoodQuantity: good.OrderGoodQuantity, 18 OrderGoodQuantity: good.OrderGoodQuantity,
@@ -24,11 +26,12 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model @@ -24,11 +26,12 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model
24 UpdatedAt: good.UpdatedAt, 26 UpdatedAt: good.UpdatedAt,
25 }) 27 })
26 } 28 }
  29 + dividendsOrderAmount, _ := decimal.NewFromFloatWithExponent(dividendsOrderModel.DividendsOrderAmount, -2).Float64()
27 return &domain.DividendsOrder{ 30 return &domain.DividendsOrder{
28 DividendsOrderId: dividendsOrderModel.DividendsOrderId, 31 DividendsOrderId: dividendsOrderModel.DividendsOrderId,
29 DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber, 32 DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
30 DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum, 33 DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum,
31 - DividendsOrderAmount: dividendsOrderModel.DividendsOrderAmount, 34 + DividendsOrderAmount: dividendsOrderAmount,
32 OrderTime: dividendsOrderModel.OrderTime, 35 OrderTime: dividendsOrderModel.OrderTime,
33 DividendTime: dividendsOrderModel.DividendTime, 36 DividendTime: dividendsOrderModel.DividendTime,
34 DividendStatus: dividendsOrderModel.DividendStatus, 37 DividendStatus: dividendsOrderModel.DividendStatus,