作者 陈志颖

fix:分红订单计算

... ... @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
... ... @@ -121,9 +122,10 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range createDividendsOrderCommand.OrderGoods {
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
... ... @@ -139,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
}
// 订单时间转换
... ... @@ -621,7 +623,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 批量创建分红订单
for _, dividendsOrder := range createDividendsOrderCommands {
// 生成分红订单号
// TODO 表为空时生成分红订单号
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -667,9 +669,11 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
}
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
... ... @@ -685,7 +689,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
})
// 计算分红订单金额
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodPrice*float64(orderGood.OrderGoodQuantity)
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
}
if len(orderGoodErrMap) > 0 {
row := &domain.ImportInfo{
... ... @@ -758,7 +762,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
for _, errorData := range errorDataList {
if len(errorData.GoodLine) == 0 { // 订单错误
for _, line := range errorData.LineNumbers {
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
}
... ... @@ -767,7 +770,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
for line := range errorData.GoodLine {
//s := strconv.Itoa(line + 1)
tmpRow := &domain.FailInfo{
FailReason: "订单数据新增错误:" + errorData.Error.Error(),
}
... ...
package transform
import (
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
... ... @@ -8,9 +9,10 @@ import (
func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder, goods []*models.OrderGood) (*domain.DividendsOrder, error) {
var orderGoods []*domain.OrderGood
for _, good := range goods {
orderGoodAmount, _ := decimal.NewFromFloatWithExponent(good.OrderGoodAmount, -2).Float64()
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: good.OrderGoodId,
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
... ... @@ -24,11 +26,12 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model
UpdatedAt: good.UpdatedAt,
})
}
dividendsOrderAmount, _ := decimal.NewFromFloatWithExponent(dividendsOrderModel.DividendsOrderAmount, -2).Float64()
return &domain.DividendsOrder{
DividendsOrderId: dividendsOrderModel.DividendsOrderId,
DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum,
DividendsOrderAmount: dividendsOrderModel.DividendsOrderAmount,
DividendsOrderAmount: dividendsOrderAmount,
OrderTime: dividendsOrderModel.OrderTime,
DividendTime: dividendsOrderModel.DividendTime,
DividendStatus: dividendsOrderModel.DividendStatus,
... ...