|
@@ -2,13 +2,14 @@ package service |
|
@@ -2,13 +2,14 @@ package service |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
5
|
- "github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
6
|
- "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
|
|
|
7
|
- "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
|
|
8
|
"math"
|
5
|
"math"
|
9
|
"strconv"
|
6
|
"strconv"
|
10
|
"time"
|
7
|
"time"
|
11
|
|
8
|
|
|
|
9
|
+ "github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
|
|
|
12
|
+
|
12
|
"github.com/linmadan/egglib-go/core/application"
|
13
|
"github.com/linmadan/egglib-go/core/application"
|
13
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
14
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
14
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
|
15
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
|
|
@@ -480,8 +481,34 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -480,8 +481,34 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
480
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
481
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
481
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
482
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
482
|
}
|
483
|
}
|
483
|
- // TODO 批量更新兑换清单中已兑换现金值
|
|
|
484
|
-
|
484
|
+ // 批量更新兑换清单中已兑换现金值
|
|
|
485
|
+ // 获取兑换清单列表
|
|
|
486
|
+ var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
487
|
+ if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
488
|
+ "transactionContext": transactionContext,
|
|
|
489
|
+ }); err != nil {
|
|
|
490
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
491
|
+ } else {
|
|
|
492
|
+ exchangeCashPersonListRepository = value
|
|
|
493
|
+ }
|
|
|
494
|
+ _, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
495
|
+ "exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
|
|
|
496
|
+ });
|
|
|
497
|
+ if err != nil {
|
|
|
498
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
499
|
+ }
|
|
|
500
|
+ // 更新兑换清单,更新已兑换现金值
|
|
|
501
|
+ for _, person := range people {
|
|
|
502
|
+ updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
503
|
+ ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * person.ExchangedSuMoney,
|
|
|
504
|
+ }
|
|
|
505
|
+ if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
|
|
|
506
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
507
|
+ }
|
|
|
508
|
+ if _, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
|
|
509
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
510
|
+ }
|
|
|
511
|
+ }
|
485
|
// 计算系统平均兑换汇率并更新现金池
|
512
|
// 计算系统平均兑换汇率并更新现金池
|
486
|
var employeeDao *dao.EmployeeDao
|
513
|
var employeeDao *dao.EmployeeDao
|
487
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
514
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -491,6 +518,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -491,6 +518,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
491
|
} else {
|
518
|
} else {
|
492
|
employeeDao = value
|
519
|
employeeDao = value
|
493
|
}
|
520
|
}
|
|
|
521
|
+ // 获取平台素币状况
|
494
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
522
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
495
|
if err != nil {
|
523
|
if err != nil {
|
496
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
524
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -499,6 +527,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -499,6 +527,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
499
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
527
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
500
|
}
|
528
|
}
|
501
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
529
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
530
|
+ // 获取平台现金状况
|
502
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
|
531
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
|
503
|
if err != nil {
|
532
|
if err != nil {
|
504
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
533
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1190,6 +1219,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1190,6 +1219,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1190
|
if cashPoolUpdated == nil {
|
1219
|
if cashPoolUpdated == nil {
|
1191
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1220
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1192
|
}
|
1221
|
}
|
|
|
1222
|
+
|
1193
|
if personUpdated, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
1223
|
if personUpdated, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
1194
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1224
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1195
|
} else {
|
1225
|
} else {
|