@@ -0,0 +1,177 @@
|
||||
package aichangefaceimgmod
|
||||
|
||||
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"
|
||||
"time"
|
||||
)
|
||||
|
||||
const table = models.AiChangeFaceImg
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// InitARDIndex 设置账户充值流水表索引
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{Key: "uid", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: -1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "status", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("AiUnDressIndex err+%v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// Insert 插入一条订单
|
||||
func Insert(a *AiChangeFaceImg) error {
|
||||
a.CreatedAt = time.Now()
|
||||
a.UpdatedAt = a.CreatedAt
|
||||
res, err := coll(nil).InsertOne(a)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-Insert]==> Model %s InsertOne fail error:%+v:", table, err))
|
||||
return err
|
||||
}
|
||||
a.ID, _ = res.InsertedID.(primitive.ObjectID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertOne(mt *db.MongoTool, cfg AiChangeFaceImg) error {
|
||||
if _, err := coll(mt).InsertOne(cfg); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-InsertOne]==> Model %s InsertOne fail error:%+v:", table, err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOrders 查询AI换脸订单
|
||||
func FindOrders(cond bson.M, opts *options.FindOptions) (int64, []*AiChangeFaceImg, error) {
|
||||
data := make([]*AiChangeFaceImg, 0)
|
||||
if err := coll(nil).Find(&data, cond, opts); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-FindOrders]==> Model %s Find fail error:%+v:", table, err),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return 0, data, err
|
||||
}
|
||||
total, err := coll(nil).Count(cond)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-FindOrders]==> Model %s Count fail error:%+v:", table, err),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return total, data, err
|
||||
}
|
||||
return total, data, nil
|
||||
}
|
||||
|
||||
// Update 修改订单
|
||||
func Update(t *db.MongoTool, id primitive.ObjectID, set bson.M) error {
|
||||
set["updatedAt"] = time.Now()
|
||||
if _, err := coll(t).UpdateOne(bson.M{"_id": id}, bson.M{"$set": set}); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-Update]==> Model %s UpdateOne fail error:%+v:", table, err),
|
||||
log.Any("id", id),
|
||||
log.Any("set", set),
|
||||
)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 int, 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
|
||||
}
|
||||
|
||||
// Edit 修改文档
|
||||
func Edit(t *db.MongoTool, filter, update primitive.M) error {
|
||||
result, err := coll(t).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-Edit]==> Model %s UpdateOne fail error:%+v:", table, err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount == 0 {
|
||||
log.Error(fmt.Sprintf("[METHOD-Edit]==> Model %s result.ModifiedCount fail error: ModifiedCount is zero", table),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return errors.New("result is null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindDataByID 根据ID查询
|
||||
func FindDataByID(id string) (AiChangeFaceImg, error) {
|
||||
objID, err := primitive.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-FindDataByID]==> Model %s ObjectIDFromHex fail error:%+v:", table, err),
|
||||
log.Any("id", id),
|
||||
)
|
||||
return AiChangeFaceImg{}, err
|
||||
}
|
||||
var aud AiChangeFaceImg
|
||||
if err = coll(nil).FindOne(&aud, bson.M{"_id": objID}); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-FindDataByID]==> Model %s FindOne fail error:%+v:", table, err),
|
||||
log.Any("objID", objID),
|
||||
)
|
||||
return aud, err
|
||||
}
|
||||
return aud, nil
|
||||
}
|
||||
|
||||
// QueryAllDocument 分页查询文档
|
||||
func QueryAllDocument(filter primitive.M, opts ...*options.FindOptions) ([]*AiChangeFaceImg, error) {
|
||||
var out []*AiChangeFaceImg
|
||||
if err := coll(nil).Find(&out, filter, opts...); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-QueryAllDocument]==> Model %s Find fail error:%+v:", table, err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// CountDocument 查询文档条目数
|
||||
func CountDocument(filter primitive.M) (int64, error) {
|
||||
count, err := coll(nil).Count(filter)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-CountDocument]==> Model %s Count fail error:%+v:", table, err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func FindByID(t *db.MongoTool, id primitive.ObjectID) (*AiChangeFaceImg, error) {
|
||||
var acf AiChangeFaceImg
|
||||
return &acf, coll(t).FindOne(&acf, bson.M{"_id": id})
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package aichangefaceimgmod
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// AiChangFaceImgAppRes AI记录 App返回给前端
|
||||
type AiChangFaceImgAppRes struct {
|
||||
UID uint64 `json:"uid" bson:"uid"` // 用户id
|
||||
OriginPic string `json:"originPic" bson:"originPic"` // 脱衣原图
|
||||
NewPic []string `json:"newPic" bson:"newPic"` // 脱衣后新图
|
||||
Status int `json:"status" bson:"status"` // 1、进行中 2、生成成功 3、生成失败
|
||||
Remark string `json:"remark" bson:"remark"` // 备注
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 刷新时间
|
||||
}
|
||||
|
||||
type ListRequest struct {
|
||||
Status *int `form:"status" json:"status" bson:"status"` // 1、进行中 2、生成成功 3、生成失败
|
||||
commod.Page
|
||||
}
|
||||
|
||||
func (receiver *ListRequest) Filter(uid uint64) primitive.M {
|
||||
filter := bson.M{}
|
||||
if receiver.Status != nil {
|
||||
filter["status"] = receiver.Status
|
||||
if *receiver.Status == 1 {
|
||||
filter["status"] = bson.M{"$in": []int{Processing, StatusSubmit}}
|
||||
}
|
||||
}
|
||||
filter["uid"] = uid
|
||||
filter["isHide"] = bson.M{"$in": []any{nil, false}}
|
||||
return filter
|
||||
}
|
||||
|
||||
func (receiver *ListRequest) Options() *options.FindOptions {
|
||||
return options.Find().SetSkip(int64(receiver.Skip())).SetLimit(int64(receiver.Limit())).SetSort(bson.M{"fakeLikeCount": -1})
|
||||
}
|
||||
|
||||
type GenerateRequest struct {
|
||||
OriginPic string `json:"originPic" bson:"originPic" binding:"required"` // 换脸原图
|
||||
MId string `json:"mId" bson:"mId" binding:"required"` // 模版ID
|
||||
IsFreeTimes bool `json:"isFreeTimes" bson:"isFreeTimes"` // 是否使用免费次数
|
||||
Coin int64 `json:"coin" bson:"coin"` // 此次脱衣金币个数
|
||||
ShareTitle string `json:"shareTitle" bson:"shareTitle"` // 分享标题
|
||||
ShareStatus int `json:"shareStatus" bson:"shareStatus"` // 是否分享 0-不分享 1-分享
|
||||
|
||||
}
|
||||
|
||||
func (receiver *GenerateRequest) Generate(orderId primitive.ObjectID, createdAt time.Time, uid uint64, modTitle, modPic string, privilegeCount, debitFreeCount, debitCoins, debitIncomeCoins int64) AiChangeFaceImg {
|
||||
isFreeTimes := false
|
||||
if debitFreeCount > 0 {
|
||||
isFreeTimes = true
|
||||
}
|
||||
if privilegeCount > 0 {
|
||||
isFreeTimes = true
|
||||
}
|
||||
return AiChangeFaceImg{
|
||||
ID: orderId,
|
||||
Coin: debitIncomeCoins + debitCoins,
|
||||
DebitAmountCoin: debitCoins,
|
||||
DebitIncomeCoin: debitIncomeCoins,
|
||||
IsFreeTimes: isFreeTimes,
|
||||
Count: debitFreeCount + privilegeCount,
|
||||
OriginPic: receiver.OriginPic,
|
||||
MId: receiver.MId,
|
||||
ModTitle: modTitle,
|
||||
ModPic: modPic,
|
||||
UID: uid,
|
||||
Status: Processing,
|
||||
IsHide: false,
|
||||
ShareTitle: receiver.ShareTitle,
|
||||
ShareStatus: receiver.ShareStatus,
|
||||
UpdatedAt: createdAt,
|
||||
CreatedAt: createdAt,
|
||||
}
|
||||
}
|
||||
|
||||
type DelRequest struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"id"` // AI订单ID
|
||||
}
|
||||
|
||||
func (receiver *DelRequest) Filter() primitive.M {
|
||||
filter := bson.M{}
|
||||
filter["_id"] = receiver.ID
|
||||
return filter
|
||||
}
|
||||
|
||||
func (receiver *DelRequest) Update() primitive.M {
|
||||
update := bson.M{}
|
||||
update["isHide"] = true
|
||||
update["updatedAt"] = time.Now()
|
||||
return bson.M{"$set": update}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package aichangefaceimgmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
Processing = 1 // 1、进行中
|
||||
SUCCESS = 2 // 2、成功
|
||||
FAILURE = 3 // 3、失败
|
||||
REFUND = 4 // 4、退款
|
||||
StatusSubmit = 5 //5,提交
|
||||
)
|
||||
|
||||
type Status int
|
||||
|
||||
var status = map[Status]string{
|
||||
Processing: "processing",
|
||||
FAILURE: "failure",
|
||||
SUCCESS: "success",
|
||||
REFUND: "refund",
|
||||
}
|
||||
|
||||
func (s Status) Desc() string {
|
||||
if desc, ok := status[s]; ok {
|
||||
return desc
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
// AiChangeFaceImg AI图片换脸
|
||||
type AiChangeFaceImg struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 脱衣记录id
|
||||
UID uint64 `json:"uid" bson:"uid"` // 用户id
|
||||
OriginPic string `json:"originPic" bson:"originPic"` // AI换脸原图
|
||||
MId string `json:"mId" bson:"mId"` // AI换脸模版图ID
|
||||
ModTitle string `json:"modTitle" bson:"modTitle"` // AI换脸模标题
|
||||
ModPic string `json:"modPic" bson:"modPic"` // AI换脸模版图
|
||||
NewPic []string `json:"newPic" bson:"newPic"` // AI换脸后新图
|
||||
Coin int64 `json:"coin" bson:"coin"` // 此次AI换脸金币个数
|
||||
DebitAmountCoin int64 `json:"debitAmountCoin" bson:"debitAmountCoin"` // 此次AI换脸扣除金币个数
|
||||
DebitIncomeCoin int64 `json:"debitIncomeCoin" bson:"debitIncomeCoin"` // 此次AI换脸扣除收益金币个数
|
||||
Status int `json:"status" bson:"status"` // 1、进行中 2、生成成功 3、生成失败
|
||||
Remark string `json:"remark" bson:"remark"` // 备注
|
||||
Count int64 `json:"count" bson:"count"` // 此次AI换脸AI换脸消耗次数
|
||||
IsFreeTimes bool `json:"isFreeTimes" bson:"isFreeTimes"` // 是否使用免费次数
|
||||
IsHide bool `json:"isHide" bson:"isHide"` // 是否被用户隐藏(用户订单列表是否不显示)
|
||||
UpdateAct string `json:"updateAct" bson:"updateAct"` // 修改账号
|
||||
ShareTitle string `json:"shareTitle" bson:"shareTitle"` // 分享标题
|
||||
ShareStatus int `json:"shareStatus" bson:"shareStatus"` // 是否分享 0-不分享 1-分享
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 刷新时间
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package aichangefaceimgmod
|
||||
|
||||
import (
|
||||
"91porn-server/models/commod"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RechargeUpdateReq 修改参数
|
||||
type RechargeUpdateReq struct {
|
||||
StatusDesc *string `json:"statusDesc" bson:"statusDesc"` // 状态描述
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
type RchgQueryReq struct {
|
||||
ID *string `form:"id" json:"_id,omitempty" bson:"_id"` // 流水id
|
||||
UID *uint64 `form:"uid" json:"uid,omitempty" bson:"uid"` // 用户id
|
||||
Status *int `form:"status" json:"status,omitempty" bson:"status"` // 1、进行中 2、生成成功 3、生成失败 4、已经退款
|
||||
}
|
||||
|
||||
type WebListRequest struct {
|
||||
Status *int `form:"status" json:"status" bson:"status"` // 1、进行中 2、生成成功 3、生成失败 4、已经退款
|
||||
UID *uint64 `form:"uid" json:"uid,omitempty" bson:"uid"` // 用户id
|
||||
ID *string `form:"id" json:"_id,omitempty" bson:"_id"` // 流水id
|
||||
MId *string `form:"mId" json:"mId,omitempty" bson:"_id"` // AI模版id
|
||||
commod.Page
|
||||
}
|
||||
|
||||
func (receiver *WebListRequest) Filter() primitive.M {
|
||||
filter := bson.M{}
|
||||
if receiver.Status != nil {
|
||||
filter["status"] = receiver.Status
|
||||
}
|
||||
if receiver.UID != nil {
|
||||
filter["uid"] = receiver.UID
|
||||
}
|
||||
if receiver.MId != nil {
|
||||
filter["mId"] = receiver.MId
|
||||
}
|
||||
if receiver.ID != nil {
|
||||
id, _ := primitive.ObjectIDFromHex(*receiver.ID)
|
||||
filter["_id"] = id
|
||||
}
|
||||
return filter
|
||||
}
|
||||
|
||||
func (receiver *WebListRequest) Options() *options.FindOptions {
|
||||
return options.Find().SetSkip(int64(receiver.Skip())).SetLimit(int64(receiver.Limit() + 1)).SetSort(bson.M{"updatedAt": -1})
|
||||
}
|
||||
|
||||
type EditCond struct {
|
||||
ID string `json:"id" binding:"required"` // 文档
|
||||
NewPic *[]string `json:"newPic" bson:"newPic"` // AI图片换脸后新图
|
||||
Status *int `json:"status" bson:"status"` // 状态 1、进行中 2、生成成功 3、生成失败
|
||||
Remark *string `json:"remark" bson:"remark"` // 拒绝理由
|
||||
}
|
||||
|
||||
func (receiver *EditCond) Filter() bson.M {
|
||||
objID, _ := primitive.ObjectIDFromHex(receiver.ID)
|
||||
return bson.M{"_id": objID}
|
||||
}
|
||||
|
||||
func (receiver *EditCond) Update(updateAct string) bson.M {
|
||||
var update = bson.M{}
|
||||
if receiver.NewPic != nil {
|
||||
update["newPic"] = receiver.NewPic
|
||||
}
|
||||
if receiver.Status != nil {
|
||||
update["status"] = receiver.Status
|
||||
}
|
||||
if receiver.Remark != nil {
|
||||
update["remark"] = receiver.Remark
|
||||
}
|
||||
update["updateAct"] = updateAct
|
||||
update["updatedAt"] = time.Now()
|
||||
return bson.M{"$set": update}
|
||||
}
|
||||
Reference in New Issue
Block a user