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
+246
View File
@@ -0,0 +1,246 @@
package walletctrl
import (
"91porn-server/app/service/walletser"
"91porn-server/common"
"91porn-server/common/stderr"
"91porn-server/models/commod"
"91porn-server/models/l/payvidlgmod"
"91porn-server/models/v/txnmod"
"91porn-server/models/v/usermod"
"github.com/gin-gonic/gin"
)
// GetBill doc
// @Summary --我的账单
// @Description 我的账单
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Param pageNumber formData int true "页码"
// @Param pageSize formData int true "条数"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/mine/bills [get]
func GetBill(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var arg struct {
Timestamp int64 `form:"timeline"`
}
if err = ctx.ShouldBind(&arg); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, hasNext, nextTimeline, err := walletser.GetBills(uid, arg.Timestamp)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
common.ServeJSON(ctx, stderr.Success, gin.H{
"hasNext": hasNext,
"list": data,
"timeline": nextTimeline,
})
}
// GetNewBill doc
// @Summary --我的账单新
// @Description 我的账单
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Param year query string true "年"
// @Param month query string true "月"
// @Param pageNumber query int true "页码"
// @Param pageSize query int true "条数"
// @Success 200 {object} txnmod.Bills1Res "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/mine/zhangdan [get]
func GetNewBill(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var arg struct {
Month int `form:"month"`
Year int `form:"year"`
commod.Page
}
if err = ctx.ShouldBind(&arg); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, err := walletser.GetBills1(uid, arg.Year, arg.Month, arg.PageNumber, arg.PageSize)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
// GetWorksIncome doc
// @Summary 我的作品--帖子收入记录详情
// @Description 查询收入记录详情
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Param pageNumber formData int true "页码"
// @Param pageSize formData int true "条数"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/mine/income/works [get]
func GetWorksIncome(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var page commod.Page
if err = ctx.ShouldBind(&page); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
//total, totalAmount, data, hasNext, err := payvidlgmod.FindThreeMonthVideoPayRecord(uid, arg.PageNumber, arg.PageSize)
//if err != nil {
// common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
// return
//}
//common.ServeJSON(ctx, stderr.Success, gin.H{
// "total": total,
// "totalIncome": totalAmount,
// "history": data,
// "list": data,
// "hasNext": hasNext,
//})
list, next, err := payvidlgmod.GetWorksIncomeList(uid, page)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, nil)
return
}
common.ServeJSON(ctx, stderr.Success, gin.H{
"list": list,
"hasNext": next,
})
}
// GetIncome doc
// @Summary --收益明细
// @Description 收益明细
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Param startTime query string false "开始时间"
// @Param endTime query string false "结束时间"
// @Param pageNumber formData int true "页码"
// @Param pageSize formData int true "条数"
// @Success 200 {object} txnmod.TransactionLog "{"list": [],"hasNext":false}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /app/mine/iIncomes [get]
func GetIncome(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var arg struct {
commod.Page
}
if err = ctx.ShouldBind(&arg); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
data, hasNext, err := txnmod.FindIncome(uid, arg.PageNumber, arg.PageSize)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
var rechargeIds []uint64
for _, d := range data {
rechargeIds = append(rechargeIds, d.RechargeId)
}
if len(rechargeIds) > 0 {
// 获取用户信息
users, err := usermod.FindUsersMapByUID(rechargeIds)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
mUser := make(map[uint64]*txnmod.RechargeUserInfo)
if len(users) > 0 {
for _, u := range users {
ru := txnmod.RechargeUserInfo{
UID: u.UID,
Name: u.Name,
Portrait: u.Portrait,
}
mUser[u.UID] = &ru
}
}
for _, d := range data {
if d.RechargeId != 0 {
d.RechargeUser = *mUser[d.RechargeId]
}
}
}
common.ServeJSON(ctx, stderr.Success, gin.H{
"list": data,
"hasNext": hasNext,
})
}
// GetAllIncome doc
// @Summary --收益明细
// @Description 收益明细
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Param startTime query string false "开始时间"
// @Param endTime query string false "结束时间"
// @Param pageNumber formData int true "页码"
// @Param pageSize formData int true "条数"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/mine/getAllIncome [get]
func GetAllIncome(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
data, err := walletser.GetIncome(uid)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
common.ServeJSON(ctx, stderr.Success, data)
}
func FruitCoinBill(c *gin.Context) {
uid, err := common.GetUID(c)
if err != nil {
common.ServeJSON(c, stderr.ErrNoToken, err)
return
}
var in = new(walletser.FruitCoinBillCond)
if err = c.ShouldBindQuery(&in); err != nil {
common.ServeJSON(c, stderr.ErrParamError, err)
return
}
data, code := walletser.FruitCoinBill(uid, in)
if code != stderr.Success {
common.ServeJSON(c, code, nil)
return
}
common.ServeJSON(c, code, data)
}
+128
View File
@@ -0,0 +1,128 @@
package walletctrl
import (
"91porn-server/app/appg"
"91porn-server/app/service/walletser"
"91porn-server/common"
"91porn-server/common/stderr"
"91porn-server/common/store"
"91porn-server/models/v/walletmod"
"encoding/json"
"errors"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
"net/http"
"time"
)
func WalletBalance(ctx *gin.Context) {
req := struct {
Uid uint64 `json:"uid" form:"uid"`
}{}
err := ctx.ShouldBind(&req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
w, err := walletmod.GetWallet(req.Uid)
if err != nil {
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
return
}
resp := struct {
Balance int64 `json:"balance"`
}{}
resp.Balance = w.Amount + w.Income
ctx.JSON(http.StatusOK, gin.H{
"code": stderr.Success,
"msg": stderr.Success.Msg(),
"tip": stderr.Success.Tip(),
"data": resp,
"time": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
})
}
func WalletDeduct(ctx *gin.Context) {
req := struct {
Uid uint64 `json:"uid" form:"uid"`
OrderId primitive.ObjectID `json:"orderId" form:"orderId"`
Source int `json:"source" form:"source"`
Amount int64 `json:"amount" form:"amount"` // 扣除金额
Desc string `json:"desc" form:"desc"`
}{}
err := ctx.ShouldBind(&req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
if req.Uid <= 0 || req.OrderId.IsZero() || req.Amount <= 0 {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
err = Check(ctx, req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
resp := struct {
Balance int64 `json:"balance"`
}{}
balance, code := walletser.StoreDeductBalance(req.Uid, req.Amount, req.OrderId, req.Source, req.Desc)
resp.Balance = balance
ctx.JSON(http.StatusOK, gin.H{
"code": code,
"msg": code.Msg(),
"tip": code.Tip(),
"data": resp,
"time": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
})
}
func Check(ctx *gin.Context, param interface{}) (err error) {
b, _ := json.Marshal(param)
sign, err := store.Encrypt(b, appg.Conf.Base.StoreEncryptKey)
if err != nil {
return
}
headerSign := ctx.Request.Header.Get("sign")
if sign != headerSign {
return errors.New("校验失败")
}
return nil
}
func WalletRefund(ctx *gin.Context) {
req := struct {
Uid uint64 `json:"uid"`
OrderId primitive.ObjectID `json:"orderId"`
Source int `json:"source"`
Amount int64 `json:"amount"`
Desc string `json:"desc"`
}{}
err := ctx.ShouldBind(&req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
if req.Uid <= 0 || req.OrderId.IsZero() || req.Amount <= 0 {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
err = Check(ctx, req)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
resp := struct {
Balance int64 `json:"balance"`
}{}
balance, code := walletser.StoreRefund(req.Uid, req.Amount, req.OrderId, req.Source, req.Desc)
resp.Balance = balance
ctx.JSON(http.StatusOK, gin.H{
"code": code,
"msg": code.Msg(),
"tip": code.Tip(),
"data": resp,
"time": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
})
}
+48
View File
@@ -0,0 +1,48 @@
package walletctrl
import (
"91porn-server/app/service/ai_undress_server"
"91porn-server/app/service/aiser"
"91porn-server/common"
"91porn-server/common/log"
"91porn-server/common/stderr"
"91porn-server/models/v/walletmod"
"github.com/gin-gonic/gin"
)
// GetWalletAmount doc
// @Summary 获取钱包信息
// @Description 获取钱包信息
// @Tags 钱包
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {object} walletmod.Wallet "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /mine/wallet [get]
func GetWalletAmount(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err.Error())
return
}
// 从AI女友页面返回后,钱包查询会先尝试把第三方剩余余额下分回主钱包。
// 下分失败只记录告警,钱包接口仍返回当前本地余额。
if err = aiser.TrySettleDown(ctx.Request.Context(), uid); err != nil {
log.Warn("wallet AI girlfriend settlement failed", log.Any("uid", uid), log.E(err))
}
w, err := walletmod.GetWallet(uid)
if err != nil {
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
return
}
resp := &walletmod.WalletResp{}
// 当日剩余ai免费脱衣次数
if w != nil {
resp.Wallet = *w
resp.TodayAiFreeTimes = ai_undress_server.GetTodayRemainingAiFreeUndressTimes(*w)
}
common.ServeJSON(ctx, stderr.Success, resp)
}