作者 陈志颖

fix:修复更新兑换活动汇率,现金池计算问题

... ... @@ -727,6 +727,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
}
if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
// 增大汇率
if updateExchangeCashActivityCommand.ExchangeRate > activityFound.Rate {
}
// 减小汇率
if updateExchangeCashActivityCommand.ExchangeRate < activityFound.Rate {
}
// 获取当前公司现金池
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": activityFound.CompanyId,
... ... @@ -763,10 +773,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
// 批量更新兑换清单,更新已兑换现金值
for _, personFound := range peopleFound {
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
// 更新兑换清单命令
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFound.ExchangedSuMoney,
ExchangedSuMoney: personFound.ExchangedSuMoney,
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
ExchangedSuMoney: personFoundExchangedSuMoney,
}
// 更新素币兑换清单
... ... @@ -779,6 +790,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 获取平台素币状况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
if err != nil {
... ... @@ -801,22 +813,26 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
// 更新兑换活动命令已兑换现金
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
// 计算平均兑换汇率
var rate float64
if systemExchangedSuMoney == 0 {
rate = 0
} else {
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (systemExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney), 64)
}
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
ExchangedCash: systemUnExchangeCash,
UnExchangeCash: systemUnExchangeCash,
ExchangedCash: systemExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),
UnExchangeCash: systemUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) ,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: rate,
Cash: cashPoolsFound[0].Cash,
}
// 更新现金池
... ... @@ -832,10 +848,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if cashPoolUpdated == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 更新兑换活动命令已兑换现金
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
} else { // 未更新兑换活动汇率
updateExchangeCashActivityCommand.ExchangedCash = activityFound.ExchangedCash
}
... ... @@ -1110,14 +1122,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
Cash: cashPoolsFound[0].Cash,
//CompanyId: cashPoolsFound[0].CompanyId,
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: newRate,
LastRate: cashPoolsFound[0].LastRate,
//CreateTime: time.Now(),
}
// 更新现金池
... ...