init: web_hgcg_server 初始化提交

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:44:55 +08:00
co-authored by Claude Opus 4.7
commit 189556e702
627 changed files with 126228 additions and 0 deletions
+143
View File
@@ -0,0 +1,143 @@
package coinapi
import (
"fmt"
"net/url"
"videoweb/app/service/coinser"
"videoweb/app/service/rechargeser"
"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
}
deviceID := rechargeser.PayDeviceID(ctx.GetString(consts.CtxDevId), user.DevID, user.DevV2)
resp, serr := coinser.CreateCoinOrder(ctx, userId, user.NickName, req.PackageId, req.PayMode, sysType, devType, deviceID, ip, user.DistrictCode)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ExportCoinTrans 导出当前用户金币余额明细
// @Tags 金币
// @Summary 导出金币余额明细 -- by 王鸣
// @Description 导出当前登录用户的金币收入、支出流水CSV;type=0全部 1充值 2消费 3奖励
// @Produce text/csv
// @Param type query int false "类型:0全部 1充值 2消费 3奖励"
// @Success 200 {file} file "CSV文件"
// @Security ApiKeyAuth
// @Router /api/app/coin/trans/export [GET]
func ExportCoinTrans(ctx *gin.Context) {
var req coinTransListReq
_ = ctx.ShouldBindQuery(&req)
data, fileName, err := coinser.ExportCoinTrans(ctx, common.GetUserId(ctx), req.Type)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
ctx.Header("Content-Type", "text/csv; charset=utf-8")
ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename*=UTF-8''%s", url.QueryEscape(fileName)))
ctx.Data(200, "text/csv; charset=utf-8", data)
}
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"`
// 类型:0-全部 1-充值 2-消费 3-奖励
Type int64 `json:"type" form:"type"`
}
// GetCoinTransList 查询当前用户金币余额明细
// @Tags 金币
// @Summary 查询金币余额明细 -- by 旺鸣
// @Description 返回当前登录用户的金币收入、支出流水,按交易时间倒序;type=0全部 1充值 2消费 3奖励
// @Produce json
// @Param page query int false "页码(默认1)"
// @Param pageSize query int false "每页数量(默认10,最大100)"
// @Param type query int false "类型:0全部 1充值 2消费 3奖励"
// @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, req.Type)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}