52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package actvser
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
"91porn-server/models/v/actmod"
|
|
)
|
|
|
|
var dateMax = time.Date(2999, 12, 31, 0, 0, 0, 0, time.Local)
|
|
|
|
func GetActivities(req GetActitiesRequest) ([]actmod.Activity, bool, error) {
|
|
skip := uint64((req.PageNumber - 1) * req.PageSize)
|
|
limit := uint64(req.PageSize + 1)
|
|
actvs, err := actmod.GetActivitiesValid(skip, limit)
|
|
if err != nil {
|
|
return nil, false, err
|
|
}
|
|
hasNext := false
|
|
if uint64(len(actvs)) > req.PageSize {
|
|
hasNext = true
|
|
actvs = actvs[:req.PageSize]
|
|
}
|
|
now := time.Now()
|
|
for i := range actvs {
|
|
if actvs[i].ExpiredIn.IsZero() {
|
|
actvs[i].ExpiredIn = dateMax
|
|
continue
|
|
}
|
|
if actvs[i].ExpiredIn.Before(now) {
|
|
actvs[i].Status = 2 // 状态设置为已过期
|
|
}
|
|
}
|
|
return actvs, hasNext, nil
|
|
}
|
|
|
|
func GetActiveByID(id primitive.ObjectID) (*actmod.Activity, error) {
|
|
actv, err := actmod.GetActivityByActivityID(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if actv.ExpiredIn.IsZero() {
|
|
actv.ExpiredIn = dateMax
|
|
return actv, nil
|
|
}
|
|
if actv.Status == 1 && actv.ExpiredIn.Before(time.Now()) {
|
|
actv.Status = 2
|
|
}
|
|
return actv, nil
|
|
}
|