Commit 21aed002 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

add submitTimestamp

parent 7bcec231
...@@ -136,28 +136,28 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) { ...@@ -136,28 +136,28 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) {
return count > 0, err return count > 0, err
} }
func (d *Dao) GetTaskResult(tid int, userId string) (status string, err error) { func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt time.Time, err error) {
isDailyTask, err := d.IsDailyTask(tid) isDailyTask, err := d.IsDailyTask(tid)
if err != nil { if err != nil {
return "", err return "", time.Time{}, err
} }
temp := &dbModel.TaskHistory{} temp := &dbModel.TaskHistory{}
tx := d.db.Session(&gorm.Session{Logger: logger.Default.LogMode(logger.Silent)}) tx := d.db.Session(&gorm.Session{Logger: logger.Default.LogMode(logger.Silent)})
if !isDailyTask { if !isDailyTask {
err = tx.Model(&dbModel.TaskHistory{}).Where("task_id = ? and user_id = ?", tid, userId).First(temp).Error err = tx.Model(&dbModel.TaskHistory{}).Where("task_id = ? and user_id = ?", tid, userId).First(temp).Error
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, nil return constant.TaskHistoryStatusTodo, time.Time{}, nil
} }
return temp.Status, err return temp.Status, temp.CreatedAt, err
} }
err = tx.Model(&dbModel.TaskHistory{}). err = tx.Model(&dbModel.TaskHistory{}).
Where("task_id = ? and user_id = ? and created_at >= ?", tid, userId, time.Now().UTC().Truncate(24*time.Hour)). Where("task_id = ? and user_id = ? and created_at >= ?", tid, userId, time.Now().UTC().Truncate(24*time.Hour)).
First(temp).Error First(temp).Error
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, nil return constant.TaskHistoryStatusTodo, time.Time{}, nil
} }
return temp.Status, err return temp.Status, temp.CreatedAt, err
} }
func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, initStatus string) (exist bool, err error) { func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, initStatus string) (exist bool, err error) {
......
...@@ -46,20 +46,21 @@ type CreateGroupRequest struct { ...@@ -46,20 +46,21 @@ type CreateGroupRequest struct {
} }
type Task struct { type Task struct {
TaskId interface{} `json:"taskId,omitempty"` TaskId interface{} `json:"taskId,omitempty"`
Platform string `json:"platform" binding:"required"` Platform string `json:"platform" binding:"required"`
Action string `json:"action" binding:"required"` Action string `json:"action" binding:"required"`
Url string `json:"url"` Url string `json:"url"`
TweetId int `json:"tweetId"` TweetId int `json:"tweetId"`
Description string `json:"description" binding:"required"` Description string `json:"description" binding:"required"`
Reward int `json:"reward" binding:"required"` Reward int `json:"reward" binding:"required"`
Start int `json:"start" binding:"required"` Start int `json:"start" binding:"required"`
End int `json:"end" binding:"required"` End int `json:"end" binding:"required"`
Daily bool `json:"daily" binding:"required"` Daily bool `json:"daily" binding:"required"`
Status string `json:"status"` Status string `json:"status"`
TelegramActiveThreshold int `json:"telegramActiveThreshold"` // 仅电报活跃可用 TelegramActiveThreshold int `json:"telegramActiveThreshold"` // 仅电报活跃可用
Enable bool `json:"enable"` Enable bool `json:"enable"`
Msg string `json:"msg"` Msg string `json:"msg"`
SubmitTimestamp int `json:"submitTimestamp"`
} }
type CreateTaskRequest struct { type CreateTaskRequest struct {
......
...@@ -79,7 +79,7 @@ func checkTask(c *gin.Context) { ...@@ -79,7 +79,7 @@ func checkTask(c *gin.Context) {
return return
} }
status, err := srv.GetTaskResult(taskId, userId) status, _, err := srv.GetTaskResult(taskId, userId)
if err != nil { if err != nil {
c.JSON(200, withError(constant.InternalError)) c.JSON(200, withError(constant.InternalError))
return return
...@@ -117,7 +117,7 @@ func submitTask(c *gin.Context) { ...@@ -117,7 +117,7 @@ func submitTask(c *gin.Context) {
return return
} }
status, err := srv.GetTaskResult(taskId, userId) status, _, err := srv.GetTaskResult(taskId, userId)
if err != nil { if err != nil {
c.JSON(200, withError(constant.InternalError)) c.JSON(200, withError(constant.InternalError))
return return
......
...@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
Enable: task.Enable, Enable: task.Enable,
} }
status, err := s.GetTaskResult(_task.TaskId.(int), userId) status, createdAt, err := s.GetTaskResult(_task.TaskId.(int), userId)
if err != nil { if err != nil {
log.WithError(err).Error("group check task") log.WithError(err).Error("group check task")
return nil, err return nil, err
...@@ -83,6 +83,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -83,6 +83,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
if status == constant.TaskHistoryStatusRetry { if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again." _task.Msg = "The task is not completed, please try again."
} }
_task.SubmitTimestamp = int(createdAt.Unix())
resp.Tasks = append(resp.Tasks, _task) resp.Tasks = append(resp.Tasks, _task)
} }
return return
......
...@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) { ...@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) {
return return
} }
func (s *Service) GetTaskResult(taskId int, userId string) (status string, err error) { func (s *Service) GetTaskResult(taskId int, userId string) (status string, createdAt time.Time, err error) {
status, err = s.d.GetTaskResult(taskId, userId) status, createdAt, err = s.d.GetTaskResult(taskId, userId)
if err != nil { if err != nil {
log.WithError(err).Error("get task result error") log.WithError(err).Error("get task result error")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment