Browse Source

fix: 活动相关接口调整

hsun 3 years ago
parent
commit
897fbca03d
2 changed files with 9 additions and 21 deletions
  1. 5 15
      controller/activity/activity.go
  2. 4 6
      services/activity/activity.go

+ 5 - 15
controller/activity/activity.go

@@ -40,7 +40,7 @@ func GetPageList(c *gin.Context) {
 }
 
 func _handleListQuery(c *gin.Context) (string, []interface{}, string) {
-	condition := "is_delete = 0"
+	condition := "is_delete = 0 AND publish_status = 1"
 	pars := make([]interface{}, 0)
 	// 活动类别/标题
 	reqTitle := c.DefaultQuery("title", "")
@@ -53,22 +53,11 @@ func _handleListQuery(c *gin.Context) (string, []interface{}, string) {
 	reqState := c.DefaultQuery("active_state", "0")
 	if reqState != "0" {
 		state, _ := strconv.Atoi(reqState)
-		nowTime := time.Now().Format("2006-01-02 15:04:05")
-		weekStart := utils.GetNowWeekMonday()
-		weekEnd := utils.GetNowWeekLastDay()
-		// 比对本周开始时间和当前时间
-		timeNow, _ := time.ParseInLocation("2006-01-02 15:04:05", nowTime, time.Local)
-		queryStart := timeNow
-		if timeNow.Before(weekStart) {
-			queryStart = weekStart
-		}
+		nowTime := time.Now().Format(utils.FormatDateTime)
 		switch state {
 		case 1:
-			// 时间在本周内且未开始
-			condition += ` AND start_time >= ?`
-			pars = append(pars, queryStart)
-			condition += ` AND end_time < ?`
-			pars = append(pars, weekEnd)
+			condition += ` AND start_time > ?`
+			pars = append(pars, nowTime)
 		case 2:
 			condition += ` AND start_time <= ?`
 			pars = append(pars, nowTime)
@@ -77,6 +66,7 @@ func _handleListQuery(c *gin.Context) (string, []interface{}, string) {
 		case 3:
 			condition += ` AND end_time < ?`
 			pars = append(pars, nowTime)
+			order = "start_time desc"
 		}
 	}
 	reqType := c.DefaultQuery("activity_type", "0")

+ 4 - 6
services/activity/activity.go

@@ -91,18 +91,16 @@ func PageList(condition string, pars []interface{}, page, limit int, order strin
 
 // getActivityStateByTime 根据时间生成活动枚举值
 func getActivityStateByTime(startTime, endTime time.Time) (state int) {
-	weekStart := utils.GetNowWeekMonday()
-	weekEnd := utils.GetNowWeekLastDay()
-	nowTime := time.Now().Format("2006-01-02 15:04:05")
-	timeNow, _ := time.ParseInLocation("2006-01-02 15:04:05", nowTime, time.Local)
+	nowTime := time.Now().Format(utils.FormatDateTime)
+	timeNow, _ := time.ParseInLocation(utils.FormatDateTime, nowTime, time.Local)
 	if timeNow.Before(endTime) && timeNow.After(startTime) {
 		// 进行中
 		state = 2
 	} else if timeNow.After(endTime) {
 		// 已结束
 		state = 3
-	} else if timeNow.Before(weekEnd) && timeNow.Before(endTime) && timeNow.After(weekStart) && timeNow.Before(startTime) {
-		// 本周预告
+	} else if timeNow.Before(startTime) {
+		// 未开始
 		state = 1
 	}
 	return