116 lines
3.9 KiB
Go
116 lines
3.9 KiB
Go
package aichangefacemod
|
|
|
|
import (
|
|
"91porn-server/common/db"
|
|
"91porn-server/models/commod"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type AiChangeFaceWebResp struct {
|
|
ID primitive.ObjectID `json:"id"`
|
|
Uid uint64 `json:"uid"` // 用户
|
|
Pic []string `json:"picture"` // 换脸照片
|
|
ModId primitive.ObjectID `json:"modId"` // 视频模版id
|
|
ModUrl string `json:"modUrl"` // 视频模版播放地址url
|
|
ModTitle string `json:"modTitle"` // 模版标题
|
|
Coin int64 `json:"coin"` // 普通金币数
|
|
IncomeCoin int64 `json:"incomeCoin"` // 可提现金币数
|
|
Status AiChangeFaceStatus `json:"status"` // 0 未完成; 1 已完成; -1 已退款
|
|
Cover string `json:"cover"` // 换脸后封面大图
|
|
Url string `json:"url"` // 换脸后视频地址
|
|
Remark string `json:"remark"` // 拒绝理由
|
|
Operator string `json:"operator"` // 操作员
|
|
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
|
UpdatedAt time.Time `json:"updatedAt"` // 刷新时间
|
|
}
|
|
|
|
type ListRequest struct {
|
|
ID *string `form:"id" json:"id"`
|
|
Uid *uint64 `form:"uid" json:"uid"`
|
|
Status *AiChangeFaceStatus `form:"status" json:"status"`
|
|
VidID *string `form:"vidId" json:"vidId"`
|
|
commod.Page
|
|
}
|
|
|
|
type EditAiChangeFace struct {
|
|
ID primitive.ObjectID `json:"id" binding:"required"` // 被编辑的ai换脸id
|
|
Status *AiChangeFaceStatus `json:"status"` // 0 未完成; 1 已完成; -1 已退款 2 已经提交
|
|
Cover *string `json:"cover"` // 换脸后封面大图
|
|
Url *string `json:"url"` // 换脸后视频地址
|
|
Remark *string `json:"remark"` // 拒绝理由
|
|
Title *string `json:"title"` // 标题
|
|
}
|
|
|
|
func (receiver *EditAiChangeFace) Update(updateAct string) bson.M {
|
|
var update = bson.M{}
|
|
if receiver.Url != nil {
|
|
update["url"] = receiver.Url
|
|
}
|
|
if receiver.Cover != nil {
|
|
update["cover"] = receiver.Cover
|
|
}
|
|
if receiver.Status != nil {
|
|
update["status"] = receiver.Status
|
|
}
|
|
if receiver.Remark != nil {
|
|
update["remark"] = receiver.Remark
|
|
}
|
|
update["operator"] = updateAct
|
|
update["updatedAt"] = time.Now()
|
|
return bson.M{"$set": update}
|
|
}
|
|
|
|
func WebList(id *primitive.ObjectID, uid *uint64, status *AiChangeFaceStatus, vidId *string, skip, limit int) ([]AiChangeFace, int64, error) {
|
|
cond := bson.M{}
|
|
if id != nil {
|
|
cond["_id"] = *id
|
|
}
|
|
if uid != nil {
|
|
cond["uid"] = *uid
|
|
}
|
|
if status != nil {
|
|
cond["status"] = *status
|
|
}
|
|
if vidId != nil {
|
|
vidObjId, _ := primitive.ObjectIDFromHex(*vidId)
|
|
cond["vidId"] = vidObjId
|
|
}
|
|
count, err := coll(nil).Count(cond)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
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))
|
|
}
|
|
return acfs, count, coll(nil).Find(&acfs, cond, opts)
|
|
}
|
|
|
|
func Update(t *db.MongoTool, id primitive.ObjectID, set bson.M) error {
|
|
_, err := coll(t).UpdateOne(bson.M{"_id": id}, set)
|
|
return err
|
|
}
|
|
|
|
// TransitionStatus atomically changes an order from the expected status. The
|
|
// returned boolean is false when another worker or callback handled it first.
|
|
func TransitionStatus(t *db.MongoTool, id primitive.ObjectID, from, to AiChangeFaceStatus, set bson.M) (bool, error) {
|
|
if set == nil {
|
|
set = bson.M{}
|
|
}
|
|
set["status"] = to
|
|
set["updatedAt"] = time.Now()
|
|
result, err := coll(t).UpdateOne(bson.M{"_id": id, "status": from}, bson.M{"$set": set})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return result.ModifiedCount == 1, nil
|
|
}
|