作者 陈志颖

fix:修复分红退货单计算

@@ -45,15 +45,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -45,15 +45,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
45 cooperationProjectRepository = value 45 cooperationProjectRepository = value
46 } 46 }
47 47
48 - // 获取共创项目  
49 - cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": applyForCooperationCommand.CooperationProjectId})  
50 - if err != nil {  
51 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")  
52 - }  
53 - if cooperationProject == nil {  
54 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))  
55 - }  
56 -  
57 // 用户REST服务初始化 48 // 用户REST服务初始化
58 var userService service.UserService 49 var userService service.UserService
59 if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { 50 if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
@@ -102,6 +93,19 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -102,6 +93,19 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
102 organization = data 93 organization = data
103 } 94 }
104 95
  96 + // 获取共创项目
  97 + cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": applyForCooperationCommand.CooperationProjectId})
  98 + if err != nil {
  99 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在")
  100 + }
  101 + if cooperationProject == nil {
  102 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
  103 + }
  104 +
  105 + // TODO 校验:同一个用户,不能多次申请同一个项目
  106 +
  107 + // TODO 校验:判断用户类型是否属于承接对象
  108 +
105 newCooperationApplication := &domain.CooperationApplication{ 109 newCooperationApplication := &domain.CooperationApplication{
106 CooperationApplicationApplicant: applicant, 110 CooperationApplicationApplicant: applicant,
107 CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment, 111 CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
@@ -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/dividendsReturnedOrder/command" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsReturnedOrder/command"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsReturnedOrder/query" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsReturnedOrder/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"
@@ -130,12 +131,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide @@ -130,12 +131,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
130 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在") 131 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
131 } 132 }
132 133
  134 + // 退货金额
  135 + var dividendsReturnedOrderRefund float64
  136 +
133 // 获取分红退货单产品 137 // 获取分红退货单产品
134 var orderGoods []*domain.OrderGood 138 var orderGoods []*domain.OrderGood
135 for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods { 139 for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods {
  140 + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
136 orderGoods = append(orderGoods, &domain.OrderGood{ 141 orderGoods = append(orderGoods, &domain.OrderGood{
137 OrderGoodId: 0, 142 OrderGoodId: 0,
138 - OrderGoodAmount: orderGood.OrderGoodAmount, 143 + OrderGoodAmount: orderGoodAmount,
139 OrderGoodName: orderGood.OrderGoodName, 144 OrderGoodName: orderGood.OrderGoodName,
140 OrderGoodPrice: orderGood.OrderGoodPrice, 145 OrderGoodPrice: orderGood.OrderGoodPrice,
141 OrderGoodQuantity: orderGood.OrderGoodQuantity, 146 OrderGoodQuantity: orderGood.OrderGoodQuantity,
@@ -150,11 +155,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide @@ -150,11 +155,12 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
150 DeletedAt: time.Time{}, 155 DeletedAt: time.Time{},
151 UpdatedAt: time.Time{}, 156 UpdatedAt: time.Time{},
152 }) 157 })
  158 + dividendsReturnedOrderRefund, _ = decimal.NewFromFloat(dividendsReturnedOrderRefund).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)))).Float64()
