...
|
...
|
@@ -34,7 +34,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -43,7 +42,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 统计系统素币
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -52,7 +50,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
// 统计系统现金
|
|
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -61,7 +60,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
if systemCashStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -70,15 +70,8 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
|
} else {
|
|
|
cashPoolRepository = value
|
|
|
}
|
|
|
|
|
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
// TODO 计算系统平均兑换汇率
|
|
|
// 计算系统平均兑换汇率
|
|
|
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
|
|
|
|
|
|
// 新建现金池
|
|
|
newCashPool := &domain.CashPool{
|
|
|
CompanyId: createCashPoolCommand.CompanyId,
|
...
|
...
|
@@ -122,7 +115,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 统计系统素币
|
|
|
var employeeDao *dao.EmployeeDao
|
|
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -131,8 +124,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
} else {
|
|
|
employeeDao = value
|
|
|
}
|
|
|
|
|
|
// 统计系统素币
|
|
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -140,10 +131,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
if systemSuMoneyStatistics == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
}
|
|
|
|
|
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
|
|
|
var cashPoolRepository domain.CashPoolRepository
|
|
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -158,7 +147,6 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// 初始状态下,现金池返回默认值
|
|
|
if count == 0 {
|
|
|
return map[string] interface{} {
|
|
|
"cashPoolId": 0,
|
...
|
...
|
@@ -192,12 +180,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = createExchangeCashActivityCommand.Deadline
|
|
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
|
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
...
|
...
|
@@ -208,7 +194,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
CreateTime: timeNow,
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -217,7 +202,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
} else {
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -233,7 +217,6 @@ 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())
|
...
|
...
|
@@ -244,7 +227,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -253,7 +235,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
} else {
|
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -360,7 +341,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// TODO 更新汇率处理:
|
|
|
// TODO 更新汇率判断
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
...
|
...
|
@@ -380,25 +361,20 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
|
|
activityUpdated, err := exchangeCashActivityRepository.Save(activity)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
|
|
|
}
|
|
|
|
|
|
//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
|
|
|
//}
|
|
|
// TODO 更新现金池
|
|
|
// 获取现金池
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activityUpdated, nil
|
|
|
// 更新现金池
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
|
|
|
// 新增兑换素币清单
|
...
|
...
|
@@ -416,58 +392,121 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// TODO 获取兑换活动兑换汇率
|
|
|
|
|
|
//var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
//activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
//if err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
//if activity == nil {
|
|
|
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))
|
|
|
//} else {
|
|
|
// fmt.Print(activity.Rate)
|
|
|
//}
|
|
|
|
|
|
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
|
|
|
|
|
|
// TODO 新增兑换清单时,根据uid判断成员是否存在,判断素币值是否超过本人持有的素币
|
|
|
|
|
|
// TODO 导入兑换清单时,时根据手机账号判断成员是否存在,判断素币是否超过本人持有的素币
|
|
|
|
|
|
// 获取兑换活动兑换汇率
|
|
|
var rate float64
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity != nil {
|
|
|
rate = activity.Rate
|
|
|
}
|
|
|
// 根据uid/手机账号判断成员是否存在
|
|
|
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
|
|
|
}
|
|
|
employee, err := employeeRepository.FindOne(map[string]interface{}{
|
|
|
"uid": createExchangeCashPersonCommand.Uid,
|
|
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if employee == nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
|
|
}
|
|
|
if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
|
|
}
|
|
|
// 新增兑换清单
|
|
|
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
|
|
|
}
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
|
|
EmployeeName: createExchangeCashPersonCommand.PersonName,
|
|
|
EmployeeAccount: createExchangeCashPersonCommand.PersonAccount,
|
|
|
Uid: employee.EmployeeInfo.Uid,
|
|
|
EmployeeName: employee.EmployeeInfo.EmployeeName,
|
|
|
EmployeeAccount: employee.EmployeeInfo.EmployeeAccount,
|
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
|
|
|
}
|
|
|
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
person, err := exchangeCashPersonListRepository.Save(newPerson)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
// 生成素币流水,更新个人素币
|
|
|
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 {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 3,
|
|
|
OperationDescription: "素币兑换现金",
|
|
|
}
|
|
|
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)))
|
|
|
}
|
|
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
|
|
// 更新兑换活动
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
// TODO 更新个人素币
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
createExchangeCashPersonCommand.ExchangedSuMoney += activityFound.ExchangedSuMoney
|
|
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(createExchangeCashPersonCommand)); 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)))
|
|
|
}
|
|
|
|
|
|
// TODO 更新活动数据
|
|
|
// TODO 判断清单中现金总额超过现金池未兑换现金时创建失败,提示:“已超过投入现金池的未兑换现金”
|
|
|
|
|
|
// TODO 更新现金池数据
|
|
|
// TODO 更新现金池
|
|
|
// 获取现金池
|
|
|
// 更新现金池
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return person, nil
|
|
|
}
|
|
|
|
|
|
// 返回兑换素币清单
|
...
|
...
|
@@ -558,6 +597,27 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
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
|
|
|
}
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": 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(removeExchangeCashPersonCommand.ListId)))
|
|
|
}
|
|
|
// 移除兑换素币清单
|
|
|
personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
// 生成素币流水,更新个人素币
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -566,52 +626,62 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: person.ExchangedSuMoney,
|
|
|
OperationType: 1,
|
|
|
OperationDescription: "素币兑换现金调整",
|
|
|
}
|
|
|
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)))
|
|
|
}
|
|
|
// 更新兑换活动
|
|
|
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 {
|
|
|
exchangeCashPersonListRepository = value
|
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
|
|
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
|
|
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)))
|
|
|
if activityFound == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
|
|
}
|
|
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
|
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
|
|
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
|
|
}
|
|
|
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
|
|
|
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())
|
|
|
} else {
|
|
|
// TODO 更新个人素币,个人素币值需要还原,理由:素币兑换现金调整
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: 0,
|
|
|
OperationType: 5,
|
|
|
OperationDescription: "素币兑换现金调整",
|
|
|
}
|
|
|
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)))
|
|
|
}
|
|
|
}
|
|
|
if activityUpdated == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
|
|
|
// TODO 更新兑换活动数据
|
|
|
// TODO 更新现金池
|
|
|
|
|
|
// TODO 更新现金池数据
|
|
|
|
|
|
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 personDeleted, 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())
|
...
|
...
|
@@ -626,6 +696,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// 更新兑换清单
|
|
|
var operationSuMoneyService service.OperationSuMoneyService
|
|
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -634,7 +705,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
} else {
|
|
|
operationSuMoneyService = value
|
|
|
}
|
|
|
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
|
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -653,34 +723,38 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if personUpdated, err := exchangeCashPersonListRepository.Save(person); err != nil {
|
|
|
personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 5,
|
|
|
OperationDescription: "参与兑换素币活动",
|
|
|
}
|
|
|
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
|
|
|
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)))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 更新兑换活动数据
|
|
|
// TODO 更新兑换活动
|
|
|
|
|
|
// TODO 更新现金池
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
// TODO 判断现金池未兑换现金
|
|
|
|
|
|
|
|
|
// TODO 更新现金池
|
|
|
|
|
|
// 生成素币兑换流水记录,更新员工素币
|
|
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
Uid: person.EmployeeInfo.Uid,
|
|
|
Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
SuMoney: updateExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
OperationType: 3,
|
|
|
OperationDescription: "参与兑换素币活动",
|
|
|
}
|
|
|
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)))
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
|
|
|
func NewCashPoolService(options map[string]interface{}) *CashPoolService {
|
...
|
...
|
|