作者 陈志颖

fix:活动截止时间格式化

... ... @@ -288,7 +288,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
}
// 时间格式化
var deadline = createExchangeCashActivityCommand.Deadline
dd, _ := time.ParseDuration("24h")
var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
var t1 = time.Now()
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.UTC)
... ... @@ -357,7 +358,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc
// 提取兑换现金活动截止时间
var deadlines []interface{}
for _, activity := range activities {
tmpTime := activity.Deadline.Format("2006-01-02")
tmpTime := activity.Deadline.UTC().Format("2006-01-02")
if !utils.IsContain(deadlines, tmpTime) {
deadlines = append(deadlines, tmpTime)
}
... ... @@ -397,8 +398,6 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
exchangeActivityRepository = value
}
//fmt.Printf("查找活动命令:%+v\n", activityCommand)
// 查找兑换现金活动
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(activityCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -407,7 +406,7 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
var t1 = time.Now()
var t2 = activity.Deadline
// 更新兑换活动命令
// 更新兑换活动倒计时命令
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
ExchangeCashActivityId: activity.ActivityId,
CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算倒计时
... ... @@ -423,12 +422,12 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
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())
... ... @@ -438,9 +437,26 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var activitiesFormat []interface{}
for _, activity := range activities {
activityFormat := map[string]interface{} {
"activityId": activity.ActivityId,
"exchangeActivityName": activity.ExchangeActivityName,
"companyId": activity.CompanyId,
"exchangedCash": activity.ExchangedCash,
"exchangedSuMoney": activity.ExchangedSuMoney,
"deadline": activity.Deadline.UTC().Format("2006-01-02"),
"countDown": activity.CountDown,
"rate": activity.Rate,
"createTime": activity.CreateTime.UTC(),
}
activitiesFormat = append(activitiesFormat, activityFormat)
}
return map[string]interface{}{
"count": count,
"activities": activities,
"activities": activitiesFormat,
}, nil
}
}
... ... @@ -522,7 +538,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
"deadline": activity.Deadline.UnixNano() / 1e6, // 秒级时间戳转换
"countDown": activity.CountDown,
"rate": activity.Rate,
"createTime": activity.CreateTime,
"createTime": activity.CreateTime.UTC(),
}
activitiesWithTs = append(activitiesWithTs, activityWithTs)
}
... ...