作者 陈志颖

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

... ... @@ -727,16 +727,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
}
if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
// 增大汇率
if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {
}
// 减小汇率
if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {
}
//// 增大汇率
//if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {
//
//}
//
//// 减小汇率
//if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {
//
//}
// 获取当前公司现金池
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": activityFound.CompanyId,
... ... @@ -1089,14 +1088,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
}
// 获取平台现金兑换情况
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
//systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if systemCashStatistics == nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
//}
//systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
// 获取平台素币兑换情况
... ... @@ -1115,7 +1114,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if systemExchangedSuMoney == 0 {
newRate = 0
} else {
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney), 64)
}
// 更新现金池命令
... ... @@ -1273,7 +1272,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
}
}
// 更新兑换清单
// 更新兑换素币清单
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -1453,7 +1452,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
//systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
// 统计平台素币兑换状况
... ... @@ -1464,7 +1463,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
//systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
// 判断是否超过平台未兑换现金
... ... @@ -1483,6 +1482,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
}
systemExchangedCash := cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate
systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
// 计算现金池平均兑换汇率
var newRate float64
if systemExchangedSuMoney == 0 {
... ... @@ -1494,14 +1496,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
Cash: cashPoolsFound[0].Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
Rate: newRate,
ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
LastRate: cashPoolsFound[0].LastRate,
//CompanyId: cashPoolsFound[0].CompanyId,
//CreateTime: time.Now(),
}
// 更新现金池
... ... @@ -1658,14 +1659,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
}
// 获取平台现金兑换情况
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemCashStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
//systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if systemCashStatistics == nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
//}
//systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
// 获取平台素币兑换情况
... ... @@ -1695,7 +1696,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
if systemExchangedSuMoney == 0 {
newRate = 0
} else {
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash - personFoundExchangedSuMoney) / systemExchangedSuMoney), 64)
}
// 更新现金池命令
... ...