作者 陈志颖

fix:个人素币判断、现金池现金判断

... ... @@ -102,6 +102,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cashPoolExchangeCash := cashPools[0].ExchangedCash
// 不存在现金池
if count == 0 { // 新增现金池
... ... @@ -130,11 +131,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
return cashPool, nil
}
} else { // 更新现金池
if createCashPoolCommand.Cash < cashPools[0].ExchangedCash {
if createCashPoolCommand.Cash < cashPoolExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "投入的现金值必须大于当前已兑换现金值")
}
// 重新计算平均兑换汇率
newRate := cashPools[0].ExchangedCash / systemExchangedSuMoney
newRate := cashPoolExchangeCash / systemExchangedSuMoney
// 获取上次兑换活动兑换汇率查询
var lastActivityRate float64
... ... @@ -158,7 +159,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPools[0].CashPoolId,
Cash: createCashPoolCommand.Cash,
ExchangedCash: cashPools[0].ExchangedCash,
ExchangedCash: cashPoolExchangeCash,
UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
... ... @@ -589,7 +590,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
// 更新兑换现金活动倒计时命令
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
ExchangeCashActivityId: activity.ActivityId,
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)), // 重新计算活动倒计时
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
Deadline: activity.Deadline.Local(),
ExchangedSuMoney: activity.ExchangedSuMoney,
ExchangedCash: activity.ExchangedCash,
... ... @@ -870,13 +871,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
return activityUpdated, nil
}
}
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
// 获取当前兑换活动汇率
activityFoundRate := activityFound.Rate
if updateExchangeCashActivityCommand.ExchangeRate != activityFoundRate && updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
... ... @@ -930,14 +933,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
if systemExchangedSuMoney == 0 {
rate = 0
} else {
rate = (cashPoolsFound[0].ExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney
rate = (cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney
}
// 更新现金池命令
updateCashPoolCommand := &command.UpdateCashPoolCommand{
CashPoolId: cashPoolsFound[0].CashPoolId,
ExchangedCash: cashPoolsFound[0].ExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) ,
ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) ,
ExchangedSuMoney: systemExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: rate,
... ... @@ -1128,9 +1131,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
if employeeFound == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
}
employeeFoundSuMoney := employeeFound.SuMoney
// 判断该员工兑换的素币是否超过本人持有的素币
if employeeFound.SuMoney < updateExchangeCashPersonCommand.ExchangedSuMoney {
if employeeFoundSuMoney < updateExchangeCashPersonCommand.ExchangedSuMoney {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
}
... ... @@ -1224,8 +1228,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
}
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
// 判断是否超过平台未兑换现金
if activityUpdated.ExchangedSuMoney * activityUpdated.Rate > cashPoolsFound[0].UnExchangeCash {
if activityUpdated.ExchangedSuMoney * activityUpdated.Rate > cashPoolFoundUnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
}
... ... @@ -2217,6 +2223,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if employeeFound == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
}
employeeFoundSuMoney := employeeFound.SuMoney
// 判断当前员工是否已经存在兑换素币清单中
if _, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
... ... @@ -2231,7 +2238,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
}
// 判断该员工兑换的素币是否超过本人持有的素币
if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
if employeeFoundSuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
}
... ... @@ -2309,9 +2316,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
if len(cashPoolsFound) == 0 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
}
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
// 判断兑换活动的现金是否超过现金池未兑换现金
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池未兑换现金")
}
... ...