@@ -0,0 +1,83 @@
|
||||
package checkinconfigmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
const table = models.CheckinConfig
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "enable", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
// FindOne 查找签到配置
|
||||
func FindOne(filter primitive.M) (*CheckinConfig, error) {
|
||||
var config CheckinConfig
|
||||
if err := coll(nil).FindOne(&config, filter); err != nil {
|
||||
log.Error(fmt.Sprintf("[checkinconfigmod:FindOne] failed: %+v", err))
|
||||
return nil, err
|
||||
}
|
||||
if config.ID.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
// UpdateOne 更新签到配置
|
||||
func UpdateOne(filter primitive.M, update primitive.M) error {
|
||||
result, err := coll(nil).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[checkinconfigmod:UpdateOne] failed: %+v", err))
|
||||
return err
|
||||
}
|
||||
if result.MatchedCount == 0 {
|
||||
return mongo.ErrNoDocuments
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertOne 插入签到配置
|
||||
func InsertOne(config *CheckinConfig) error {
|
||||
if _, err := coll(nil).InsertOne(config); err != nil {
|
||||
log.Error(fmt.Sprintf("[checkinconfigmod:InsertOne] failed: %+v", err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Count 统计数量
|
||||
func Count(filter primitive.M) (int64, error) {
|
||||
count, err := coll(nil).Count(filter)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[checkinconfigmod:Count] failed: %+v", err))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package checkinconfigmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/models/v/prizemod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const CheckinConfigId = "checkin_config_1"
|
||||
|
||||
type CheckinConfig struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Enable bool `json:"enable" bson:"enable"` // 是否启用
|
||||
Description string `json:"description" bson:"description"` // 规则说明
|
||||
BackgroundImage string `json:"backgroundImage" bson:"backgroundImage"` // 背景图片
|
||||
RewardBgVideos []RewardBgVideo `json:"rewardBgVideos" bson:"rewardBgVideos"` // 奖励播放媒体地址
|
||||
IntegerExchangeList []GiftItem `json:"integerExchangeList" bson:"integerExchangeList"` // 积分可兑换豪礼列表
|
||||
}
|
||||
|
||||
type GiftItem struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
Icon string `json:"icon" bson:"icon"`
|
||||
}
|
||||
|
||||
type RewardBgVideo struct {
|
||||
PrizeType prizemod.PrizeType `json:"prizeType" bson:"prizeType"` // 奖品类型
|
||||
BgMediaUrl string `json:"bgMediaUrl" bson:"bgMediaUrl"` // 奖励背景动画
|
||||
FsResourceStatus string `json:"fsResourceStatus" bson:"fsResourceStatus"` // 视频文件切片状态
|
||||
FsResourceId string `json:"fsResourceId" bson:"fsResourceId"` // 文件服id
|
||||
}
|
||||
|
||||
var mdb *db.MongoDB
|
||||
Reference in New Issue
Block a user