@@ -0,0 +1,99 @@
|
||||
package actvser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/v/actmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func GetActities(req GetActitiesRequest) (int64, []actmod.Activity, bool, error) {
|
||||
skip := (req.PageNum - 1) * req.PageSize
|
||||
count, err := actmod.GetActivitiesCount()
|
||||
if err != nil {
|
||||
return 0, nil, false, err
|
||||
}
|
||||
if uint64(count) <= skip {
|
||||
return 0, nil, false, err
|
||||
}
|
||||
limit := req.PageSize + 1
|
||||
actvs, err := actmod.GetActivities(skip, limit)
|
||||
if err != nil {
|
||||
return count, nil, false, err
|
||||
}
|
||||
hasNext := false
|
||||
if uint64(len(actvs)) > req.PageSize {
|
||||
hasNext = true
|
||||
actvs = actvs[:req.PageSize]
|
||||
}
|
||||
return count, actvs, hasNext, nil
|
||||
}
|
||||
|
||||
func AddActivity(req AddActivityRequest) error {
|
||||
now := time.Now()
|
||||
act := actmod.Activity{
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
if req.ActivityName != nil {
|
||||
act.ActivityName = *req.ActivityName
|
||||
}
|
||||
if req.Desc != nil {
|
||||
act.Desc = *req.Desc
|
||||
}
|
||||
if req.Img != nil {
|
||||
act.Img = *req.Img
|
||||
}
|
||||
if req.Content != nil {
|
||||
act.Content = *req.Content
|
||||
}
|
||||
if req.Link != nil {
|
||||
act.Link = *req.Link
|
||||
}
|
||||
if req.Sort != nil {
|
||||
act.Sort = *req.Sort
|
||||
}
|
||||
if req.Status != nil {
|
||||
act.Status = *req.Status
|
||||
}
|
||||
if req.ExpiredIn != nil {
|
||||
act.ExpiredIn = *req.ExpiredIn
|
||||
}
|
||||
return actmod.AddACtivity(act)
|
||||
}
|
||||
|
||||
func UpdateActivity(req UpdateActivityRequest) error {
|
||||
b := make(bson.M)
|
||||
if req.ActivityName != nil {
|
||||
b["activityName"] = *req.ActivityName
|
||||
}
|
||||
if req.Desc != nil {
|
||||
b["desc"] = *req.Desc
|
||||
}
|
||||
if req.Img != nil {
|
||||
b["img"] = *req.Img
|
||||
}
|
||||
if req.Content != nil {
|
||||
b["content"] = *req.Content
|
||||
}
|
||||
if req.Link != nil {
|
||||
b["link"] = *req.Link
|
||||
}
|
||||
if req.Sort != nil {
|
||||
b["sort"] = *req.Sort
|
||||
}
|
||||
if req.Status != nil {
|
||||
b["status"] = *req.Status
|
||||
}
|
||||
if req.ExpiredIn != nil {
|
||||
b["expiredIn"] = *req.ExpiredIn
|
||||
}
|
||||
if len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
now := time.Now()
|
||||
b["createdAt"] = now
|
||||
b["updatedAt"] = now
|
||||
return actmod.EidtActivity(req.ActvID, b)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package actvser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type GetActitiesRequest struct {
|
||||
PageNum uint64 `form:"pageNum" json:"pageNum" binding:"required,min=1"` // 页码
|
||||
PageSize uint64 `form:"pageSize" json:"pageSize" binding:"required,min=1,max=20"` // 每页展示数
|
||||
}
|
||||
|
||||
type UpdateActivityRequest struct {
|
||||
ActvID primitive.ObjectID `json:"activeID"` // 被编辑的活动id
|
||||
ActivityName *string `json:"activityName"` // 活动名
|
||||
Desc *string `json:"desc"` // 活动说明
|
||||
Img *string `json:"img"` // 活动图片
|
||||
Content *string `json:"content"` // 富文本内容
|
||||
Link *string `json:"link"` // 链接地址
|
||||
Sort *int `json:"sort"` // 活动排序
|
||||
Status *int `json:"status"` // 状态 1 有效 0 无效
|
||||
ExpiredIn *time.Time `json:"expiredIn"` // 过期时间
|
||||
}
|
||||
|
||||
type AddActivityRequest struct {
|
||||
ActivityName *string `json:"activityName"` // 活动名
|
||||
Desc *string `json:"desc"` // 活动说明
|
||||
Img *string `json:"img"` // 活动图片
|
||||
Content *string `json:"content"` // 富文本内容
|
||||
Link *string `json:"link"` // 链接地址
|
||||
Sort *int `json:"sort"` // 活动排序
|
||||
Status *int `json:"status"` // 状态 1 有效 0 无效
|
||||
ExpiredIn *time.Time `json:"expiredIn"` // 过期时间
|
||||
}
|
||||
Reference in New Issue
Block a user