作者 陈志颖

fix:修复新增现金池

... ... @@ -41,7 +41,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
} else {
cashPoolDao = value
}
var systemExchangedCash float64
var (
systemExchangedCash float64
systemUnExchangeCash float64
)
if value, err := cashPoolDao.CalculateSystemCash(createCashPoolCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -67,19 +70,25 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": createCashPoolCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// TODO 获取系统未兑换现金
//count, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
// "companyId": createCashPoolCommand.CompanyId,
//})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if count == 0 {
// systemUnExchangeCash = 0
//} else {
// systemUnExchangeCash = cashPools[0].UnExchangeCash
//}
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: systemExchangedCash,
UnExchangeCash: createCashPoolCommand.Cash + cashPools[0].UnExchangeCash,
UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash,
ExchangedSuMoney: systemChangedSuMoney,
UnExchangeSuMoney: systemUnChangeSuMoney,
Rate: rate,
... ... @@ -94,13 +103,13 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
if activity, err := cashPoolRepository.Save(newCashPool); err != nil {
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return activity, nil
return cashPool, nil
}
}
... ... @@ -387,16 +396,18 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
// TODO 获取兑换活动兑换汇率
//var exchangeCashActivityRepository domain.ExchangeActivityRepository
//activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
//activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//if activity.Rate == 0 {
//if activity == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))
//} else {
// fmt.Print(activity.Rate)
//}
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
// TODO 新增兑换人员时,判断成员是否存在,判断素币值是否超过本人持有的素币,以手机账号为判断依据
... ... @@ -409,7 +420,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
},
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
//ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activity.Rate,
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney,
}
... ...