Files
huangguo_server/app/api/ai_mate_ctrl/ai_mate.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

152 lines
4.2 KiB
Go

package ai_mate_ctrl
import (
"91porn-server/app/appg"
"91porn-server/app/service/ai_mate_ser"
"91porn-server/common"
"91porn-server/common/log"
"91porn-server/common/stderr"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
// GetCurrencys doc
// @Summary AI伴侣
// @Description 获取AI伴侣币列表
// @Tags mine
// @Accept json
// @Produce json
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/aimate/currencys [get]
func GetCurrencys(ctx *gin.Context) {
code, data := ai_mate_ser.GetCurrencyList()
if code != stderr.Success {
common.ServeJSON(ctx, code, nil)
return
}
common.ServeJSON(ctx, code, gin.H{"list": data})
}
// Exchange doc
// @Summary AI伴侣
// @Description 兑换AI伴侣货币
// @Tags mine
// @Accept json
// @Produce json
// @Param q query ai_mate_ser.ExchangeReq false "请求参数"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/aimate/exchange [post]
func Exchange(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
var req ai_mate_ser.ExchangeReq
if err = ctx.ShouldBindJSON(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
ua, _ := common.GetUA(ctx)
ip := common.GetIP(ctx)
code := ai_mate_ser.Exchange(uid, req, ua, ip)
if code != stderr.Success {
common.ServeJSON(ctx, code, nil)
return
}
common.ServeJSON(ctx, code, "操作成功")
}
// Login doc
// @Summary AI伴侣
// @Description 获取当前用户的AI女友登录地址
// @Tags mine
// @Accept json
// @Produce json
// @Success 200 {object} ai_mate_ser.LoginResp
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/aimate/login [get]
func Login(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
if appg.Conf.URL.AIMateH5 == "" {
common.ServeJSON(ctx, stderr.FunctionNotEnabled, nil)
return
}
ret, err := ai_mate_ser.Login(uid)
if err != nil {
log.Error("ai_mate_ser Login failed", log.Any("uid", uid), log.E(err))
common.ServeJSON(ctx, stderr.Failure, nil)
return
}
common.ServeJSON(ctx, stderr.Success, ret)
}
// GetBalance doc
// @Summary AI伴侣
// @Description 获取用户AI伴侣余额
// @Tags mine
// @Accept json
// @Produce json
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/app/aimate/getBalance [get]
func GetBalance(ctx *gin.Context) {
uid, err := common.GetUID(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.ErrNoToken, err)
return
}
if appg.Conf.URL.AIMateH5 == "" {
common.ServeJSON(ctx, stderr.FunctionNotEnabled, nil)
return
}
ret, err := ai_mate_ser.GetNewBalance(uid)
if err != nil {
log.Error(fmt.Sprintf("uid:%d, ai_mate_ser GetNewBalance err:%v", uid, err))
common.ServeJSON(ctx, stderr.Failure, nil)
return
}
common.ServeJSON(ctx, stderr.Success, ret)
}
// GianBalance 保留历史拼写错误的接口,兼容旧客户端。
func GianBalance(ctx *gin.Context) {
GetBalance(ctx)
}
// SyncInfo doc
// @Summary 同步聊天信息
// @Description 同步聊天信息
// @Tags AI伴侣模块
// @Accept mpfd,json
// @Produce json,html
// @Param param body ai_mate_ser.SyncInfoRes true "参数列表"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Router /api/app/aimate/sync [post]
func SyncInfo(ctx *gin.Context) {
var in ai_mate_ser.SyncInfoRes
if err := ctx.ShouldBindJSON(&in); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
err := in.Sync()
if err != nil {
log.Error(fmt.Sprintf("uid:%v,aimate sync err:%v", in.UID, err))
common.ServeJSON(ctx, stderr.Failure, err)
return
}
ctx.JSON(http.StatusOK, stderr.Success.Msg())
}