...
|
...
|
@@ -103,6 +103,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
cashPoolExchangeCash := cashPools[0].ExchangedCash
|
|
|
cashPoolUnExchangeCash := cashPools[0].UnExchangeCash
|
|
|
|
|
|
// 不存在现金池
|
|
|
if count == 0 { // 新增现金池
|
...
|
...
|
@@ -160,7 +161,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: cashPoolExchangeCash,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),
|
|
|
UnExchangeCash: cashPoolUnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -838,6 +839,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
...
|
...
|
@@ -879,7 +883,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
if updateExchangeCashActivityCommand.ExchangeRate != activityFoundRate && updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率
|
|
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
|
|
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
if activityFoundExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -924,7 +928,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// 更新兑换活动命令已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFoundExchangedSuMoney
|
|
|
deadline := updateExchangeCashActivityCommand.Deadline.Local()
|
|
|
updateExchangeCashActivityCommand.Deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
|
|
|
|
...
|
...
|
@@ -933,14 +937,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
rate = 0
|
|
|
} else {
|
|
|
rate = (cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash)) / systemExchangedSuMoney
|
|
|
rate = (cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash)) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash),
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFound.ExchangedCash) ,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash) ,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: rate,
|
...
|
...
|
@@ -962,7 +966,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
} else { // 更新兑换活动时间
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = activityFound.ExchangedCash
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = activityFoundExchangedCash
|
|
|
deadline := updateExchangeCashActivityCommand.Deadline.Local()
|
|
|
updateExchangeCashActivityCommand.Deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
|
|
|
}
|
...
|
...
|
@@ -979,7 +983,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令已兑换素币
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activityFoundExchangedSuMoney
|
|
|
|
|
|
var currentExchangeCashActivityIndex int
|
|
|
|
...
|
...
|
@@ -1107,6 +1111,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if personFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 获取相关兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": personFound.ExchangeCashActivityId})
|
...
|
...
|
@@ -1116,6 +1121,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
|
|
|
}
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// 获取员工查询条件
|
|
|
getEmployee := map[string]interface{}{
|
...
|
...
|
@@ -1134,13 +1141,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
employeeFoundSuMoney := employeeFound.SuMoney
|
|
|
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if employeeFoundSuMoney < updateExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
if updateExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney {
|
|
|
if employeeFoundSuMoney < (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取兑换清单员工已兑换素币
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
|
...
|
...
|
@@ -1158,8 +1164,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
// 更新素币兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
ExchangedCash: activityFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1229,13 +1235,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * activityUpdated.Rate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {
|
|
|
if (activityUpdated.ExchangedSuMoney - activityFoundExchangedSuMoney) * activityUpdated.Rate > cashPoolFoundUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate
|
|
|
systemExchangedCash := cashPoolFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate
|
|
|
//systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
|
|
|
// 计算现金池平均兑换汇率
|
...
|
...
|
@@ -1251,7 +1260,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
...
|
...
|
@@ -1395,6 +1404,9 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
continue
|
|
|
}
|
|
|
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
...
|
...
|
@@ -1420,6 +1432,9 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
continue
|
|
|
}
|
|
|
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
|
|
|
// 获取员工查询条件
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
...
|
...
|
@@ -1448,6 +1463,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
employeeFoundSuMoney := employeeFound.SuMoney
|
|
|
|
|
|
// 判断当前员工是否已经在素币兑换清单中
|
|
|
_, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
...
|
...
|
@@ -1465,18 +1481,23 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
|
|
createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
"当前兑换素币超过本人持有的素币值",
|
|
|
} else {
|
|
|
if len(peopleFound) != 0 {
|
|
|
peopleFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFoundExchangedSuMoney {
|
|
|
if employeeFoundSuMoney < (createExchangeCashPersonCommand.ExchangedSuMoney - peopleFoundExchangedSuMoney) {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
|
|
createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
"当前兑换素币超过本人持有的素币值",
|
|
|
}
|
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
failureDataList = append(failureDataList, row)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换
|
...
|
...
|
@@ -1488,7 +1509,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
|
|
|
// 素币减量
|
|
|
suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
|
|
|
suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
|
|
|
|
|
|
// 现金减量
|
|
|
cashDecrement := suMoneyDecrement * activityFound.Rate
|
...
|
...
|
@@ -1529,8 +1550,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
// 更新素币兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - suMoneyDecrement,
|
|
|
ExchangedCash: activityFound.ExchangedCash - cashDecrement,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
ExchangedCash: activityFoundExchangedCash - cashDecrement,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1606,7 +1627,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
...
|
...
|
@@ -1647,15 +1668,15 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate = (cashPoolFoundExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash - cashDecrement,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash + cashDecrement,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash - cashDecrement,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -1739,8 +1760,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
// 更新素币兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + suMoneyIncrement,
|
|
|
ExchangedCash: activityFound.ExchangedCash + cashIncrement,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
ExchangedCash: activityFoundExchangedCash + cashIncrement,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1816,7 +1837,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
...
|
...
|
@@ -1857,15 +1878,15 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate = (cashPoolFoundExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + cashIncrement,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - cashIncrement,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + cashIncrement,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -1972,8 +1993,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2015,7 +2036,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
|
|
row := []interface{}{
|
|
|
createExchangeCashPersonCommand.PersonName,
|
|
|
createExchangeCashPersonCommand.PersonAccount,
|
...
|
...
|
@@ -2056,15 +2077,15 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -2208,6 +2229,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
...
|
...
|
@@ -2285,8 +2308,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2317,6 +2340,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
|
|
|
}
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolFoundUnExchangeCash {
|
...
|
...
|
@@ -2339,15 +2363,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -2601,6 +2625,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(personFound.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// 判断当前人员状态
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": personFound.EmployeeInfo.Uid,
|
...
|
...
|
@@ -2620,8 +2647,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
// 更新兑换素币活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - personFoundExchangedCash,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash - personFoundExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2681,12 +2708,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var newRate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash - personFoundExchangedCash) / systemExchangedSuMoney
|
|
|
newRate = (cashPoolFoundExchangedCash - personFoundExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
...
|
...
|
@@ -2694,8 +2724,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash - personFoundExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash + personFoundExchangedCash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash - personFoundExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash + personFoundExchangedCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
...
|
...
|
|