@@ -0,0 +1,33 @@
|
||||
package integralconfigmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type APPIntegralConfig struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 积分配置的唯一id
|
||||
Name string `json:"name" bson:"name"` // 积分名称
|
||||
Duration uint64 `json:"duration" bson:"duration"` // 积分持续天数
|
||||
Type int `json:"type" bson:"type"` // 类型
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Img string `json:"img" bson:"img"` // 图片LOGO
|
||||
Price int64 `json:"price" bson:"price"` // 积分价格
|
||||
}
|
||||
|
||||
type ExchangeIntegralReq struct {
|
||||
ID string `json:"id" bson:"id" binding:"required"` // 积分配置的唯一id
|
||||
Name string `json:"name" bson:"name"` // 兑换用户姓名
|
||||
Tel string `json:"tel" bson:"tel"` // 兑换用户电话
|
||||
Address string `json:"address" bson:"address"` // 兑换用户地址
|
||||
}
|
||||
|
||||
type AppIntegralRecord struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 记录id
|
||||
Integral int64 `json:"integral" bson:"integral"` // 积分数量
|
||||
Type int `json:"type" bson:"type"` // 兑换记录类型
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Name string `json:"name" bson:"name"` // 积分名称
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 兑换时间
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package integralconfigmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const table = models.IntegralConfig
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initIndex 索引设置
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{"createdAt", -1}},
|
||||
},
|
||||
}
|
||||
_, err := coll(nil).CreateIndex(many)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("user model set index err ==>[%+v]", err))
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func InsertOne(mt *db.MongoTool, cfg IntegralConfig) error {
|
||||
if _, err := coll(mt).InsertOne(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindOneById(id primitive.ObjectID) (IntegralConfig, error) {
|
||||
cfg := IntegralConfig{}
|
||||
err := coll(nil).FindOne(&cfg, bson.M{"_id": id})
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func FindOneByVId(vid primitive.ObjectID) (IntegralConfig, error) {
|
||||
cfg := IntegralConfig{}
|
||||
err := coll(nil).FindOne(&cfg, bson.M{"vidId": vid})
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
// GetByVidIds 根据vid获取列表
|
||||
func GetByVidIds(vidIds []primitive.ObjectID) ([]IntegralConfig, error) {
|
||||
vidTimeOnlineList := make([]IntegralConfig, 0)
|
||||
err := coll(nil).Find(&vidTimeOnlineList, bson.M{"vidId": bson.M{"$in": vidIds}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vidTimeOnlineList, nil
|
||||
}
|
||||
|
||||
// DeleteByIds 删除
|
||||
func DeleteByIds(ids []primitive.ObjectID) error {
|
||||
_, err := coll(nil).DeleteMany(bson.M{"_id": bson.M{"$in": ids}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteByVids 根据帖子id删除数据
|
||||
func DeleteByVids(vids []primitive.ObjectID) error {
|
||||
_, err := coll(nil).DeleteMany(bson.M{"vidId": bson.M{"$in": vids}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryAllList 分页查询文档
|
||||
func QueryAllList(filter primitive.M, opts ...*options.FindOptions) (out []*IntegralConfig, err error) {
|
||||
if err = coll(nil).Find(&out, filter, opts...); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllList", table, "Find", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("opts", opts),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// QueryAllCount 查询文档条目数
|
||||
func QueryAllCount(filter primitive.M) (int64, error) {
|
||||
if count, err := coll(nil).Count(filter); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllCount", table, "Count", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return 0, err
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Edit 修改文档
|
||||
func Edit(filter, update primitive.M) error {
|
||||
result, err := coll(nil).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "UpdateOne", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount == 0 {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "result.ModifiedCount", "ModifiedCount is zero"),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return errors.New("result is null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoList 获取作品列表
|
||||
func GetVideoList(skip, limit int64, cond bson.M, opts ...*options.FindOptions) (back []*APPIntegralConfig, total int64, hasNext bool, err error) {
|
||||
// 获取总条数
|
||||
total, err = coll(nil).Count(cond)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "getVideoList", table, "Find", err),
|
||||
log.Any("skip", skip),
|
||||
log.Any("limit", limit),
|
||||
log.Any("cond", cond))
|
||||
return
|
||||
}
|
||||
if total == 0 {
|
||||
return
|
||||
}
|
||||
err = coll(nil).Find(&back, cond, opts...)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "getVideoList", table, "Find", err),
|
||||
log.Any("skip", skip),
|
||||
log.Any("limit", limit),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return
|
||||
}
|
||||
if len(back) > int(limit) {
|
||||
hasNext = true
|
||||
back = back[:limit]
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package integralconfigmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var (
|
||||
mdb *db.MongoDB
|
||||
)
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
VIPDate // 1 VIP兑换
|
||||
AICount // 2 AI黑科技卷
|
||||
GoldCoinBonus // 3 金币加赠券
|
||||
GoldWatch // 4 金币观影券
|
||||
InKind // 5 实物奖励
|
||||
FreeCount // 6 幸运抽奖次数
|
||||
)
|
||||
|
||||
// IntegralConfig 积分配置
|
||||
type IntegralConfig struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 积分配资的唯一id
|
||||
Name string `json:"name" bson:"name"` // 积分名称
|
||||
Duration uint64 `json:"duration" bson:"duration"` // 积分持续天数
|
||||
Type int `json:"type" bson:"type"` // 类型
|
||||
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"` // 积分价值
|
||||
SortCode int64 `json:"sortCode" bson:"sortCode"` // 排序
|
||||
Status bool `json:"status" bson:"status"` // 积分状态
|
||||
UpdateAct string `json:"updateAct" bson:"updateAct"` // 操作账号
|
||||
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 更新时间
|
||||
CreateTime time.Time `json:"createTime" bson:"createTime"` // 创建时间
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
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})
|
||||
}
|
||||
Reference in New Issue
Block a user