作者 陈志颖

fix:修复创建现金池问题

... ... @@ -57,6 +57,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id")
}
// 获取平台素币兑换情况
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -74,28 +75,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.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)
// 计算系统平均兑换汇率
var rate float64
if systemExchangedSuMoney == 0 {
rate = 0
} else {
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
}
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
// 判断当前是否有现金池
var cashPoolRepository domain.CashPoolRepository
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
"transactionContext": transactionContext,
... ... @@ -105,18 +88,49 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
countCashPools, _, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(createCashPoolCommand));
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 新建现金池
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash,
ExchangedCash: 0,
UnExchangeCash: 0,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: rate,
Rate: 0,
CreateTime: time.Now(),
}
if countCashPools == 0 { // 现金池为空时处理
newCashPool.ExchangedCash = 0.0
newCashPool.UnExchangeCash = createCashPoolCommand.Cash
} else {
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.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, "无效的公司")
}
newCashPool.ExchangedCash = systemCashStatistics["systemExchangedCash"].(float64)
newCashPool.UnExchangeCash = systemCashStatistics["systemUnExchangeCash"].(float64) + createCashPoolCommand.Cash
// 计算系统平均兑换汇率
var rate float64
if systemExchangedSuMoney == 0 {
rate = 0
} else {
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", newCashPool.ExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
}
newCashPool.Rate = rate
}
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...