95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package aichangefacemod
|
|
|
|
import (
|
|
"91porn-server/common/aiService"
|
|
"91porn-server/common/db"
|
|
"91porn-server/models"
|
|
"fmt"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
var mdb *db.MongoDB
|
|
|
|
const table = models.AiChangeFace
|
|
|
|
func coll(t *db.MongoTool) *db.MongoTool {
|
|
if t == nil {
|
|
return mdb.Coll(table)
|
|
}
|
|
return t.Coll(table)
|
|
}
|
|
|
|
func Init() {
|
|
mdb = db.Init(table)
|
|
initIndex()
|
|
}
|
|
|
|
func initIndex() {
|
|
many := []mongo.IndexModel{
|
|
{
|
|
Keys: bson.D{{Key: "uid", Value: 1}},
|
|
},
|
|
}
|
|
if _, err := coll(nil).CreateIndex(many); err != nil {
|
|
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
|
}
|
|
}
|
|
|
|
func AddAiChangeFace(t *db.MongoTool, orderId primitive.ObjectID, orderCreatedAt time.Time, uid uint64, pic []string, vidMod aiService.Template, coin, incomeCoin int64, discount []primitive.ObjectID, shareTitle string, shareStatus int) error {
|
|
_, err := coll(t).InsertOne(AiChangeFace{
|
|
ID: orderId,
|
|
Uid: uid,
|
|
Pic: pic,
|
|
VidID: vidMod.ID,
|
|
ModTitle: vidMod.Title,
|
|
ModCover: vidMod.Cover,
|
|
ModVideo: vidMod.M3u8Url,
|
|
Coin: coin,
|
|
IncomeCoin: incomeCoin,
|
|
Discount: discount,
|
|
Status: StatusGenning,
|
|
IsHide: false,
|
|
Cover: "",
|
|
Url: "",
|
|
ShareTitle: shareTitle,
|
|
ShareStatus: shareStatus,
|
|
CreatedAt: orderCreatedAt,
|
|
UpdatedAt: orderCreatedAt,
|
|
})
|
|
return err
|
|
}
|
|
|
|
func ListByUid(uid uint64, status *AiChangeFaceStatus, skip, limit int) ([]AiChangeFace, error) {
|
|
var acfs []AiChangeFace
|
|
opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}})
|
|
if skip > 0 {
|
|
opts.SetSkip(int64(skip))
|
|
}
|
|
if limit > 0 {
|
|
opts.SetLimit(int64(limit))
|
|
}
|
|
cond := bson.M{"uid": uid, "isHide": bson.M{"$in": []any{nil, false}}}
|
|
if status != nil {
|
|
cond["status"] = *status
|
|
if *status == StatusGenning {
|
|
cond["status"] = bson.M{"$in": []int{0, 2}}
|
|
}
|
|
}
|
|
return acfs, coll(nil).Find(&acfs, cond, opts)
|
|
}
|
|
|
|
func Hide(uid uint64, id primitive.ObjectID) error {
|
|
_, err := coll(nil).UpdateOne(bson.M{"uid": uid, "_id": id}, bson.M{"$set": bson.M{"isHide": true}})
|
|
return err
|
|
}
|
|
|
|
func FindByID(t *db.MongoTool, id primitive.ObjectID) (*AiChangeFace, error) {
|
|
var acf AiChangeFace
|
|
return &acf, coll(t).FindOne(&acf, bson.M{"_id": id})
|
|
}
|