153 } 159 }
154 160
155 newDividendsReturnedOrder := &domain.DividendsReturnedOrder{ 161 newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
156 DividendsReturnedOrderNumber: dividendsReturnedOrderNumber, 162 DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
157 - DividendsReturnedOrderRefund: createDividendsReturnedOrderCommand.DividendsReturnedOrderRefund, 163 + DividendsReturnedOrderRefund: dividendsReturnedOrderRefund,
158 OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum, 164 OriginalOrderNum: createDividendsReturnedOrderCommand.OriginalOrderNum,
159 DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber, 165 DividendsOrderNumber: createDividendsReturnedOrderCommand.DividendsOrderNumber,
160 DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName, 166 DividendsReturnedCustomerName: createDividendsReturnedOrderCommand.DividendsReturnedCustomerName,
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 )
@@ -10,9 +11,10 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels( @@ -10,9 +11,10 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(
10 goods []*models.OrderGood) (*domain.DividendsReturnedOrder, error) { 11 goods []*models.OrderGood) (*domain.DividendsReturnedOrder, error) {
11 var orderGoods []*domain.OrderGood 12 var orderGoods []*domain.OrderGood
12 for _, good := range goods { 13 for _, good := range goods {
  14 + orderGoodAmount, _ := decimal.NewFromFloatWithExponent(good.OrderGoodAmount, -2).Float64()
13 orderGoods = append(orderGoods, &domain.OrderGood{ 15 orderGoods = append(orderGoods, &domain.OrderGood{
14 OrderGoodId: good.OrderGoodId, 16 OrderGoodId: good.OrderGoodId,
15 - OrderGoodAmount: good.OrderGoodAmount, 17 + OrderGoodAmount: orderGoodAmount,
16 OrderGoodName: good.OrderGoodName, 18 OrderGoodName: good.OrderGoodName,
17 OrderGoodPrice: good.OrderGoodPrice, 19 OrderGoodPrice: good.OrderGoodPrice,
18 OrderGoodQuantity: good.OrderGoodQuantity, 20 OrderGoodQuantity: good.OrderGoodQuantity,
@@ -26,10 +28,11 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels( @@ -26,10 +28,11 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(
26 UpdatedAt: good.UpdatedAt, 28 UpdatedAt: good.UpdatedAt,
27 }) 29 })
28 } 30 }
  31 + dividendsReturnedOrderRefund, _ := decimal.NewFromFloatWithExponent(dividendsReturnedOrderModel.DividendsReturnedOrderRefund, -2).Float64()
29 return &domain.DividendsReturnedOrder{ 32 return &domain.DividendsReturnedOrder{
30 DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId, 33 DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId,
31 DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber, 34 DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber,
32 - DividendsReturnedOrderRefund: dividendsReturnedOrderModel.DividendsReturnedOrderRefund, 35 + DividendsReturnedOrderRefund: dividendsReturnedOrderRefund,
33 OriginalOrderNum: dividendsReturnedOrderModel.OriginalOrderNum, 36 OriginalOrderNum: dividendsReturnedOrderModel.OriginalOrderNum,
34 DividendsOrderNumber: dividendsReturnedOrderModel.DividendsOrderNumber, 37 DividendsOrderNumber: dividendsReturnedOrderModel.DividendsOrderNumber,
35 DividendsReturnedCustomerName: dividendsReturnedOrderModel.DividendsReturnedCustomerName, 38 DividendsReturnedCustomerName: dividendsReturnedOrderModel.DividendsReturnedCustomerName,
@@ -108,7 +108,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -108,7 +108,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
108 ); err != nil { 108 ); err != nil {
109 return dividendsReturnedOrder, err 109 return dividendsReturnedOrder, err
110 } 110 }
111 - // 新增单产品 111 + // 新增退货单产品
112 var orderGoodsModel []*models.OrderGood 112 var orderGoodsModel []*models.OrderGood
113 for _, good := range dividendsReturnedOrder.Goods { 113 for _, good := range dividendsReturnedOrder.Goods {
114 orderGoodsModel = append(orderGoodsModel, &models.OrderGood{ 114 orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
@@ -247,9 +247,6 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -247,9 +247,6 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
247 } 247 }
248 } 248 }
249 } 249 }
250 - log.Logger.Info("待更新的分红退货单产品", map[string]interface{}{  
251 - "orderGoodModelsToUpdate": orderGoodModelsToUpdate,  
252 - })  
253 for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate { 250 for i, orderGoodModelToUpdate := range orderGoodModelsToUpdate {
254 for j, orderGood := range dividendsReturnedOrder.Goods { 251 for j, orderGood := range dividendsReturnedOrder.Goods {
255 if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId { 252 if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
@@ -274,6 +271,9 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -274,6 +271,9 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
274 } 271 }
275 } 272 }
276 if len(orderGoodModelsToUpdate) > 0 { 273 if len(orderGoodModelsToUpdate) > 0 {
  274 + log.Logger.Info("待更新的分红退货单产品", map[string]interface{}{
  275 + "orderGoodModelsToUpdate": orderGoodModelsToUpdate,
  276 + })
277 if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { 277 if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil {
278 return nil, err 278 return nil, err
279 } 279 }