|
|
@@ -5,6 +5,7 @@ import (
|
|
|
"app/commons/services"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
@@ -306,7 +307,45 @@ func (s *Server) TaskDetail(c *gin.Context) {
|
|
|
userTask := &entity.DtUserTask{}
|
|
|
if err := db.Where("user_id = ? AND task_id = ?", userId, taskId).
|
|
|
Order("id DESC").First(userTask).Error; err == nil {
|
|
|
- apply = userTask
|
|
|
+
|
|
|
+ // 如果任务已完成,需要检查是否可以再次领取
|
|
|
+ if userTask.Status == entity.UserTaskStatusCompleted {
|
|
|
+ canReClaim := true
|
|
|
+ today := time.Now().Format("2006-01-02")
|
|
|
+
|
|
|
+ // 检查每日限制
|
|
|
+ if task.DailyLimit > 0 {
|
|
|
+ var todayCount int64
|
|
|
+ db.Model(&entity.DtUserTask{}).
|
|
|
+ Where("user_id = ? AND task_id = ? AND DATE(FROM_UNIXTIME(created_at)) = ?",
|
|
|
+ userId, taskId, today).
|
|
|
+ Count(&todayCount)
|
|
|
+ if int(todayCount) >= task.DailyLimit {
|
|
|
+ canReClaim = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查总限制
|
|
|
+ if canReClaim && task.TotalLimit > 0 {
|
|
|
+ var totalCount int64
|
|
|
+ db.Model(&entity.DtUserTask{}).
|
|
|
+ Where("user_id = ? AND task_id = ? AND status != ?",
|
|
|
+ userId, taskId, entity.UserTaskStatusAbandoned).
|
|
|
+ Count(&totalCount)
|
|
|
+ if int(totalCount) >= task.TotalLimit {
|
|
|
+ canReClaim = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if canReClaim {
|
|
|
+ apply = nil
|
|
|
+ } else {
|
|
|
+ apply = userTask
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 其他状态(进行中、待审核等)直接返回
|
|
|
+ apply = userTask
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|