@@ -0,0 +1,33 @@
|
||||
package vipconfigmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
type VIPConfig struct {
|
||||
ID int `json:"-" bson:"_id,omitempty"`
|
||||
VipUpPrice int64 `json:"vipUpPrice" bson:"vipUpPrice"` //vip升级价格
|
||||
SVipUpPrice int64 `json:"sVipUpPrice" bson:"sVipUpPrice"` //svip升级价格
|
||||
VipUpCheapPrice int64 `json:"vipUpCheapPrice" bson:"vipUpCheapPrice"` //vip升级节省价格
|
||||
SVipUpCheapPrice int64 `json:"sVipUpCheapPrice" bson:"sVipUpCheapPrice"` //svip升级节省价格
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` //创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //修改时间
|
||||
TimeConfig int64 `json:"timeConfig" bson:"timeConfig"` //时间配置
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
}
|
||||
|
||||
type EditSelector struct {
|
||||
VipUpPrice *int64 `json:"vipUpPrice,omitempty" bson:"vipUpPrice,omitempty"` //vip升级价格
|
||||
SVipUpPrice *int64 `json:"sVipUpPrice,omitempty" bson:"sVipUpPrice,omitempty"` //svip升级价格
|
||||
VipUpCheapPrice *int64 `json:"vipUpCheapPrice,omitempty" bson:"vipUpCheapPrice,omitempty"` //vip升级节省价格
|
||||
SVipUpCheapPrice *int64 `json:"sVipUpCheapPrice,omitempty" bson:"sVipUpCheapPrice,omitempty"` //svip升级节省价格
|
||||
TimeConfig *int64 `json:"timeConfig,omitempty" bson:"timeConfig,omitempty"` //时间配置
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //修改时间
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package vipconfigmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
const table = models.VipConfig
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
func FindOne() (c VIPConfig, err error) {
|
||||
err = coll(nil).FindOne(&c, bson.M{"_id": 1})
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetByID", table, "FindOne", err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//todo app
|
||||
|
||||
// todo web
|
||||
// InsertVIP 插入一条数据
|
||||
func Update(set EditSelector) error {
|
||||
now := time.Now()
|
||||
set.UpdatedAt = now
|
||||
_, err := coll(nil).UpsertOne(bson.M{"_id": 1}, bson.M{"$set": set, "$setOnInsert": bson.M{"createdAt": set.UpdatedAt}})
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Update", table, "UpsertOne", err))
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user