作者 陈志颖

fix:修复分红退货单计算

... ... @@ -45,15 +45,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
cooperationProjectRepository = value
}
// 获取共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": applyForCooperationCommand.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
}
// 用户REST服务初始化
var userService service.UserService
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
... ... @@ -102,6 +93,19 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
organization = data
}
// 获取共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": applyForCooperationCommand.CooperationProjectId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
}
// TODO 校验:同一个用户,不能多次申请同一个项目
// TODO 校验:判断用户类型是否属于承接对象
newCooperationApplication := &domain.CooperationApplication{
CooperationApplicationApplicant: applicant,
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
... ...
... ... @@ -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/dividendsReturnedOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsReturnedOrder/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
... ... @@ -130,12 +131,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
}
// 退货金额
var dividendsReturnedOrderRefund float64
// 获取分红退货单产品
var orderGoods []*domain.OrderGood
for _, orderGood := range createDividendsReturnedOrderCommand.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,
... ... @@ -150,11 +155,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
dividendsReturnedOrderRefund, _ = decimal.NewFromFloat(dividendsReturnedOrderRefund).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)))).Float64()
}
newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
DividendsReturnedOrderRefund: createDividendsReturnedOrderCommand.DividendsReturnedOrderRefund,
DividendsReturnedOrderRefund: dividendsReturnedOrderRefund,
OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum,
DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber,
DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName,
... ...
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"
)
... ... @@ -10,9 +11,10 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(
goods []*models.OrderGood) (*domain.DividendsReturnedOrder, 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,
... ... @@ -26,10 +28,11 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(
UpdatedAt: good.UpdatedAt,
})
}
dividendsReturnedOrderRefund, _ := decimal.NewFromFloatWithExponent(dividendsReturnedOrderModel.DividendsReturnedOrderRefund, -2).Float64()
return &domain.DividendsReturnedOrder{
DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId,
DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber,
DividendsReturnedOrderRefund: dividendsReturnedOrderModel.DividendsReturnedOrderRefund,
DividendsReturnedOrderRefund: dividendsReturnedOrderRefund,
OriginalOrderNum: dividendsReturnedOrderModel.OriginalOrderNum,
DividendsOrderNumber: dividendsReturnedOrderModel.DividendsOrderNumber,
DividendsReturnedCustomerName: dividendsReturnedOrderModel.DividendsReturnedCustomerName,
... ...
... ... @@ -108,7 +108,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
); err != nil {
return dividendsReturnedOrder, err
}
// 新增单产品
// 新增退货单产品
var orderGoodsModel []*models.OrderGood
for _, good := range dividendsReturnedOrder.Goods {
orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
... ... @@ -247,9 +247,6 @@ 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 {
... ... @@ -274,6 +271,9 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
}
}
if len(orderGoodModelsToUpdate) > 0 {
log.Logger.Info("待更新的分红退货单产品", map[string]interface{}{
"orderGoodModelsToUpdate": orderGoodModelsToUpdate,
})
if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
return nil, err
}
... ...