Commit 69fd239d by 杨树贤

判断优先级

parent 525fcd95
...@@ -5,6 +5,8 @@ import ( ...@@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
...@@ -30,6 +32,8 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p ...@@ -30,6 +32,8 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
//对活动进行创建时间逆序排序,因为要以创建时间靠后的优先级最高
sort.Sort(sorter.ActivitySorter(activities))
if len(activities) != 0 { if len(activities) != 0 {
priceActivity = as.GetPriceActivity(checkData, activities) priceActivity = as.GetPriceActivity(checkData, activities)
} }
......
package sorter
import "go_sku_server/model"
// 阶梯价格排序算法
type ActivitySorter []model.Activity
func (a ActivitySorter) Len() int {
return len(a)
}
func (a ActivitySorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a ActivitySorter) Less(i, j int) bool {
return a[j].AddTime < a[i].AddTime
}
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 sign in to comment