Files
huangguo_server/models/v/integralconfigmod/web.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

119 lines
4.1 KiB
Go

package integralconfigmod
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
)
type AddCond struct {
Name string `json:"name" bson:"name"` // 积分名称
Duration uint64 `json:"duration" bson:"duration"` // 积分持续天数
Desc string `json:"desc" bson:"desc"` // 描述
Img string `json:"img" bson:"img"` // 图片LOGO
Price int64 `json:"price" bson:"price"` // 积分价格
EquivalentPrice int64 `json:"equivalentPrice" bson:"equivalentPrice"` // 积分价值
Type int `json:"type" bson:"type"` // 类型
Status bool `json:"status" bson:"status"` // 积分状态
SortCode int64 `json:"sortCode" bson:"sortCode"` // 排序
}
func (receiver *AddCond) Generate(addAct string) IntegralConfig {
now := time.Now()
return IntegralConfig{
Name: receiver.Name,
Duration: receiver.Duration,
Desc: receiver.Desc,
Price: receiver.Price,
EquivalentPrice: receiver.EquivalentPrice,
Status: receiver.Status,
Type: receiver.Type,
SortCode: receiver.SortCode,
Img: receiver.Img,
UpdateAct: addAct,
UpdateTime: now,
CreateTime: now,
}
}
type EditCond struct {
ID primitive.ObjectID `json:"id" binding:"required"` // 文档
Name *string `json:"name" bson:"name"` // 积分名称
Duration *uint64 `json:"duration" bson:"duration"` // 积分持续天数
Desc *string `json:"desc" bson:"desc"` // 描述
Img *string `json:"img" bson:"img"` // 图片LOGO
Price *int64 `json:"price" bson:"price"` // 积分价格
EquivalentPrice *int64 `json:"equivalentPrice" bson:"equivalentPrice"` // 积分价值
Type *int `json:"type" bson:"type"` // 类型
Status *bool `json:"status" bson:"status"` // 积分状态
SortCode *int64 `json:"sortCode" bson:"sortCode"` // 排序
}
func (receiver *EditCond) Filter() bson.M {
return bson.M{"_id": receiver.ID}
}
func (receiver *EditCond) Update(updateAct string) bson.M {
var update = bson.M{}
if receiver.Name != nil {
update["name"] = receiver.Name
}
if receiver.Duration != nil {
update["duration"] = receiver.Duration
}
if receiver.Desc != nil {
update["desc"] = receiver.Desc
}
if receiver.Price != nil {
update["price"] = receiver.Price
}
if receiver.EquivalentPrice != nil {
update["equivalentPrice"] = receiver.EquivalentPrice
}
if receiver.Status != nil {
update["status"] = receiver.Status
}
if receiver.SortCode != nil {
update["sortCode"] = receiver.SortCode
}
if receiver.Img != nil {
update["img"] = receiver.Img
}
if receiver.Type != nil {
update["type"] = receiver.Type
}
update["updateAct"] = updateAct
update["updateTime"] = time.Now()
update["reviewAt"] = time.Now()
return bson.M{"$set": update}
}
type QueryAllCond struct {
Page int64 `form:"page" binding:"required"` // 当前页
Limit int64 `form:"limit" binding:"required"` // 页码
ID *string `form:"id"` // ID
Status *bool `form:"status"` // 审核状态 0未审核 1 通过 2 拒绝
}
type QueryAllRes struct {
List []*IntegralConfig `json:"list"`
Total int64 `json:"total"`
}
func (receiver *QueryAllCond) Filter() bson.M {
var query = bson.M{}
if receiver.Status != nil {
query["status"] = receiver.Status
}
if receiver.ID != nil {
query["_id"] = receiver.ID
}
return query
}
func (receiver QueryAllCond) Options() *options.FindOptions {
return options.Find().SetSkip((receiver.Page - 1) * receiver.Limit).SetLimit(receiver.Limit).SetSort(bson.M{"updateTime": -1})
}