...
|
...
|
@@ -723,16 +723,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
// 现金池DAO初始化
|
|
|
//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
|
|
|
//}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
...
|
...
|
@@ -764,16 +754,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
|
|
}
|
|
|
|
|
|
// 获取活动素币统计
|
|
|
//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)
|
|
|
|
|
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
|
|
if activityFound.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
...
|
...
|
@@ -792,7 +772,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
personFoundExchangedSuMoney := personFound.ExchangedSuMoney
|
|
|
|
|
|
// 更新兑换清单命令
|
|
|
//updateExchangeCashActivityExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney), 64)
|
|
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
|
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * personFoundExchangedSuMoney,
|
|
|
ExchangedSuMoney: personFoundExchangedSuMoney,
|
...
|
...
|
@@ -820,17 +799,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// 获取平台现金状况
|
|
|
//systemCashStatistics, 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 := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 更新兑换活动命令已兑换现金
|
|
|
updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activityFound.ExchangedSuMoney
|
|
|
|
...
|
...
|
@@ -899,8 +867,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 新增兑换素币清单
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
// 新增导入兑换素币清单
|
|
|
func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
@@ -955,16 +923,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
//// 现金池DAO初始化
|
|
|
//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
|
|
|
//}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
...
|
...
|
@@ -991,19 +949,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 判断导入方式,页面/Excel
|
|
|
getEmployee := map[string]interface{}{}
|
|
|
if createExchangeCashPersonCommand.PersonAccount == "" {
|
|
|
getEmployee = map[string]interface{}{
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
} else {
|
|
|
getEmployee = map[string]interface{}{
|
|
|
// 获取员工查询条件
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 判断当前员工是否有效
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
...
|
...
|
@@ -1020,19 +970,164 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
}
|
|
|
|
|
|
// 判断当前员工是否已经在素币兑换清单中
|
|
|
count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
"uid": employeeFound.EmployeeInfo.Uid,
|
|
|
count, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
"employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
"exchangeCashActivityId": activityFound.ActivityId,
|
|
|
"offset": 0,
|
|
|
"limit": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if count > 0 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
|
|
|
|
|
|
// 更新兑换素币清单命令
|
|
|
updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{
|
|
|
ListId: peopleFound[0].ListId,
|
|
|
ExchangedSuMoney: peopleFound[0].ExchangedSuMoney,
|
|
|
ExchangedCash: peopleFound[0].ExchangedCash,
|
|
|
}
|
|
|
|
|
|
if count > 0 { // 追加素币兑换或撤回素币兑换
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 4,
|
|
|
OperationDescription: "素币兑换现金",
|
|
|
}
|
|
|
if createExchangeCashPersonCommand.ExchangedSuMoney < peopleFound[0].ExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
|
|
|
//suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney // 减量
|
|
|
// 更新兑换素币清单命令
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand.OperationType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE
|
|
|
operationSuMoneyCommand.OperationDescription = ""
|
|
|
|
|
|
} else if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFound[0].ExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
|
|
|
//suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney // 增量
|
|
|
// 更新兑换素币清单命令
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand.OperationType = domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH
|
|
|
operationSuMoneyCommand.OperationDescription = ""
|
|
|
|
|
|
|
|
|
}
|
|
|
// 更新兑换素币清单
|
|
|
if err := peopleFound[0].Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存兑换素币清单更新
|
|
|
personUpdated, err := exchangeCashPersonListRepository.Save(peopleFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
|
|
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())
|
|
|
}
|
|
|
if task == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personUpdated.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
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(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPoolsFound) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
|
|
|
}
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 获取平台素币兑换情况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var newRate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personUpdated.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cashPoolUpdated == nil {
|
|
|
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())
|
|
|
}
|
|
|
return nil, nil
|
|
|
} else if count == 0 { // 新增
|
|
|
// 新增兑换清单命令
|
|
|
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
|
|
|
// 新增兑换素币清单命令
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
...
|
...
|
@@ -1056,7 +1151,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 4,
|
|
|
OperationDescription: "参与" + activityFound.ExchangeActivityName,
|
|
|
OperationDescription: "素币兑换现金",
|
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
...
|
...
|
@@ -1093,16 +1188,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 获取兑换活动素币兑换情况
|
|
|
//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)
|
|
|
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
...
|
...
|
@@ -1119,16 +1204,277 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 获取平台现金兑换情况
|
|
|
//systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
//if err != nil {
|
|
|
// 获取平台素币兑换情况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// 计算平均兑换汇率
|
|
|
var newRate float64
|
|
|
if systemExchangedSuMoney == 0 {
|
|
|
newRate = 0
|
|
|
} else {
|
|
|
newRate = (cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash) / systemExchangedSuMoney
|
|
|
}
|
|
|
|
|
|
// 更新现金池命令
|
|
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
|
|
CashPoolId: cashPoolsFound[0].CashPoolId,
|
|
|
Cash: cashPoolsFound[0].Cash,
|
|
|
ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
|
|
|
UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
|
|
|
ExchangedSuMoney: systemExchangedSuMoney,
|
|
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
|
|
Rate: newRate,
|
|
|
LastRate: cashPoolsFound[0].LastRate,
|
|
|
}
|
|
|
|
|
|
// 更新现金池
|
|
|
if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 保存现金池更新
|
|
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPoolsFound[0])
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cashPoolUpdated == nil {
|
|
|
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())
|
|
|
}
|
|
|
return personSaved, nil
|
|
|
}
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 新增兑换素币清单
|
|
|
func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
if err := createExchangeCashPersonCommand.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())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 兑换活动仓储初始化
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 兑换素币清单仓储初始化
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
}
|
|
|
|
|
|
// 现金池仓储初始化
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
// 员工仓储初始化
|
|
|
var employeeRepository domain.EmployeeRepository
|
|
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeRepository = value
|
|
|
}
|
|
|
|
|
|
// 员工DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 操作素币服务初始化
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
// 获取当前兑换清单兑换活动
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
getEmployee := map[string]interface{}{
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
}
|
|
|
|
|
|
// 判断当前员工是否有效
|
|
|
employeeFound, err := employeeRepository.FindOne(getEmployee)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employeeFound == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
}
|
|
|
|
|
|
// 判断该员工兑换的素币是否超过本人持有的素币
|
|
|
if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
}
|
|
|
|
|
|
//// 判断当前员工是否已经在素币兑换清单中,区分excel导入新增和页面添加新增
|
|
|
//if !createFlag { // 页面新增
|
|
|
// count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
// "uid": employeeFound.EmployeeInfo.Uid,
|
|
|
// "exchangeCashActivityId": activityFound.ActivityId,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// if count > 0 { // 已存在兑换素币清单
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
|
|
|
// }
|
|
|
// if count == 0 { // 未存在,新增兑换素币清单
|
|
|
//
|
|
|
// }
|
|
|
//} else { // 导入新增
|
|
|
// count, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
|
|
// "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
// "exchangeCashActivityId": activityFound.ActivityId,
|
|
|
// "offset": 0,
|
|
|
// "limit": 1,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// if count > 0 { // 追加素币兑换或撤回素币兑换
|
|
|
// if createExchangeCashPersonCommand.ExchangedSuMoney < peopleFound[0].ExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
|
|
|
// suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney // 减量
|
|
|
//
|
|
|
// } else if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFound[0].ExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
|
|
|
// suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney // 增量
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
// if count == 0 { // 新增
|
|
|
//
|
|
|
// }
|
|
|
//}
|
|
|
//if systemCashStatistics == nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
//}
|
|
|
//systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
//systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
|
|
|
// 新增兑换清单命令
|
|
|
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
|
|
|
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
EmployeeName: employeeFound.EmployeeInfo.EmployeeName,
|
|
|
EmployeeAccount: employeeFound.EmployeeInfo.EmployeeAccount,
|
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: newPersonExchangedCash,
|
|
|
}
|
|
|
|
|
|
// 保存兑换素币清单
|
|
|
personSaved, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 操作素币命令
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: employeeFound.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 4,
|
|
|
OperationDescription: "参与" + activityFound.ExchangeActivityName,
|
|
|
}
|
|
|
|
|
|
// 操作素币,生成素币流水
|
|
|
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())
|
|
|
}
|
|
|
if task == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动命令
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
|
|
|
ExchangeActivityName: activityFound.ExchangeActivityName,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
|
|
|
Deadline: activityFound.Deadline,
|
|
|
CountDown: activityFound.CountDown,
|
|
|
ExchangeRate: activityFound.Rate,
|
|
|
}
|
|
|
|
|
|
// 更新兑换活动
|
|
|
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(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// 获取当前现金池
|
|
|
_, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
"companyId": activityFound.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(cashPoolsFound) == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
|
|
|
}
|
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 获取平台素币兑换情况
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
...
|
...
|
@@ -1360,16 +1706,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
//// 现金池DAO初始化
|
|
|
//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
|
|
|
//}
|
|
|
|
|
|
// 用户DAO初始化
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
...
|
...
|
|