...
|
...
|
@@ -498,8 +498,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
"companyId": activity.CompanyId,
|
|
|
"exchangedCash": activity.ExchangedCash,
|
|
|
"exchangedSuMoney": activity.ExchangedSuMoney,
|
|
|
"deadline": activity.Deadline.Unix(),
|
|
|
"countDown": activity.CountDown,
|
|
|
"deadline": activity.Deadline.UnixNano() / 1e6,
|
|
|
"countdown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
|
|
"createTime": "2020-11-13T09:32:45.259856Z",
|
|
|
}
|
...
|
...
|
@@ -1231,9 +1231,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 移除兑换素币清单
|
|
|
func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
// 更新兑换清单
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -1247,7 +1247,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 移除兑换素币清单
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1257,13 +1256,13 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取待删除人员
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
|
|
// 获取兑换清单
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
...
|
...
|
@@ -1286,27 +1285,26 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
|
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 还原个人素币值,生成素币流水,描述修改成和活动相关
|
|
|
// 更新员工素币,生成素币兑换流水记录
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1316,14 +1314,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 1, // 增加素币
|
|
|
Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: 0,
|
|
|
OperationType: 0,
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
|
|
}
|
|
|
|
|
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 1
|
|
|
} else {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 3
|
|
|
}
|
|
|
|
|
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1332,7 +1338,40 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
// 统计活动已兑换素币
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activitySuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
}
|
|
|
|
|
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
|
|
|
// 统计平台现金兑换情况
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1342,7 +1381,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1351,8 +1389,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 重新获取系统现金兑换情况
|
|
|
newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
...
|
...
|
@@ -1396,13 +1448,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
|
|
fmt.Print(updateCashPoolCommand.ExchangedCash, "\n")
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
...
|
...
|
@@ -1416,20 +1470,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personDeleted, nil
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
|
|
|
// 更新兑换清单
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
// 移除兑换素币清单
|
|
|
func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -1443,6 +1492,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 移除兑换素币清单
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1452,13 +1502,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取兑换清单
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
|
|
|
// 获取待删除人员
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if person == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
...
|
...
|
@@ -1481,26 +1531,27 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
|
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 更新员工素币,生成素币兑换流水记录
|
|
|
// 还原个人素币值,生成素币流水,描述修改成和活动相关
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1510,22 +1561,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: 0,
|
|
|
OperationType: 0,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 1, // 增加素币
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
|
|
}
|
|
|
|
|
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 1
|
|
|
} else {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 3
|
|
|
}
|
|
|
|
|
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1534,40 +1577,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
var cashPoolDao *dao.CashPoolDao
|
|
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolDao = value
|
|
|
}
|
|
|
|
|
|
// 统计活动已兑换素币
|
|
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activitySuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
}
|
|
|
|
|
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
|
|
|
// 统计平台现金兑换情况
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -1577,6 +1587,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1585,22 +1596,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
// 判断是否超过平台未兑换现金
|
|
|
if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 重新获取系统现金兑换情况
|
|
|
newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
...
|
...
|
@@ -1644,10 +1641,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1664,10 +1661,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personDeleted, nil
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
|
|
|
// 根据id获取兑换清单
|
...
|
...
|
|