作者 陈志颖

fix:修复兑换汇率计算问题

@@ -727,16 +727,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -727,16 +727,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
727 } 727 }
728 728
729 if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率 729 if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
730 - // 增大汇率  
731 - if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {  
732 -  
733 - }  
734 -  
735 - // 减小汇率  
736 - if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {  
737 -  
738 - }  
739 - 730 + //// 增大汇率
  731 + //if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {
  732 + //
  733 + //}
  734 + //
  735 + //// 减小汇率
  736 + //if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {
  737 + //
  738 + //}
740 // 获取当前公司现金池 739 // 获取当前公司现金池
741 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 740 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
742 "companyId": activityFound.CompanyId, 741 "companyId": activityFound.CompanyId,
@@ -1089,14 +1088,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1089,14 +1088,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1089 } 1088 }
1090 1089
1091 // 获取平台现金兑换情况 1090 // 获取平台现金兑换情况
1092 - systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)  
1093 - if err != nil {  
1094 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1095 - }  
1096 - if systemCashStatistics == nil {  
1097 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1098 - }  
1099 - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 1091 + //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
  1092 + //if err != nil {
  1093 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1094 + //}
  1095 + //if systemCashStatistics == nil {
  1096 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  1097 + //}
  1098 + //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
1100 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1099 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1101 1100
1102 // 获取平台素币兑换情况 1101 // 获取平台素币兑换情况
@@ -1115,7 +1114,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1115,7 +1114,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1115 if systemExchangedSuMoney == 0 { 1114 if systemExchangedSuMoney == 0 {
1116 newRate = 0 1115 newRate = 0
1117 } else { 1116 } else {
1118 - newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1117 + newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney), 64)
1119 } 1118 }
1120 1119
1121 // 更新现金池命令 1120 // 更新现金池命令
@@ -1273,7 +1272,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1273,7 +1272,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1273 } 1272 }
1274 } 1273 }
1275 1274
1276 -// 更新兑换清单 1275 +// 更新兑换素币清单
1277 func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) { 1276 func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
1278 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil { 1277 if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
1279 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1278 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -1453,7 +1452,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1453,7 +1452,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1453 if systemCashStatistics == nil { 1452 if systemCashStatistics == nil {
1454 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1453 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1455 } 1454 }
1456 - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 1455 + //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
1457 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1456 systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1458 1457
1459 // 统计平台素币兑换状况 1458 // 统计平台素币兑换状况
@@ -1464,7 +1463,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1464,7 +1463,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1464 if systemSuMoneyStatistics == nil { 1463 if systemSuMoneyStatistics == nil {
1465 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 1464 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
1466 } 1465 }
1467 - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 1466 + //systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1468 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1467 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1469 1468
1470 // 判断是否超过平台未兑换现金 1469 // 判断是否超过平台未兑换现金
@@ -1483,6 +1482,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1483,6 +1482,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1483 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId))) 1482 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
1484 } 1483 }
1485 1484
  1485 + systemExchangedCash := cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate
  1486 + systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
  1487 +
1486 // 计算现金池平均兑换汇率 1488 // 计算现金池平均兑换汇率
1487 var newRate float64 1489 var newRate float64
1488 if systemExchangedSuMoney == 0 { 1490 if systemExchangedSuMoney == 0 {
@@ -1494,14 +1496,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1494,14 +1496,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1494 // 更新现金池命令 1496 // 更新现金池命令
1495 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1497 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1496 CashPoolId: cashPoolsFound[0].CashPoolId, 1498 CashPoolId: cashPoolsFound[0].CashPoolId,
1497 - ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate, 1499 + Cash: cashPoolsFound[0].Cash,
  1500 + ExchangedCash: systemExchangedCash,
1498 UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate, 1501 UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
1499 Rate: newRate, 1502 Rate: newRate,
1500 - ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney), 1503 + ExchangedSuMoney: systemExchangedSuMoney,
1501 UnExchangeSuMoney: systemUnExchangeSuMoney, 1504 UnExchangeSuMoney: systemUnExchangeSuMoney,
1502 LastRate: cashPoolsFound[0].LastRate, 1505 LastRate: cashPoolsFound[0].LastRate,
1503 - //CompanyId: cashPoolsFound[0].CompanyId,  
1504 - //CreateTime: time.Now(),  
1505 } 1506 }
1506 1507
1507 // 更新现金池 1508 // 更新现金池
@@ -1658,14 +1659,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1658,14 +1659,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1658 } 1659 }
1659 1660
1660 // 获取平台现金兑换情况 1661 // 获取平台现金兑换情况
1661 - systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)  
1662 - if err != nil {  
1663 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1664 - }  
1665 - if systemCashStatistics == nil {  
1666 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1667 - }  
1668 - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) 1662 + //systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
  1663 + //if err != nil {
  1664 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1665 + //}
  1666 + //if systemCashStatistics == nil {
  1667 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
  1668 + //}
  1669 + //systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
1669 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) 1670 //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
1670 1671
1671 // 获取平台素币兑换情况 1672 // 获取平台素币兑换情况
@@ -1695,7 +1696,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -1695,7 +1696,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
1695 if systemExchangedSuMoney == 0 { 1696 if systemExchangedSuMoney == 0 {
1696 newRate = 0 1697 newRate = 0
1697 } else { 1698 } else {
1698 - newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) 1699 + newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney) / systemExchangedSuMoney), 64)
1699 } 1700 }
1700 1701
1701 // 更新现金池命令 1702 // 更新现金池命令