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
+275
View File
@@ -0,0 +1,275 @@
package activityctrl
import (
"strconv"
"91porn-server/app/service/activityser"
"91porn-server/common"
"91porn-server/common/log"
"91porn-server/common/stderr"
"github.com/gin-gonic/gin"
)
type CurrencyListReq struct {
UserID string `json:"userId" binding:"required"`
}
func CurrencyList(c *gin.Context) {
var req CurrencyListReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
data, code := activityser.GetCurrencyList(c)
if code != stderr.Success {
common.ServeJSONNoEncrypt(c, code, nil)
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, gin.H{
"list": data,
})
}
// VipDeductReq 会员卡当前可用抵扣(按抵扣后金额匹配支付通道)
type VipDeductReq struct {
ProductID string `json:"productId"` // 会员卡ID
DeductAmount int64 `json:"deductAmount"` // 券面额(分)
}
type ProductListReq struct {
UserID string `json:"userId" binding:"required"`
Deducts []VipDeductReq `json:"deducts"` // 各会员卡可用抵扣;按抵扣后有效金额匹配支付通道,可选
}
func ProductList(c *gin.Context) {
var req ProductListReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
uid, err := strconv.ParseUint(req.UserID, 10, 64)
if err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, "invalid userId")
return
}
deducts := make([]activityser.VipDeduct, 0, len(req.Deducts))
for _, d := range req.Deducts {
deducts = append(deducts, activityser.VipDeduct{ProductID: d.ProductID, DeductAmount: d.DeductAmount})
}
res, err := activityser.GetProductList(c, uid, deducts)
if err != nil {
log.ErrorX(c, "活动服-获取会员卡列表异常", log.Any("uid", req.UserID), log.E(err))
common.ServeJSONNoEncrypt(c, stderr.ErrNetWorkBusy, nil)
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, gin.H{
"list": res,
})
}
type RechargeOrderReq struct {
UserID string `json:"userId" binding:"required"`
RechargeType string `json:"rechargeType" binding:"required"`
ProductID string `json:"productId" binding:"required"`
BuyType int `json:"buyType" binding:"required"`
ActivityID string `json:"activityId"`
ExperimentID string `json:"experimentId"`
ExperimentVariant string `json:"experimentVariant"`
SessionID string `json:"sessionId"`
CouponID string `json:"couponId"` // 会员抵扣券ID(可选,购买会员卡时自动抵扣)
DeductAmount int64 `json:"deductAmount"` // 活动服建议抵扣金额(分,可选),本服按券自行校验上限后折价
}
func RechargeOrder(c *gin.Context) {
var req RechargeOrderReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
uid, err := strconv.ParseUint(req.UserID, 10, 64)
if err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, "invalid userId")
return
}
payUrl, mode, err := activityser.CreateRechargeOrder(
c,
uid,
req.RechargeType,
req.ProductID,
req.BuyType,
c.ClientIP(),
activityser.RechargeAttribution{
ActivityID: req.ActivityID,
ExperimentID: req.ExperimentID,
ExperimentVariant: req.ExperimentVariant,
SessionID: req.SessionID,
},
req.CouponID,
req.DeductAmount,
)
if err != nil {
log.ErrorX(c, "活动服-充值下单异常", log.Any("uid", req.UserID), log.E(err))
common.ServeJSONNoEncrypt(c, stderr.RechargeFaile, err.Error())
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, gin.H{
"payUrl": payUrl,
"mode": mode,
})
}
type BuyCoinProductReq struct {
UserID string `json:"userId" binding:"required"`
ProductID string `json:"productId" binding:"required"`
}
func BuyCoinProduct(c *gin.Context) {
var req BuyCoinProductReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
uid, err := strconv.ParseUint(req.UserID, 10, 64)
if err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, "invalid userId")
return
}
code, err := activityser.BuyCoinProduct(c, uid, req.ProductID, "")
if err != nil {
log.ErrorX(c, "活动服-金币购买异常", log.Any("uid", req.UserID), log.Any("productId", req.ProductID), log.E(err))
if code == stderr.InsufficientBalance {
common.ServeJSONNoEncrypt(c, 201, "余额不足")
return
}
common.ServeJSONNoEncrypt(c, code, err.Error())
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, nil)
}
type UserBalanceReq struct {
UserID string `json:"userId" binding:"required"`
}
func UserBalance(c *gin.Context) {
var req UserBalanceReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
uid, err := strconv.ParseUint(req.UserID, 10, 64)
if err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, "invalid userId")
return
}
balance, err := activityser.GetUserBalance(uid)
if err != nil {
log.ErrorX(c, "活动服-查询余额异常", log.Any("uid", req.UserID), log.E(err))
common.ServeJSONNoEncrypt(c, stderr.ErrNetWorkBusy, nil)
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, balance)
}
type AppInfoReq struct {
UserID string `json:"userId" binding:"required"`
}
func AppInfo(c *gin.Context) {
var req AppInfoReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
uid, err := strconv.ParseUint(req.UserID, 10, 64)
if err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, "invalid userId")
return
}
data, err := activityser.GetAppInfo(c, uid)
if err != nil {
log.ErrorX(c, "活动服-获取应用信息异常", log.Any("uid", req.UserID), log.E(err))
common.ServeJSONNoEncrypt(c, stderr.ErrNetWorkBusy, nil)
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, data)
}
func Reward(c *gin.Context) {
var req activityser.RewardReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
if err := activityser.GrantReward(c, &req); err != nil {
log.ErrorX(c, "活动服-发奖异常",
log.Any("uid", req.UserId),
log.Any("rewardType", req.RewardType),
log.Any("amount", req.Amount),
log.E(err))
common.ServeJSONNoEncrypt(c, stderr.Failure, err.Error())
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, nil)
}
func BatchReward(c *gin.Context) {
var req activityser.BatchRewardReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
if err := activityser.GrantBatchReward(c, &req); err != nil {
log.ErrorX(c, "活动服-批量发奖异常",
log.Any("uid", req.UserId),
log.Any("rewardCount", len(req.Rewards)),
log.E(err))
common.ServeJSONNoEncrypt(c, stderr.Failure, err.Error())
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, nil)
}
func Deduct(c *gin.Context) {
var req activityser.DeductReq
if err := c.ShouldBindJSON(&req); err != nil {
common.ServeJSONNoEncrypt(c, stderr.ErrParamError, nil)
return
}
code, err := activityser.Deduct(c, &req)
if err != nil {
log.ErrorX(c, "活动服-扣款异常",
log.Any("uid", req.UserId),
log.Any("deductType", req.DeductType),
log.Any("amount", req.Amount),
log.E(err))
common.ServeJSONNoEncrypt(c, code, err.Error())
return
}
common.ServeJSONNoEncrypt(c, stderr.Success, nil)
}