@@ -0,0 +1,56 @@
|
||||
package active2023mod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
const active2023LotteryFreeInc = models.Active2023FreeLotteryInc // 用户免费次数新增表
|
||||
|
||||
func initFreeIndex() {
|
||||
coll := active2023LotteryFreeIncColl(nil)
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{Key: "uid", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", active2023PrizeTable, err))
|
||||
}
|
||||
}
|
||||
|
||||
func active2023LotteryFreeIncColl(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(active2023LotteryFreeInc)
|
||||
}
|
||||
return t.Coll(active2023LotteryFreeInc)
|
||||
}
|
||||
|
||||
// 添加免费次数
|
||||
func AddLotteryCountFree(t *db.MongoTool, uid int64, fi FreeLotteryInc) error {
|
||||
f := bson.M{"uid": uid}
|
||||
now := time.Now()
|
||||
update := bson.M{"$inc": bson.M{"lotteryRemain": fi.Count}, "$set": bson.M{"updatedAt": now}}
|
||||
result, err := active2023UserColl(t).UpdateOne(f, update)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount != 1 {
|
||||
if _, err := active2023UserColl(t).InsertOne(&UserActive2023{
|
||||
UID: uid,
|
||||
LotteryRemain: fi.Count,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = active2023LotteryFreeIncColl(t).InsertOne(fi)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user