@@ -0,0 +1,11 @@
|
||||
package taskmod
|
||||
|
||||
type ReceiveTaskReq struct {
|
||||
TaskID string `json:"taskId" bson:"taskId" binding:"required"` // 任务ID
|
||||
Type int `json:"type" bson:"type" binding:"required"` // 任务类型 1:每日任务 2:一次性任务 3:成长任务
|
||||
}
|
||||
|
||||
type DoTaskReq struct {
|
||||
TaskID string `json:"taskId" bson:"taskId" binding:"required"` // 任务ID
|
||||
Type int `json:"type" bson:"type" binding:"required"` // 任务类型
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package taskmod
|
||||
|
||||
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.TaskConfig
|
||||
|
||||
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{{Key: "status", Value: 1}, {Key: "finishCondition", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "type", Value: 1}, {Key: "status", Value: 1}, {Key: "finishCondition", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "finishCondition", Value: 1}, {Key: "type", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "status", Value: 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 ConfigList() ([]*TaskConfig, error) {
|
||||
var out []*TaskConfig = make([]*TaskConfig, 0)
|
||||
if err := coll(nil).Find(&out, bson.M{"status": true}, options.Find().SetSort(bson.M{"finishCondition": 1})); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "ConfigList", models.TaskConfig, "Find", err))
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func GetConfigListByType(t ConfigType) ([]*TaskConfig, error) {
|
||||
var out []*TaskConfig = make([]*TaskConfig, 0)
|
||||
if err := coll(nil).Find(&out, bson.M{"type": t, "status": true}, options.Find().SetSort(bson.M{"finishCondition": 1})); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "ConfigList", models.TaskConfig, "Find", err))
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func GetConfigByID(id primitive.ObjectID) (*TaskConfig, error) {
|
||||
var out *TaskConfig = new(TaskConfig)
|
||||
if err := coll(nil).FindOne(&out, bson.M{"_id": id, "status": true}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func IsExistConfig(finishCondition int64, configType ConfigType) (bool, error) {
|
||||
count, err := coll(nil).Count(bson.M{"finishCondition": finishCondition, "type": configType})
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IsExistConfig", models.TaskConfig, "Count", err),
|
||||
log.Any("finishCondition", finishCondition),
|
||||
log.Any("configType", configType),
|
||||
)
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func AddConfig(sc TaskConfig) error {
|
||||
if _, err := coll(nil).InsertOne(&sc); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "AddConfig", models.TaskConfig, "InsertOne", err),
|
||||
log.Any("sc", sc),
|
||||
)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ModifyConfig(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:", "ModifyConfig", models.TaskConfig, "UpdateOne", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount == 0 {
|
||||
err = errors.New("prize UpdateOne ModifiedCount err")
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "ModifyConfig", models.TaskConfig, "result.ModifiedCount == 0", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func QueryAllConfig(filter primitive.M, opts ...*options.FindOptions) ([]*TaskConfig, error) {
|
||||
var out []*TaskConfig = []*TaskConfig{}
|
||||
if err := coll(nil).Find(&out, filter, opts...); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllConfig", models.TaskConfig, "Find", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func CountConfig(filter primitive.M) (int64, error) {
|
||||
count, err := coll(nil).Count(filter)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "CountConfig", models.TaskConfig, "Count", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func QueryTaskConfigByCond(filter primitive.M) (*TaskConfig, error) {
|
||||
var out *TaskConfig
|
||||
if err := coll(nil).FindOne(&out, filter); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryTaskConfigByCond", models.TaskConfig, "Find", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package taskmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
type ConfigType int
|
||||
|
||||
const (
|
||||
GrowthBuyGold = iota + 1 // 成长任务-购买金币
|
||||
GrowthBuyInviteUser // 邀请任务
|
||||
GrowthBuyLogin // 登陆任务
|
||||
|
||||
// 以下都是旧的,暂时没用
|
||||
//Sign // 签到福利
|
||||
//JewelBox // 宝箱福利
|
||||
//ConsumerFeedback // 消费回馈(站群)
|
||||
//OnceTask // 新手一次福利 4
|
||||
//DailyTask // 日常福利 5
|
||||
)
|
||||
|
||||
type TaskConfig struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 文档ID
|
||||
Title string `json:"title" bson:"title"` // 任务标题
|
||||
Img string `json:"img" bson:"img"` // 任务图片
|
||||
Desc string `json:"desc" bson:"desc"` // 任务描述
|
||||
FinishCondition int64 `json:"finishCondition" bson:"finishCondition"` // 达成条件
|
||||
Type ConfigType `json:"type" bson:"type"` // 配置类型
|
||||
Prizes []primitive.ObjectID `json:"prizes" bson:"prizes"` // 奖品列表
|
||||
Detail []TaskDetail `json:"detail" bson:"detail"` // 任务详情(进阶任务使用)
|
||||
Link string `json:"link" bson:"link"` // 跳转链接
|
||||
Status bool `json:"status" bson:"status"` // 启用/禁用
|
||||
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 修改时间
|
||||
CreateTime time.Time `json:"createTime" bson:"createTime"` // 创建时间
|
||||
}
|
||||
|
||||
type TaskDetail struct {
|
||||
Prize primitive.ObjectID `json:"prize" bson:"prize"` // 奖品
|
||||
SubTitle string `json:"subTitle"` // 子标题
|
||||
FinishCondition uint64 `json:"finishCondition" bson:"finishCondition"` // 达成条件
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package taskmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type AddConfigCond struct {
|
||||
Title string `json:"title"` // 任务标题
|
||||
Desc string `json:"desc"` // 任务描述
|
||||
//FinishCondition int64 `json:"finishCondition"` // 达成条件 Todo:连续签到多少天
|
||||
Type ConfigType `json:"type" binding:"required"` // 配置类型 1-购买金币
|
||||
//Prizes []primitive.ObjectID `json:"prizes"` // 奖品列表(暂时不需要)
|
||||
Img string `json:"img" bson:"img"` // 任务图片
|
||||
Detail []TaskDetail `json:"detail" bson:"detail"` // 任务详情(进阶任务使用)
|
||||
Link string `json:"link" bson:"link"` // 跳转链接
|
||||
Status bool `json:"status"` // 启用/禁用
|
||||
}
|
||||
|
||||
type ModifyConfigCond struct {
|
||||
ID primitive.ObjectID `json:"id"` // 任务id
|
||||
Title *string `json:"title"` // 任务标题
|
||||
Desc *string `json:"desc"` // 任务描述
|
||||
//FinishCondition int64 `json:"finishCondition"` // 达成条件 Todo:连续签到多少天
|
||||
Type *ConfigType `json:"type" binding:"required"` // 配置类型 1-购买金币
|
||||
//Prizes []primitive.ObjectID `json:"prizes"` // 奖品列表(暂时不需要)
|
||||
Img *string `json:"img" bson:"img"` // 任务图片
|
||||
Detail []TaskDetail `json:"detail" bson:"detail"` // 任务详情(进阶任务使用)
|
||||
Link *string `json:"link" bson:"link"` // 跳转链接
|
||||
Status *bool `json:"status"` // 启用/禁用
|
||||
}
|
||||
|
||||
func (m *ModifyConfigCond) Cond() primitive.M {
|
||||
return bson.M{"_id": m.ID}
|
||||
}
|
||||
|
||||
func (m *ModifyConfigCond) Bson() primitive.M {
|
||||
set := bson.M{"updateTime": time.Now()}
|
||||
//if m.FinishCondition != nil {
|
||||
// set["finishCondition"] = m.FinishCondition
|
||||
//}
|
||||
if m.Title != nil {
|
||||
set["title"] = m.Title
|
||||
}
|
||||
if m.Desc != nil {
|
||||
set["desc"] = m.Desc
|
||||
}
|
||||
if m.Type != nil {
|
||||
set["type"] = m.Type
|
||||
}
|
||||
//if len(m.Prizes) > 0 {
|
||||
// set["prizes"] = m.Prizes
|
||||
//}
|
||||
if len(m.Detail) > 0 {
|
||||
set["detail"] = m.Detail
|
||||
}
|
||||
if m.Img != nil {
|
||||
set["img"] = m.Img
|
||||
}
|
||||
if m.Img != nil {
|
||||
set["img"] = m.Img
|
||||
}
|
||||
if m.Link != nil {
|
||||
set["link"] = m.Link
|
||||
}
|
||||
if m.Status != nil {
|
||||
set["status"] = m.Status
|
||||
}
|
||||
return bson.M{"$set": set}
|
||||
}
|
||||
|
||||
type QueryAllConfigCond struct {
|
||||
Status *bool `form:"status,omitempty"` // 启用/禁用
|
||||
commod.Page
|
||||
}
|
||||
|
||||
func (q *QueryAllConfigCond) Options() *options.FindOptions {
|
||||
return options.Find().SetLimit(int64(q.PageSize)).SetSkip(int64((q.PageNumber - 1) * q.PageSize)).SetSort(bson.M{"finishCondition": 1})
|
||||
}
|
||||
|
||||
func (q *QueryAllConfigCond) Query() primitive.M {
|
||||
fliter := bson.M{}
|
||||
if q.Status != nil {
|
||||
fliter["status"] = q.Status
|
||||
}
|
||||
return fliter
|
||||
}
|
||||
Reference in New Issue
Block a user