Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+198
View File
@@ -0,0 +1,198 @@
package aiUnDressmod
import (
"errors"
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"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"
)
const table = models.AiUnDress
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 *AiUnDress) 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 AiUnDress) 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 查询脱衣订单
func FindOrders(cond bson.M, opts *options.FindOptions) (int64, []*AiUnDress, error) {
data := make([]*AiUnDress, 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) (AiUnDress, 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 AiUnDress{}, err
}
var aud AiUnDress
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) ([]*AiUnDress, error) {
var out []*AiUnDress
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) (*AiUnDress, error) {
var acf AiUnDress
return &acf, coll(t).FindOne(&acf, bson.M{"_id": id})
}
func InsertMany(mt *db.MongoTool, cfg []AiUnDress) error {
if _, err := coll(mt).InsertMany(cfg); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertMany", table, "InsertMany", err))
return err
}
return nil
}
// 更新订单提交状态
func SubmitStatus(id string, status int, remark string) error {
_id, err := primitive.ObjectIDFromHex(id)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-SubmitStatus]==> Model %s ObjectIDFromHex fail error:%+v:", table, err), log.Any("id", id))
return err
}
_, err = coll(nil).UpdateOne(bson.M{"_id": _id}, bson.M{"$set": bson.M{"status": status, "newPic": nil, "remark": remark}})
return err
}
+165
View File
@@ -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}
}
+64
View File
@@ -0,0 +1,64 @@
package aiUnDressmod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const (
Processing = 1 // 1、进行中
SUCCESS = 2 // 2、成功
FAILURE = 3 // 3、失败
REFUND = 4 // 4、退款
PartSuccess = 5 // 5、部分成功
SubmitOrder = 6 // 6、已提交
)
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
// AiUnDress AI脱衣
type AiUnDress struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 脱衣记录id
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"` // 此次脱衣金币个数
DebitAmountCoin int64 `json:"debitAmountCoin" bson:"debitAmountCoin"` // 此次脱衣扣除金币个数
DebitIncomeCoin int64 `json:"debitIncomeCoin" bson:"debitIncomeCoin"` // 此次脱衣扣除收益金币个数
Status int `json:"status" bson:"status"` // 1、进行中 2、生成成功 3、生成失败 4、退款 5、部分成功 6、已提交
Count int64 `json:"count" bson:"count"` // 此次ai脱衣消耗次数
IsFreeTimes bool `json:"isFreeTimes" bson:"isFreeTimes"` // 是否使用免费次数
IsHide bool `json:"isHide" bson:"isHide"` // 是否被用户隐藏(用户订单列表是否不显示)
Remark string `json:"remark" bson:"remark"` // 备注
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()
}
+105
View File
@@ -0,0 +1,105 @@
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"
)
// 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
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.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"` // 脱衣后新图
Status *int `json:"status" bson:"status"` // 状态 1、进行中 2、生成成功 3、生成失败
Remark *string `json:"remark" bson:"remark"` // 拒绝理由
}
type AutoCond struct {
ID string `json:"id" binding:"required"` // 文档
}
type AutoBatchCond struct {
IDs []string `json:"ids" from:"ids" binding:"required"` // 文档
Pass bool `json:"pass" from:"pass"` // 是否通过
Remark string `json:"remark" from:"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}
}
type AiUndressOrderReq struct {
AppId int `json:"appId"`
FileUrl []string `json:"fileUrl"` //base64存的文件服地址
UserId string `json:"userId"` //用户id
AppOrderNum string `json:"appOrderNum"` //app中生成的订单号
NotifyUrl string `json:"notifyUrl"` //回调产品地址
}
type AiUndressOrderResp struct {
Code int `json:"code"`
}
type CallBackReq struct {
ImgUrl []string `json:"imgUrl"` //脱衣后地址
AppOrderNum string `json:"appOrderNum"` //app订单号
Msg string `json:"msg"` //消息
}