Initial commit

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-23 11:07:42 +08:00
co-authored by Claude Opus 5.5
commit 7974a42301
633 changed files with 120248 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
package coinapi
import (
"videoweb/app/service/coinser"
"videoweb/pub/common"
"videoweb/pub/common/enum/consts"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
type buyCoinReq struct {
PackageId int64 `json:"packageId" binding:"required"` // 购买套餐ID(金币充值)
PayMode string `json:"payMode" binding:"required"` // 支付方式:alipay/wechat
}
// BuyCoin 购买金币(发起第三方支付)
// @Tags 金币
// @Summary 购买金币
// @Description 根据指定金币套餐发起第三方支付,返回支付链接
// @Accept json
// @Produce json
// @Param param body buyCoinReq true "购买参数"
// @Success 200 {object} coinser.BuyCoinResp "支付链接"
// @Security ApiKeyAuth
// @Router /api/app/coin/buy [POST]
func BuyCoin(ctx *gin.Context) {
var req buyCoinReq
if err := ctx.ShouldBind(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId := common.GetUserId(ctx)
sysType := ctx.GetString(consts.CtxSysType)
devType := ctx.GetString(consts.CtxDevType)
ip := ipaddr.ResolveClientIP(ctx)
user, serr := coinser.GetUserInfo(ctx, userId)
if serr != nil || user == nil {
common.ServerJSON(ctx, srvdef.ErrUserNotExsit, nil)
return
}
resp, serr := coinser.CreateCoinOrder(ctx, userId, user.NickName, req.PackageId, req.PayMode, sysType, devType, ip, user.DistrictCode)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
type coinOrderHistoryReq struct {
Page int64 `json:"page" form:"page"`
PageSize int64 `json:"pageSize" form:"pageSize"`
}
// GetCoinOrderHistory 查询当前用户金币购买记录
// @Tags 金币
// @Summary 查询金币购买记录
// @Produce json
// @Param page query int false "页码(默认1)"
// @Param pageSize query int false "每页数量(默认10)"
// @Success 200 {object} object "订单列表"
// @Security ApiKeyAuth
// @Router /api/app/coin/orders [GET]
func GetCoinOrderHistory(ctx *gin.Context) {
var req coinOrderHistoryReq
_ = ctx.ShouldBindQuery(&req)
if req.Page <= 0 {
req.Page = 1
}
if req.PageSize <= 0 {
req.PageSize = 10
}
userId := common.GetUserId(ctx)
list, total, serr := coinser.GetCoinOrderHistory(ctx, userId, req.Page, req.PageSize)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, gin.H{"total": total, "list": list})
}
type coinTransListReq struct {
// 页码,默认1
Page int64 `json:"page" form:"page"`
// 每页数量,默认10,最大100
PageSize int64 `json:"pageSize" form:"pageSize"`
}
// GetCoinTransList 查询当前用户金币余额明细
// @Tags 金币
// @Summary 查询金币余额明细 -- by 旺鸣
// @Description 返回当前登录用户的金币收入、支出流水,按交易时间倒序
// @Produce json
// @Param page query int false "页码(默认1)"
// @Param pageSize query int false "每页数量(默认10,最大100)"
// @Success 200 {object} response.BasePageResp{list=[]proto.CoinTransListItemResp} "成功"
// @Security ApiKeyAuth
// @Router /api/app/coin/trans/list [GET]
func GetCoinTransList(ctx *gin.Context) {
var req coinTransListReq
_ = ctx.ShouldBindQuery(&req)
userId := common.GetUserId(ctx)
resp, err := coinser.GetCoinTransList(ctx, userId, req.Page, req.PageSize)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}