...
|
...
|
@@ -277,7 +277,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
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)
|
|
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
|
|
|
|
|
|
newActivity := &domain.ExchangeCashActivity{
|
|
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
...
|
...
|
@@ -285,7 +285,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
|
ExchangedCash: 0,
|
|
|
ExchangedSuMoney: 0,
|
|
|
//Deadline: time.Date(deadline.Year(), deadline.Month(), deadline.Day(), deadline.Hour(), deadline.Minute(), deadline.Second(), 0, time.Local),
|
|
|
Deadline: createExchangeCashActivityCommand.Deadline,
|
|
|
Deadline: deadline,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算活动截止倒计时
|
|
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
|
|
CreateTime: time.Now(),
|
...
|
...
|
@@ -349,7 +349,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
|
|
|
var deadlines []interface{}
|
|
|
for _, activity := range activities {
|
|
|
deadlines = append(deadlines, activity.Deadline.Format("2006-01-02"))
|
|
|
deadlines = append(deadlines, activity.Deadline)
|
|
|
}
|
|
|
|
|
|
if len(deadlines) == 0 {
|
...
|
...
|
@@ -362,6 +362,71 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 搜索兑换现金活动
|
|
|
func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityCommand *command.SearchExchangeCashActivityCommand) (interface{}, error) {
|
|
|
if err := activityCommand.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 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
|
|
|
}
|
|
|
|
|
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, activity := range activities {
|
|
|
var t1 = time.Now()
|
|
|
var t2 = activity.Deadline
|
|
|
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
|
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
|
|
Deadline: activity.Deadline,
|
|
|
}
|
|
|
|
|
|
// 倒计时结束
|
|
|
if t2.Before(t1) {
|
|
|
updateExchangeCashActivity.CountDown = 0
|
|
|
updateExchangeCashActivity.Deadline = activity.Deadline
|
|
|
}
|
|
|
|
|
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
_, err := exchangeActivityRepository.Save(activity)
|
|
|
if err != 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 map[string]interface{}{
|
|
|
"count": count,
|
|
|
"activities": activities,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回兑换现金活动列表
|
|
|
func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCashActivityQuery *query.ListExchangeCashActivityQuery) (interface{}, error) {
|
|
|
if err := listExchangeCashActivityQuery.ValidateQuery(); err != nil {
|
...
|
...
|
@@ -391,10 +456,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for _, activity := range activities {
|
|
|
var timeNow = time.Now()
|
|
|
var deadline = activity.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)
|
|
|
//var timeNow = time.Now()
|
|
|
//var deadline = activity.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(), 23, 59, 59, 0, time.Local)
|
|
|
var t1 = time.Now()
|
|
|
var t2 = activity.Deadline
|
|
|
|
|
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
|
|
ExchangeCashActivityId: activity.ActivityId,
|
...
|
...
|
|