...
|
...
|
@@ -302,12 +302,36 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
exchangeCashActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 兑换现金活动仓储初始化
|
|
|
var exchangeActivityRepository 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 {
|
|
|
exchangeActivityRepository = value
|
|
|
}
|
|
|
|
|
|
// 时间格式化
|
|
|
dd, _ := time.ParseDuration("24h")
|
|
|
var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
|
|
|
//dd, _ := time.ParseDuration("24h")
|
|
|
//var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
|
|
|
var deadline = createExchangeCashActivityCommand.Deadline
|
|
|
var t1 = time.Now()
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
|
|
|
|
|
|
// 获取该公司所有兑换现金活动
|
|
|
if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
|
|
|
"companyId": createExchangeCashActivityCommand.CompanyId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, activity := range activities {
|
|
|
if t2.Equal(activity.Deadline) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 创建兑换活动命令
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
...
|
...
|
@@ -332,6 +356,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
activity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
return activity, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -454,12 +480,14 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma |
|
|
|
|
|
var activitiesFormat []interface{}
|
|
|
for _, activity := range activities {
|
|
|
cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
|
|
|
suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
|
|
|
activityFormat := map[string]interface{} {
|
|
|
"activityId": activity.ActivityId,
|
|
|
"exchangeActivityName": activity.ExchangeActivityName,
|
|
|
"companyId": activity.CompanyId,
|
|
|
"exchangedCash": activity.ExchangedCash,
|
|
|
"exchangedSuMoney": activity.ExchangedSuMoney,
|
|
|
"exchangedCash": cash,
|
|
|
"exchangedSuMoney": suMoney,
|
|
|
"deadline": activity.Deadline.UTC().Format("2006-01-02"),
|
|
|
"countDown": activity.CountDown,
|
|
|
"rate": activity.Rate,
|
...
|
...
|
@@ -682,6 +710,8 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -872,6 +902,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
|
|
|
activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
|
|
|
return activityUpdated, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -1831,7 +1863,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
|
|
|
|
// 判断兑换活动的现金是否超过现金池未兑换现金
|
|
|
if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池未兑换现金")
|
|
|
}
|
|
|
|
|
|
// 获取平台素币兑换情况
|
...
|
...
|
|