@@ -0,0 +1,165 @@
|
||||
package aiUnDressmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// AiUnDressAppRes AI记录 App返回给前端
|
||||
type AiUnDressAppRes struct {
|
||||
UID uint64 `json:"uid" bson:"uid"` // 用户id
|
||||
OriginPic string `json:"originPic" bson:"originPic"` // 脱衣原图
|
||||
OriginPics []string `json:"originPics" bson:"originPics"` // 脱衣原图多张
|
||||
NewPic []string `json:"newPic" bson:"newPic"` // 脱衣后新图
|
||||
Coin int64 `json:"coin" bson:"coin"` // 此次脱衣金币个数
|
||||
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 {
|
||||
if *receiver.Status == Processing {
|
||||
filter["status"] = bson.M{"$in": []int{Processing, SubmitOrder}}
|
||||
} else {
|
||||
filter["status"] = receiver.Status
|
||||
}
|
||||
}
|
||||
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{"updatedAt": -1})
|
||||
}
|
||||
|
||||
type GenerateRequest struct {
|
||||
OriginPic []string `json:"originPic" bson:"originPic"` // 脱衣原图
|
||||
Coin int64 `json:"coin" bson:"coin"` // 此次脱衣金币个数
|
||||
IsFreeTimes bool `json:"isFreeTimes" bson:"isFreeTimes"` // 是否使用免费次数
|
||||
ShareTitle string `json:"shareTitle"` // 分享标题
|
||||
ShareStatus int `json:"shareStatus" bson:"shareStatus"` // 是否分享 0-不分享 1-分享
|
||||
}
|
||||
|
||||
//func (receiver *GenerateRequest) Generate(uid uint64) AiUnDress {
|
||||
// now := time.Now()
|
||||
// return AiUnDress{
|
||||
// OriginPic: receiver.OriginPic,
|
||||
// UID: uid,
|
||||
// Coin: receiver.Coin,
|
||||
// Status: Processing,
|
||||
// IsHide: false,
|
||||
// UpdatedAt: now,
|
||||
// CreatedAt: now,
|
||||
// }
|
||||
//}
|
||||
|
||||
func (receiver *GenerateRequest) GenerateMany(orderId primitive.ObjectID, orderCreatedAt time.Time, uid uint64, privilegeCount, debitFreeCount, debitCoins, debitIncomeCoins, singeCoin int64, shareTitle string, shareStatus int) []AiUnDress {
|
||||
var generateAiUnDress []AiUnDress
|
||||
if len(receiver.OriginPic) > 0 {
|
||||
p := receiver.OriginPic[0]
|
||||
//for _, p := range receiver.OriginPic {
|
||||
var (
|
||||
picture []string
|
||||
newCoin int64
|
||||
newDebitAmountCoin int64
|
||||
newDebitIncomeCoin int64
|
||||
newDebitFreeCount int64
|
||||
isFreeTimes bool
|
||||
)
|
||||
picture = append(picture, p)
|
||||
|
||||
if debitFreeCount > 0 {
|
||||
isFreeTimes = true
|
||||
newDebitFreeCount = 1
|
||||
// 免费次数减一
|
||||
debitFreeCount--
|
||||
} else if privilegeCount > 0 {
|
||||
isFreeTimes = true
|
||||
newDebitFreeCount = 1
|
||||
privilegeCount--
|
||||
} else {
|
||||
if debitCoins > 0 {
|
||||
newDebitAmountCoin = min(singeCoin, debitCoins)
|
||||
debitCoins -= newDebitAmountCoin
|
||||
newCoin += newDebitAmountCoin
|
||||
} else {
|
||||
newDebitIncomeCoin = min(singeCoin, debitIncomeCoins)
|
||||
debitIncomeCoins -= newDebitIncomeCoin
|
||||
newCoin += debitIncomeCoins
|
||||
}
|
||||
if newCoin < singeCoin {
|
||||
if debitCoins >= singeCoin-newCoin {
|
||||
new2DebitAmountCoin := min(singeCoin-newCoin, debitCoins)
|
||||
debitCoins -= new2DebitAmountCoin
|
||||
newDebitAmountCoin += new2DebitAmountCoin
|
||||
newCoin += new2DebitAmountCoin
|
||||
} else {
|
||||
new2DebitIncomeCoin := min(singeCoin-newCoin, debitIncomeCoins)
|
||||
debitIncomeCoins -= new2DebitIncomeCoin
|
||||
newDebitIncomeCoin += new2DebitIncomeCoin
|
||||
newCoin += new2DebitIncomeCoin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generateAiUnDress = append(generateAiUnDress, AiUnDress{
|
||||
ID: orderId,
|
||||
OriginPics: picture,
|
||||
Coin: newDebitAmountCoin + newDebitIncomeCoin,
|
||||
DebitAmountCoin: newDebitAmountCoin,
|
||||
DebitIncomeCoin: newDebitIncomeCoin,
|
||||
IsFreeTimes: isFreeTimes,
|
||||
Count: newDebitFreeCount,
|
||||
UID: uid,
|
||||
Status: Processing,
|
||||
IsHide: false,
|
||||
ShareTitle: shareTitle,
|
||||
ShareStatus: shareStatus,
|
||||
UpdatedAt: orderCreatedAt,
|
||||
CreatedAt: orderCreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
return generateAiUnDress
|
||||
}
|
||||
|
||||
// 定义一个函数,用来返回两个整数中的较小值
|
||||
func min(a, b int64) int64 {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
Reference in New Issue
Block a user