...
|
...
|
@@ -16,6 +16,8 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
|
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
)
|
|
|
|
|
|
// 现金池服务
|
...
|
...
|
@@ -27,6 +29,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if err := createCashPoolCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -116,7 +119,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = cashPoolExchangeCash / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolExchangeCash).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
|
|
|
// 获取上次兑换活动兑换汇率查询
|
...
|
...
|
@@ -137,12 +140,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
}
|
|
|
}
|
|
|
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolUnExchangeCash).Add(decimal.NewFromFloat(createCashPoolCommand.Cash).Sub(decimal.NewFromFloat(cashPoolCash))).Float64()
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
|
|
ExchangedCash: cashPoolExchangeCash,
|
|
|
UnExchangeCash: cashPoolUnExchangeCash + (createCashPoolCommand.Cash - cashPoolCash),
|
|
|
//UnExchangeCash: cashPoolUnExchangeCash + (createCashPoolCommand.Cash - cashPoolCash),
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -161,15 +167,40 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.Rate), 64)
|
|
|
cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeCash), 64)
|
|
|
cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedSuMoney), 64)
|
|
|
cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeSuMoney), 64)
|
|
|
cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedCash), 64)
|
|
|
cashPool.LastRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.LastRate), 64)
|
|
|
//cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.Rate), 64)
|
|
|
//cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeCash), 64)
|
|
|
//cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedSuMoney), 64)
|
|
|
//cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeSuMoney), 64)
|
|
|
//cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedCash), 64)
|
|
|
//cashPool.LastRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.LastRate), 64)
|
|
|
cashPool.Rate, _ = decimal.NewFromFloatWithExponent(cashPool.Rate, -2).Float64()
|
|
|
cashPool.UnExchangeCash, _ = decimal.NewFromFloatWithExponent(cashPool.UnExchangeCash, -2).Float64()
|
|
|
cashPool.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(cashPool.ExchangedSuMoney, -2).Float64()
|
|
|
cashPool.UnExchangeSuMoney, _ = decimal.NewFromFloatWithExponent(cashPool.UnExchangeSuMoney, -2).Float64()
|
|
|
cashPool.ExchangedCash, _ = decimal.NewFromFloatWithExponent(cashPool.ExchangedCash, -2).Float64()
|
|
|
cashPool.LastRate, _ = decimal.NewFromFloatWithExponent(cashPool.LastRate, -2).Float64()
|
|
|
return cashPool, nil
|
|
|
}
|
|
|
} else { // 新增现金池
|
|
|
// 获取上次兑换活动兑换汇率查询
|
|
|
var lastActivityRate float64
|
|
|
listExchangeCashActivityQuery := map[string]interface{}{
|
|
|
"companyId": createCashPoolCommand.CompanyId,
|
|
|
"order": "deadline DESC",
|
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
}
|
|
|
if _, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if len(activities) > 0 {
|
|
|
lastActivityRate = activities[0].Rate
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
lastActivityRate = 0
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
|
Cash: createCashPoolCommand.Cash,
|
...
|
...
|
@@ -177,7 +208,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
UnExchangeCash: createCashPoolCommand.Cash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
LastRate: 0,
|
|
|
LastRate: lastActivityRate,
|
|
|
Rate: 0,
|
|
|
CreateTime: time.Now().Local(),
|
|
|
}
|
...
|
...
|
@@ -187,11 +218,16 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.Rate), 64)
|
|
|
cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeCash), 64)
|
|
|
cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedSuMoney), 64)
|
|
|
cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeSuMoney), 64)
|
|
|
cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedCash), 64)
|
|
|
//cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.Rate), 64)
|
|
|
//cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeCash), 64)
|
|
|
//cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedSuMoney), 64)
|
|
|
//cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.UnExchangeSuMoney), 64)
|
|
|
//cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPool.ExchangedCash), 64)
|
|
|
cashPool.Rate, _ = decimal.NewFromFloatWithExponent(cashPool.Rate, -2).Float64()
|
|
|
cashPool.UnExchangeCash, _ = decimal.NewFromFloatWithExponent(cashPool.UnExchangeCash, -2).Float64()
|
|
|
cashPool.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(cashPool.ExchangedSuMoney, -2).Float64()
|
|
|
cashPool.UnExchangeSuMoney, _ = decimal.NewFromFloatWithExponent(cashPool.UnExchangeSuMoney, -2).Float64()
|
|
|
cashPool.ExchangedCash, _ = decimal.NewFromFloatWithExponent(cashPool.ExchangedCash, -2).Float64()
|
|
|
return cashPool, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -202,6 +238,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
if err := getCashPoolQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -272,10 +309,10 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
"nearest": true,
|
|
|
"limit": 1,
|
|
|
}
|
|
|
if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
if _, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count >= 0 {
|
|
|
if len(activities) > 0 {
|
|
|
lastActivityRate = activities[0].Rate
|
|
|
} else { // 未查询到相关兑换活动
|
|
|
lastActivityRate = 0
|
...
|
...
|
@@ -290,7 +327,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
systemUnExchangeSuMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)), 64) // 平台未兑换素币
|
|
|
//systemUnExchangeSuMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)), 64) // 平台未兑换素币
|
|
|
systemUnExchangeSuMoney, _ := decimal.NewFromFloatWithExponent(systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64), -2).Float64() // 平台未兑换素币
|
|
|
|
|
|
// 查找当前公司现金池
|
|
|
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); err != nil {
|
...
|
...
|
@@ -314,12 +352,18 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
"createTime": time.Now().Local(),
|
|
|
}, nil
|
|
|
} else {
|
|
|
cashPools[0].Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].Rate), 64)
|
|
|
cashPools[0].LastRate = lastActivityRate
|
|
|
cashPools[0].UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].UnExchangeCash), 64)
|
|
|
cashPools[0].ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedCash), 64)
|
|
|
cashPools[0].ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedSuMoney), 64)
|
|
|
cashPools[0].UnExchangeSuMoney, _= strconv.ParseFloat(fmt.Sprintf("%.2f", systemUnExchangeSuMoney), 64)
|
|
|
//cashPools[0].Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].Rate), 64)
|
|
|
//cashPools[0].LastRate = lastActivityRate
|
|
|
//cashPools[0].UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].UnExchangeCash), 64)
|
|
|
//cashPools[0].ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedCash), 64)
|
|
|
//cashPools[0].ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", cashPools[0].ExchangedSuMoney), 64)
|
|
|
//cashPools[0].UnExchangeSuMoney, _= strconv.ParseFloat(fmt.Sprintf("%.2f", systemUnExchangeSuMoney), 64)
|
|
|
cashPools[0].Rate, _ = decimal.NewFromFloatWithExponent(cashPools[0].Rate, -2).Float64()
|
|
|
cashPools[0].LastRate, _ = decimal.NewFromFloatWithExponent(lastActivityRate, -2).Float64()
|
|
|
cashPools[0].UnExchangeCash, _ = decimal.NewFromFloatWithExponent(cashPools[0].UnExchangeCash, -2).Float64()
|
|
|
cashPools[0].ExchangedCash, _ = decimal.NewFromFloatWithExponent(cashPools[0].ExchangedCash, -2).Float64()
|
|
|
cashPools[0].ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(cashPools[0].ExchangedSuMoney, -2).Float64()
|
|
|
cashPools[0].UnExchangeSuMoney, _ = decimal.NewFromFloatWithExponent(systemUnExchangeSuMoney, -2).Float64()
|
|
|
return cashPools[0], nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -330,6 +374,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -403,8 +448,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
activity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
//activity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
//activity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
activity.ExchangedCash, _ = decimal.NewFromFloatWithExponent(activity.ExchangedCash, -2).Float64()
|
|
|
activity.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(activity.ExchangedSuMoney, -2).Float64()
|
|
|
return activity, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -414,6 +461,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
if err := listExchangeCashActivityDeadlineQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -465,6 +513,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
if err := activityCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -527,8 +576,10 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
|
|
|
var activitiesFormat []interface{}
|
|
|
for _, activity := range activities {
|
|
|
cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
//cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
//suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
cash, _ := decimal.NewFromFloatWithExponent(activity.ExchangedCash, -2).Float64()
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(activity.ExchangedSuMoney, -2).Float64()
|
|
|
activityFormat := map[string]interface{} {
|
|
|
"activityId": activity.ActivityId,
|
|
|
"exchangeActivityName": activity.ExchangeActivityName,
|
...
|
...
|
@@ -559,6 +610,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -581,7 +633,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
}
|
|
|
|
|
|
// 查找兑换现金活动
|
|
|
if count, activities, err := exchangeActivityRepository.Find(map[string]interface{}{
|
|
|
if count, activitiesFound, err := exchangeActivityRepository.Find(map[string]interface{}{
|
|
|
"companyId": listExchangeCashActivityQuery.CompanyId,
|
|
|
"activityNameMatch": listExchangeCashActivityQuery.ActivityNameMatch,
|
|
|
"offset": listExchangeCashActivityQuery.Offset,
|
...
|
...
|
@@ -591,18 +643,18 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, activity := range activities {
|
|
|
for _, activityFound := range activitiesFound {
|
|
|
var t1 = time.Now().Local()
|
|
|
var t2 = activity.Deadline.Local()
|
|
|
var t2 = activityFound.Deadline.Local()
|
|
|
|
|
|
// 更新兑换现金活动倒计时命令
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
ExchangeCashActivityId: activityFound.ActivityId,
|
|
|
CountDown: int64(math.Ceil(t2.Sub(t1).Hours() / 24)),
|
|
|
Deadline: activity.Deadline.Local(),
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
Deadline: activityFound.Deadline.Local(),
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束处理
|
...
|
...
|
@@ -611,12 +663,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
}
|
|
|
|
|
|
// 更新兑换现金活动倒计时
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存兑换现金活动倒计时更新
|
|
|
_, err := exchangeActivityRepository.Save(activity)
|
|
|
_, err := exchangeActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -628,19 +680,21 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
|
|
|
// 兑换现金活动返回截止时间处理
|
|
|
var activitiesWithTs []interface{}
|
|
|
for _, activity := range activities {
|
|
|
cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
for _, activityFound := range activitiesFound {
|
|
|
//cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedCash), 64)
|
|
|
//suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activityFound.ExchangedSuMoney), 64)
|
|
|
cash, _ := decimal.NewFromFloatWithExponent(activityFound.ExchangedCash, -2).Float64()
|
|
|
suMoney, _ := decimal.NewFromFloatWithExponent(activityFound.ExchangedSuMoney, -2).Float64()
|
|
|
activityWithTs := map[string]interface{} {
|
|
|
"activityId": activity.ActivityId,
|
|
|
"exchangeActivityName": activity.ExchangeActivityName,
|
|
|
"companyId": activity.CompanyId,
|
|
|
"activityId": activityFound.ActivityId,
|
|
|
"exchangeActivityName": activityFound.ExchangeActivityName,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activity.Deadline.Local().UnixNano() / 1e6, // 秒级时间戳转换
|
|
|
"countDown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
|
|
"createTime": activity.CreateTime.Local(),
|
|
|
"deadline": activityFound.Deadline.Local().UnixNano() / 1e6, // 秒级时间戳转换
|
|
|
"countDown": activityFound.CountDown,
|
|
|
"rate": activityFound.Rate,
|
|
|
"createTime": activityFound.CreateTime.Local(),
|
|
|
}
|
|
|
activitiesWithTs = append(activitiesWithTs, activityWithTs)
|
|
|
}
|
...
|
...
|
@@ -661,6 +715,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
|
if err := removeExchangeCashActivityCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -709,6 +764,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
if err := getExchangeCashActivityQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -773,8 +829,10 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
//activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
//activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
activityUpdated.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedSuMoney, -2).Float64()
|
|
|
activityUpdated.ExchangedCash, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedCash, -2).Float64()
|
|
|
activityUpdated.Deadline = activityUpdated.Deadline.Local()
|
|
|
activityUpdated.CreateTime = activityUpdated.CreateTime.Local()
|
|
|
return activityUpdated, nil
|
...
|
...
|
@@ -846,18 +904,17 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney // 当前活动已兑换素币
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash // 当前活动已兑换现金
|
|
|
|
|
|
// 获取当前公司现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPoolsFound) == 0 { // 现金池不存在
|
|
|
if cashPoolFound != nil { // 现金池不存在
|
|
|
var t1 = time.Now().Local()
|
|
|
var t2 = updateExchangeCashActivityCommand.Deadline.Local()
|
|
|
|
...
|
...
|
@@ -896,16 +953,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
//activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
//activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
activityUpdated.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedSuMoney, -2).Float64()
|
|
|
activityUpdated.ExchangedCash, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedCash, -2).Float64()
|
|
|
activityUpdated.Deadline = activityUpdated.Deadline.Local()
|
|
|
activityUpdated.CreateTime = activityUpdated.CreateTime.Local()
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
cashPoolFoundUnExchangeCash := cashPoolFound.UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolFound.ExchangedCash
|
|
|
|
|
|
// 获取当前兑换活动汇率
|
|
|
activityFoundRate := activityFound.Rate
|
...
|
...
|
@@ -929,8 +988,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 更新兑换清单命令
|
|
|
exchangeCash, _ := decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangeRate).Mul(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
|
|
//ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
|
|
ExchangedCash: exchangeCash,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
|
|
}
|
|
|
|
...
|
...
|
@@ -966,28 +1027,33 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
rate = 0
|
|
|
} else {
|
|
|
rate = (cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash)) / systemExchangedSuMoney
|
|
|
//rate = (cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash)) / systemExchangedSuMoney
|
|
|
rate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangedCash).Sub(decimal.NewFromFloat(activityFoundExchangedCash))).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
exchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangedCash).Sub(decimal.NewFromFloat(activityFoundExchangedCash))).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(updateExchangeCashActivityCommand.ExchangedCash).Sub(decimal.NewFromFloat(activityFoundExchangedCash))).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash) ,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashActivityCommand.ExchangedCash - activityFoundExchangedCash),
|
|
|
ExchangedCash: exchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: rate,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1002,7 +1068,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
// 更新兑换活动倒计时
|
|
|
t1 := time.Now().Local()
|
|
|
//var t2 = activityFound.Deadline.Local()
|
|
|
t2 := updateExchangeCashActivityCommand.Deadline.Local()
|
|
|
updateExchangeCashActivityCommand.CountDown = int64(math.Ceil(t2.Sub(t1).Hours() / 24))
|
|
|
|
...
|
...
|
@@ -1046,8 +1111,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
//activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
//activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
activityUpdated.ExchangedSuMoney, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedSuMoney, -2).Float64()
|
|
|
activityUpdated.ExchangedCash, _ = decimal.NewFromFloatWithExponent(activityUpdated.ExchangedCash, -2).Float64()
|
|
|
activityUpdated.Deadline = activityUpdated.Deadline.Local()
|
|
|
activityUpdated.CreateTime = activityUpdated.CreateTime.Local()
|
|
|
return activityUpdated, nil
|
...
|
...
|
@@ -1059,6 +1126,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -1151,13 +1219,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
activityFoundExchangedSuMoney := activityFound.ExchangedSuMoney
|
|
|
activityFoundExchangedCash := activityFound.ExchangedCash
|
|
|
|
|
|
// 获取员工查询条件
|
|
|
// 判断当前员工是否有效
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"account": personFound.EmployeeInfo.EmployeeAccount,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
|
|
|
// 判断当前员工是否有效
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1175,7 +1241,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
//updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
updateExchangeCashPersonCommand.ExchangedCash, _ = decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Mul(decimal.NewFromFloat(activityFound.Rate)).Float64()
|
|
|
|
|
|
// 更新兑换素币清单
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
...
|
...
|
@@ -1189,10 +1256,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
// 更新素币兑换活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Mul(decimal.NewFromFloat(activityFound.Rate)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
ExchangedCash: activityFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
|
|
|
//ExchangedCash: activityFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1209,10 +1280,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
// 判断操作素币类型
|
|
|
if updateExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 追加素币兑换
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
//operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.SuMoney, _ = decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Abs().Float64()
|
|
|
operationSuMoneyCommand.OperationType = 4
|
|
|
} else { // 撤回素币兑换
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
//operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
operationSuMoneyCommand.SuMoney, _ = decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Abs().Float64()
|
|
|
operationSuMoneyCommand.OperationType = 41
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1251,18 +1324,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
cashPoolFound, err := cashPoolRepository.FindOne(map[string]interface{}{
|
|
|
"companyId": activityUpdated.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cashPoolsFound == nil {
|
|
|
if cashPoolFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
cashPoolFoundUnExchangeCash := cashPoolsFound[0].UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolsFound[0].ExchangedCash
|
|
|
cashPoolFoundUnExchangeCash := cashPoolFound.UnExchangeCash
|
|
|
cashPoolFoundExchangedCash := cashPoolFound.ExchangedCash
|
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney > activityFoundExchangedSuMoney {
|
...
|
...
|
@@ -1271,7 +1344,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := cashPoolFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate
|
|
|
//systemExchangedCash := cashPoolFoundExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate
|
|
|
systemExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Mul(decimal.NewFromFloat(activityUpdated.Rate)).Float64()
|
|
|
//systemExchangedSuMoney := cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney)
|
|
|
|
|
|
// 计算现金池平均兑换汇率
|
...
|
...
|
@@ -1279,28 +1353,31 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = systemExchangedCash / systemExchangedSuMoney
|
|
|
//newRate = systemExchangedCash / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(systemExchangedCash).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub((decimal.NewFromFloat(updateExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney))).Mul(decimal.NewFromFloat(activityUpdated.Rate))).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: systemExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityUpdated.Rate,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
LastRate: cashPoolFound.LastRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
if err := cashPoolFound.Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1570,11 +1647,15 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Mul(decimal.NewFromFloat(activityFound.Rate))).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1653,13 +1734,18 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
//newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -1701,15 +1787,22 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
personFoundExchangedCash := personFound.ExchangedCash // 当前素币清单已兑换现金
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
|
|
|
// 素币减量
|
|
|
suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
|
|
|
//suMoneyDecrement := personFoundExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
|
|
|
suMoneyDecrement, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Sub(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
|
|
|
// 现金减量
|
|
|
cashDecrement := suMoneyDecrement * activityFound.Rate
|
|
|
//cashDecrement := suMoneyDecrement * activityFound.Rate
|
|
|
cashDecrement, _ := decimal.NewFromFloat(suMoneyDecrement).Mul(decimal.NewFromFloat(activityFound.Rate)).Float64()
|
|
|
|
|
|
// 更新兑换素币清单
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Sub(decimal.NewFromFloat(suMoneyDecrement)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(personFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
|
|
|
ListId: personFound.ListId,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
ExchangedCash: personFoundExchangedCash - cashDecrement,
|
|
|
//ExchangedSuMoney: personFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
//ExchangedCash: personFoundExchangedCash - cashDecrement,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
}
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
...
|
...
|
@@ -1745,10 +1838,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 更新素币兑换活动
|
|
|
newExchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Sub(decimal.NewFromFloat(suMoneyDecrement)).Float64()
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
ExchangedCash: activityFoundExchangedCash - cashDecrement,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney - suMoneyDecrement,
|
|
|
//ExchangedCash: activityFoundExchangedCash - cashDecrement,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -1845,13 +1942,18 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolFoundExchangedCash - cashDecrement) / systemExchangedSuMoney
|
|
|
//newRate = (cashPoolFoundExchangedCash - cashDecrement) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
cashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Add(decimal.NewFromFloat(cashDecrement)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash - cashDecrement,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash - cashDecrement,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash + cashDecrement,
|
|
|
ExchangedCash: cashPoolExchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -1890,9 +1992,11 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
} else { // 当前兑换素币大于等于已兑换素币,追加兑换素币
|
|
|
// 素币增量
|
|
|
suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
|
|
|
//suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
|
|
|
suMoneyIncrement, _ := decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
|
|
// 现金增量
|
|
|
cashIncrement := suMoneyIncrement * activityFound.Rate
|
|
|
//cashIncrement := suMoneyIncrement * activityFound.Rate
|
|
|
cashIncrement, _ := decimal.NewFromFloat(suMoneyIncrement).Mul(decimal.NewFromFloat(activityFound.Rate)).Float64()
|
|
|
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if suMoneyIncrement > employeeFoundSuMoney {
|
...
|
...
|
@@ -1907,10 +2011,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 更新兑换素币清单
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(personFoundExchangedSuMoney).Add(decimal.NewFromFloat(suMoneyIncrement)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(personFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
updateExchangeCashPersonCommand := &command.UpdateExchangeCashPersonCommand{
|
|
|
ListId: personFound.ListId,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
ExchangedCash: personFoundExchangedCash + cashIncrement,
|
|
|
//ExchangedSuMoney: personFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
//ExchangedCash: personFoundExchangedCash + cashIncrement,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
}
|
|
|
if err := personFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
...
|
...
|
@@ -1946,10 +2054,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
newExchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(suMoneyIncrement)).Float64()
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
ExchangedCash: activityFoundExchangedCash + cashIncrement,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + suMoneyIncrement,
|
|
|
//ExchangedCash: activityFoundExchangedCash + cashIncrement,
|
|
|
ExchangedSuMoney: newExchangedSuMoney,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2058,13 +2170,18 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolFoundExchangedCash + cashIncrement) / systemExchangedSuMoney
|
|
|
//newRate = (cashPoolFoundExchangedCash + cashIncrement) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
newCashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(cashIncrement)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolFound.CashPoolId,
|
|
|
Cash: cashPoolFound.Cash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + cashIncrement,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + cashIncrement,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - cashIncrement,
|
|
|
ExchangedCash: newCashPoolExchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -2269,11 +2386,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Add(decimal.NewFromFloat(createExchangeCashPersonCommand.ExchangedSuMoney)).Mul(decimal.NewFromFloat(activityFound.Rate)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2327,15 +2448,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
//newRate = (cashPoolFoundExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
newCashPoolExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Add(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
unExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Sub(decimal.NewFromFloat(personSaved.ExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash + personSaved.ExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedCash: newCashPoolExchangedCash,
|
|
|
UnExchangeCash: unExchangeCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
...
|
...
|
@@ -2606,10 +2732,14 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
}
|
|
|
|
|
|
// 更新兑换素币活动命令
|
|
|
exchangedSuMoney, _ := decimal.NewFromFloat(activityFoundExchangedSuMoney).Sub(decimal.NewFromFloat(personFoundExchangedSuMoney)).Float64()
|
|
|
exchangedCash, _ := decimal.NewFromFloat(activityFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personFound.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFoundExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
ExchangedCash: activityFoundExchangedCash - personFoundExchangedCash,
|
|
|
//ExchangedSuMoney: activityFoundExchangedSuMoney - personFoundExchangedSuMoney,
|
|
|
//ExchangedCash: activityFoundExchangedCash - personFoundExchangedCash,
|
|
|
ExchangedSuMoney: exchangedSuMoney,
|
|
|
ExchangedCash: exchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
...
|
...
|
@@ -2677,16 +2807,21 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolFoundExchangedCash - personFoundExchangedCash) / systemExchangedSuMoney
|
|
|
//newRate = (cashPoolFoundExchangedCash - personFoundExchangedCash) / systemExchangedSuMoney
|
|
|
newRate, _ = decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Div(decimal.NewFromFloat(systemExchangedSuMoney)).Float64()
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
newExchangedCash, _ := decimal.NewFromFloat(cashPoolFoundExchangedCash).Sub(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
UnExchangeCash, _ := decimal.NewFromFloat(cashPoolFoundUnExchangeCash).Add(decimal.NewFromFloat(personFoundExchangedCash)).Float64()
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
ExchangedCash: cashPoolFoundExchangedCash - personFoundExchangedCash,
|
|
|
UnExchangeCash: cashPoolFoundUnExchangeCash + personFoundExchangedCash,
|
|
|
//ExchangedCash: cashPoolFoundExchangedCash - personFoundExchangedCash,
|
|
|
//UnExchangeCash: cashPoolFoundUnExchangeCash + personFoundExchangedCash,
|
|
|
ExchangedCash: newExchangedCash,
|
|
|
UnExchangeCash: UnExchangeCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
...
|
...
|
|