...
|
...
|
@@ -284,7 +284,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
|
|
ExchangedCash: 0,
|
|
|
ExchangedSuMoney: 0,
|
|
|
//Deadline: time.Date(deadline.Year(), deadline.Month(), deadline.Day(), deadline.Hour(), deadline.Minute(), deadline.Second(), 0, time.Local),
|
|
|
Deadline: t2,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算活动截止倒计时
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
...
|
...
|
@@ -398,6 +397,9 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
...
|
...
|
@@ -463,6 +465,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
...
|
...
|
@@ -594,6 +599,9 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Deadline: activity.Deadline,
|
|
|
ExchangedSuMoney: activity.ExchangedSuMoney,
|
|
|
ExchangedCash: activity.ExchangedCash,
|
|
|
ExchangeRate: activity.Rate,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
...
|
...
|
@@ -796,6 +804,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
// 更新兑换活动已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activity.ExchangedSuMoney
|
|
|
} else {
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = activity.ExchangedCash
|
|
|
}
|
|
|
|
|
|
var timeNow = time.Now()
|
...
|
...
|
@@ -805,13 +815,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
|
|
|
// 计算倒计时
|
|
|
updateExchangeCashActivityCommand.CountDown = int64(t2.Sub(t1).Hours() / 24)
|
|
|
//updateExchangeCashActivityCommand.Deadline = deadline
|
|
|
|
|
|
// 倒计时结束
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivityCommand.CountDown = 0
|
|
|
updateExchangeCashActivityCommand.Deadline = activity.Deadline
|
|
|
}
|
|
|
|
|
|
updateExchangeCashActivityCommand.ExchangedSuMoney = activity.ExchangedSuMoney
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -858,6 +870,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
fmt.Print(activity.Rate, "\n")
|
|
|
|
|
|
rate := activity.Rate
|
|
|
|
|
|
// 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
|
...
|
...
|
@@ -870,6 +884,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 判断是excel导入还是页面增加
|
|
|
getEmployee := map[string]interface{}{}
|
|
|
if createExchangeCashPersonCommand.PersonAccount == "" {
|
|
|
getEmployee = map[string]interface{}{
|
...
|
...
|
@@ -937,8 +952,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
OperationDescription: "素币兑换现金",
|
|
|
}
|
|
|
|
|
|
fmt.Print(operationSuMoneyCommand, "\n")
|
|
|
|
|
|
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())
|
...
|
...
|
@@ -967,7 +980,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
|
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
...
|
...
|
@@ -1023,12 +1039,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 判断兑换的现金是否超过现金池未兑换现金
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemUnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 获取平台素币状况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
...
|
...
|
@@ -1040,6 +1051,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
...
|
...
|
@@ -1061,6 +1073,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 判断兑换的现金是否超过现金池未兑换现金
|
|
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var newRate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
...
|
...
|
@@ -1071,8 +1088,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: systemUnExchangeCash,
|
|
|
UnExchangeCash: systemUnExchangeCash,
|
|
|
ExchangedCash: cashPools[0].ExchangedCash + person.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeCash: cashPools[0].UnExchangeCash - person.ExchangedCash,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1270,7 +1289,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
|
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
...
|
...
|
@@ -1300,12 +1322,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 1,
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "现金调整",
|
|
|
OperationType: 1, // 增加素币
|
|
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
|
|
}
|
|
|
|
|
|
fmt.Print(removeExchangeCashPersonCommand.Operator, "\n")
|
|
|
|
|
|
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())
|
...
|
...
|
@@ -1346,6 +1366,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
...
|
...
|
@@ -1377,9 +1398,11 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPools[0].CashPoolId,
|
|
|
ExchangedCash: systemUnExchangeCash,
|
|
|
UnExchangeCash: systemUnExchangeCash,
|
|
|
ExchangedCash: systemExchangedCash - person.ExchangedCash,
|
|
|
UnExchangeCash: systemUnExchangeCash + person.ExchangedCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -1402,14 +1425,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return personDeleted, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 更新兑换清单
|
|
|
func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
fmt.Print(updateExchangeCashPersonCommand, "\n")
|
|
|
if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1463,6 +1484,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
// 更新兑换清单,个人已兑换现金计算
|
|
|
updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
|
|
|
fmt.Print(updateExchangeCashPersonCommand.ExchangedCash, "\n")
|
|
|
|
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -1471,6 +1494,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
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,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
...
|
...
|
@@ -1533,7 +1559,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
|
|
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 5
|
|
|
operationSuMoneyCommand.OperationType = 1
|
|
|
} else {
|
|
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
operationSuMoneyCommand.OperationType = 3
|
...
|
...
|
@@ -1579,6 +1605,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
...
|
...
|
@@ -1613,6 +1640,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
ExchangedCash: systemUnExchangeCash,
|
|
|
UnExchangeCash: systemUnExchangeCash,
|
|
|
Rate: newRate,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
...
|
...
|
@@ -1634,7 +1663,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
|