224 lines
6.0 KiB
Go
224 lines
6.0 KiB
Go
package vipctrl
|
|
|
|
import (
|
|
"91porn-server/app/service/integral_config_ser"
|
|
"91porn-server/common/daichong"
|
|
"sync"
|
|
"time"
|
|
|
|
"91porn-server/app/proto"
|
|
"91porn-server/app/service/productser"
|
|
"91porn-server/app/service/rechargeser"
|
|
"91porn-server/app/service/vipcardexperimentser"
|
|
"91porn-server/common"
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/commod"
|
|
"91porn-server/models/v/annoumod"
|
|
"91porn-server/models/v/prdcthsomod"
|
|
"91porn-server/models/v/usermod"
|
|
"91porn-server/models/v/vipconfigmod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// PurchaseHistory doc
|
|
// @Summary vip购买历史
|
|
// @Description vip购买历史
|
|
// @Tags vipzz
|
|
// @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/vip/history [get]
|
|
func PurchaseHistory(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.ErrNoToken, err)
|
|
return
|
|
}
|
|
total, data, hasNext, err := prdcthsomod.FindProductHistorysByUID(uid, arg.PageNumber, arg.PageSize)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, map[string]interface{}{
|
|
"total": total,
|
|
"history": data,
|
|
"list": data,
|
|
"hasNext": hasNext,
|
|
})
|
|
}
|
|
|
|
// Product doc
|
|
// @Summary vip种类 新
|
|
// @Description 可购买的vip种类
|
|
// @Tags vip
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Success 200 {object} proto.ProductRes "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /app/vip/product [get]
|
|
func Product(ctx *gin.Context) {
|
|
uid, _ := common.GetUID(ctx)
|
|
ua, _ := common.GetUA(ctx)
|
|
var (
|
|
data = proto.ProductRes{
|
|
IsNewUser: false,
|
|
}
|
|
goldResError error
|
|
)
|
|
var arg struct {
|
|
IsNewUser bool `json:"isNewUser" form:"isNewUser"` // 是否新手
|
|
}
|
|
if err := ctx.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(3)
|
|
common.Go(func() {
|
|
defer wg.Done()
|
|
countdownSec, _ := productser.CountdownTiroCard(uid)
|
|
if countdownSec > 0 {
|
|
data.IsNewUser = true
|
|
}
|
|
if arg.IsNewUser == true {
|
|
data.IsNewUser = arg.IsNewUser
|
|
}
|
|
data.List, goldResError = rechargeser.New_ProductList(uid, ua.SysType, data.IsNewUser, 0)
|
|
})
|
|
common.Go(func() {
|
|
defer wg.Done()
|
|
//d, _ := daichongser.NewTakeChat(ctx, uid, 0)
|
|
d := daichong.ChatResp{}
|
|
data.Daichong = d.Data
|
|
})
|
|
common.Go(func() {
|
|
defer wg.Done()
|
|
data.IntegralList = integral_config_ser.GetAllConfig()
|
|
})
|
|
wg.Wait()
|
|
if goldResError != nil {
|
|
common.ServeJSON(ctx, stderr.PayBusy, goldResError.Error())
|
|
return
|
|
}
|
|
if err := vipcardexperimentser.ApplyToProductResponse(uid, &data, time.Now()); err != nil {
|
|
// 实验是增强能力,查询异常时降级到原套餐列表,不能阻断购买主链路。
|
|
log.Warn("vip card experiment fallback to legacy product response", log.Any("uid", uid), log.E(err))
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, data)
|
|
}
|
|
|
|
// 获取新手卡倒计时
|
|
func CountdownTiroCard(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, err)
|
|
return
|
|
}
|
|
countdownSec, err := productser.CountdownTiroCard(uid)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{"countdownSec": countdownSec})
|
|
}
|
|
|
|
// 获取新手卡倒计时
|
|
func VIPUpAnnouns(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, err)
|
|
return
|
|
}
|
|
u, err := usermod.FindUserByUID(uid)
|
|
if err != nil || u == nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
return
|
|
}
|
|
var announs []annoumod.AnnounInfo
|
|
if u.IsPaidVIP() && u.VipExpireDate.Before(time.Now().AddDate(20, 0, 0)) {
|
|
announs, _ = annoumod.GetAnnouForDomain(annoumod.VIPUP)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
return
|
|
}
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{"list": announs})
|
|
}
|
|
|
|
func VIPUpInfo(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, err)
|
|
return
|
|
}
|
|
u, err := usermod.FindUserByUID(uid)
|
|
if err != nil || u == nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
return
|
|
}
|
|
var cfg vipconfigmod.VIPConfig
|
|
cfg, _ = vipconfigmod.FindOne()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
return
|
|
}
|
|
var vipUpCheapPrice int64
|
|
var vipUpPrice int64
|
|
now := time.Now()
|
|
if u.VipExpireDate.After(now) && u.VipExpireDate.Before(now.AddDate(20, 0, 0)) {
|
|
switch u.VipLevel {
|
|
case 1:
|
|
vipUpPrice = cfg.VipUpPrice
|
|
vipUpCheapPrice = cfg.VipUpCheapPrice
|
|
case 2:
|
|
vipUpPrice = cfg.SVipUpPrice
|
|
vipUpCheapPrice = cfg.SVipUpCheapPrice
|
|
default:
|
|
}
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{
|
|
"vipUpPrice": vipUpPrice,
|
|
"vipUpCheapPrice": vipUpCheapPrice,
|
|
})
|
|
}
|
|
|
|
func VIPUp(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, err)
|
|
return
|
|
}
|
|
code := productser.VIPUp(uid)
|
|
common.ServeJSON(ctx, code, gin.H{})
|
|
}
|
|
|
|
//// VipRecommend doc
|
|
//// @Summary vip推荐展示
|
|
//// @Description vip推荐展示
|
|
//// @Tags vip
|
|
//// @Accept mpfd,json
|
|
//// @Produce json,html
|
|
//// @Success 200 {object} productmod.Product
|
|
//// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
//// @Router /api/app/vip/recommend [get]
|
|
//func VipRecommend(ctx *gin.Context) {
|
|
// resp, err := productser.GetRecommendVip()
|
|
// if err != nil {
|
|
// common.ServeJSON(ctx, stderr.ErrDbQueryError, err)
|
|
// return
|
|
// }
|
|
// common.ServeJSON(ctx, stderr.Success, resp)
|
|
//}
|