...
|
...
|
@@ -156,15 +156,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
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,
|
|
|
ExchangedCash: 0,
|
|
|
ExchangedSuMoney: 0,
|
|
|
Deadline: createExchangeCashActivityCommand.Deadline,
|
|
|
CountDown: 0,
|
|
|
Deadline: createExchangeCashActivityCommand.Deadline,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
CreateTime: time.Now(),
|
|
|
CreateTime: timeNow,
|
|
|
}
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
...
|
...
|
@@ -273,7 +278,6 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
if err := getExchangeCashActivityQuery.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())
|
...
|
...
|
@@ -284,7 +288,6 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -340,25 +343,32 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
if activity == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
}
|
|
|
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 {
|
|
|
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
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// TODO 更新现金池已兑换素币、已兑换现金值、未兑换素币、未兑换现金值、平均汇率
|
|
|
|
|
|
return activityUpdated, 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())
|
...
|
...
|
@@ -375,15 +385,20 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// TODO 需要判断新增兑换现金人员的素币值是否合理(人员参与兑换的素币不得超过该人员还未兑换的素币总值)
|
|
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if activity.Rate == 0 {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string("请设置汇率")))
|
|
|
}
|
|
|
|
|
|
// TODO 判断活动的汇率是否为空,为空则不允许新建,提示:请设置汇率
|
|
|
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
|
|
|
|
|
|
// TODO 获取参与的兑换活动的汇率,计算已兑换的现金值
|
|
|
|
|
|
// TODO 清单中现金总额超过现金池时创建失败,提示:“已超过投入现金池的未兑换现金”
|
|
|
// TODO 新增兑换人员时,判断成员是否存在,判断素币值是否超过本人持有的素币,以手机账号为判断依据
|
|
|
|
|
|
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
|
|
|
|
|
|
newPerson := &domain.ExchangeCashPersonList{
|
|
|
EmployeeInfo: &domain.EmployeeInfo{
|
...
|
...
|
@@ -392,7 +407,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
},
|
|
|
ExchangeCashActivityId: createExchangeCashPersonCommand.ExchangeCashActivityId,
|
|
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
|
|
|
|
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * activity.Rate,
|
|
|
}
|
|
|
|
|
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
...
|
...
|
@@ -406,11 +421,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
// TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
|
|
|
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// TODO 更新活动已兑换素币值、已兑换现金值、兑换汇率
|
|
|
|
|
|
return person, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -572,13 +588,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
|
if personUpdated, err := exchangeCashPersonListRepository.Save(person); 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())
|
|
|
}
|
|
|
// TODO 更新个人当前可用素币值,生成素币兑换流水记录(获取更新前的已兑换素币值,判断是扣除还是增加),记录描述:参与素币兑换现金活动(红色表示取活动名称)
|
|
|
|
|
|
|
|
|
// TODO 更新相应兑换活动已兑换素币值、已兑换现金值、兑换汇率
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return personUpdated, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
|