...
|
...
|
@@ -91,6 +91,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 不存在现金池
|
|
|
if count == 0 { // 新增现金池
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
...
|
...
|
@@ -120,7 +122,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - (cashPools[0].ExchangedCash + cashPools[0].UnExchangeCash)),
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash),
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: cashPools[0].Rate,
|
...
|
...
|
@@ -285,10 +287,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
}
|
|
|
|
|
|
// 时间格式化
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = createExchangeCashActivityCommand.Deadline
|
|
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 999999, time.Local)
|
|
|
var t1 = time.Now()
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Now().Location())
|
|
|
|
|
|
// 创建兑换活动命令
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
...
|
...
|
@@ -355,7 +356,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
// 提取兑换现金活动截止时间
|
|
|
var deadlines []interface{}
|
|
|
for _, activity := range activities {
|
|
|
deadlines = append(deadlines, activity.Deadline)
|
|
|
deadlines = append(deadlines, activity.Deadline.Format("2006-01-02"))
|
|
|
}
|
|
|
|
|
|
if len(deadlines) == 0 {
|
...
|
...
|
@@ -773,9 +774,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
// 批量更新兑换清单,更新已兑换现金值
|
|
|
for _, personFound := range peopleFound {
|
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 更新兑换清单命令
|
|
|
updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney), 64)
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
|
|
ExchangedCash: updateExchangeCashActivityExchangedCash,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
|
|
}
|
|
|
|
...
|
...
|
@@ -813,7 +816,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 更新兑换活动命令已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
|
|
updateExchangeCashActivityCommand.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney), 64)
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var rate float64
|
...
|
...
|
@@ -862,7 +865,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令已兑换素币
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedSuMoney), 64)
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
...
|
...
|
@@ -1000,6 +1003,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
}
|
|
|
|
|
|
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
|
|
|
// 新增兑换清单命令
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
...
|
...
|
@@ -1009,7 +1014,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
}
|
|
|
|
|
|
// 保存兑换素币清单
|
...
|
...
|
@@ -1036,12 +1041,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedCash: updateExchangeCashActivityExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1117,12 +1124,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
updateCashPoolExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash), 64)
|
|
|
updateCashPoolUnExchangeCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash), 64)
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: updateCashPoolExchangedCash,
|
|
|
UnExchangeCash: updateCashPoolUnExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -1370,7 +1380,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
updateExchangeCashPersonCommand.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
|
|
|
// 更新兑换素币清单
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
...
|
...
|
@@ -1383,11 +1393,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
updateActivityExchangeCash ,_ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)
|
|
|
|
|
|
// 更新素币兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedCash: updateActivityExchangeCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1482,7 +1494,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate
|
|
|
systemExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)
|
|
|
systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
|
|
|
// 计算现金池平均兑换汇率
|
...
|
...
|
@@ -1493,12 +1505,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
|
|
}
|
|
|
|
|
|
updateCashPoolUnExchangeCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate), 64)
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
UnExchangeCash: updateCashPoolUnExchangeCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
...
|
...
|
|