Merge branch 'feat-IRONFANS-70' into test

This commit is contained in:
lwl0608 2024-04-19 10:11:26 +08:00
commit 88b06ca599
2 changed files with 55 additions and 14 deletions

View File

@ -102,6 +102,8 @@ func (v *Vas) UpdateZoneMomentPrice(ctx *gin.Context, req *vasproto.UpdateZoneMo
// 创建空间订单 // 创建空间订单
func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq) (*vasproto.ZoneCreateOrderData, error) { func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq) (*vasproto.ZoneCreateOrderData, error) {
var ( var (
mid = req.Mid
zid = req.Zid
productId = req.ProductId productId = req.ProductId
calcPrice = int64(0) calcPrice = int64(0)
uid = int64(0) uid = int64(0)
@ -123,7 +125,13 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
calcPrice = mpr.Price calcPrice = mpr.Price
uid = mpr.Mid uid = mpr.Mid
oid2 = fmt.Sprintf("%d", req.MomentId) oid2 = fmt.Sprintf("%d", req.MomentId)
case dbstruct.ProductIdH5ZoneAdmission, dbstruct.ProductIdH5ZoneSuperfanship: case dbstruct.ProductIdH5ZoneAdmission:
// 是否已开通会员,不让创建订单
zu, _ := v.CheckZoneUnlockExist(ctx, nil, mid, zid)
if zu.IsUnlockAdmission() {
return nil, fmt.Errorf("您已开通该空间会员")
}
// 获取空间价格相关 // 获取空间价格相关
zv, err := v.store.GetZoneVasById(ctx, req.Zid) zv, err := v.store.GetZoneVasById(ctx, req.Zid)
if err != nil { if err != nil {
@ -135,17 +143,31 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
return nil, err return nil, err
} }
switch productId { calcPrice = zv.AdmissionPrice
case dbstruct.ProductIdH5ZoneAdmission: uid = zv.Mid
calcPrice = zv.AdmissionPrice case dbstruct.ProductIdH5ZoneSuperfanship:
uid = zv.Mid // 是否已开通超粉,不让创建订单
case dbstruct.ProductIdH5ZoneSuperfanship: zu, _ := v.CheckZoneUnlockExist(ctx, nil, mid, zid)
calcPrice = zv.SuperfanshipPrice if zu.IsUnlockSuperfanship() {
uid = zv.Mid return nil, fmt.Errorf("您已开通该空间超粉")
oid2 = fmt.Sprintf("%d", time.Now().Unix()+zv.GetSuperfanshipDurationSecond()) }
if zv.SuperfanshipValidPeriod == dbstruct.SuperfanshipValidPeriodEternal {
oid2 = "-1" // 获取空间价格相关
} zv, err := v.store.GetZoneVasById(ctx, req.Zid)
if err != nil {
logger.Error("GetZoneVasById fail, id: %v, err: %v", req.Zid, err)
return nil, err
}
if zv == nil {
err = fmt.Errorf("GetZoneVasById nil, id: %v", req.Zid)
return nil, err
}
calcPrice = zv.SuperfanshipPrice
uid = zv.Mid
oid2 = fmt.Sprintf("%d", time.Now().Unix()+zv.GetSuperfanshipDurationSecond())
if zv.SuperfanshipValidPeriod == dbstruct.SuperfanshipValidPeriodEternal {
oid2 = "-1"
} }
} }
@ -253,12 +275,31 @@ func (v *Vas) UnlockZoneAdmission(ctx *gin.Context, tx *sqlx.Tx, order *dbstruct
return err return err
} }
// 获取空间解锁
zu, _ := v.CheckZoneUnlockExist(ctx, tx, mid, zid)
// 添加到空间成员 // 添加到空间成员
err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeNormal) err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeNormal)
if err != nil { if err != nil {
logger.Error("AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err) logger.Error("AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err return err
} }
// 如果之前开通过铁粉,这次要添加到成员列表
if zu.IsUnlockIronfanship() {
err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeIronfan)
if err != nil {
logger.Error("AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err
}
}
// 如果之前开通过超粉,这次要添加到成员列表
if zu.IsUnlockSuperfanship() {
err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeSuperfan)
if err != nil {
logger.Error("AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err
}
}
// 计算收入 // 计算收入
totalDias := int64(float64(order.GetPayAmount()) / 100.0 * 10.0) totalDias := int64(float64(order.GetPayAmount()) / 100.0 * 10.0)

View File

@ -973,14 +973,14 @@ func (p *ZoneUnlock) IsUnlockAdmission() bool {
} }
func (p *ZoneUnlock) IsUnlockIronfanship() bool { func (p *ZoneUnlock) IsUnlockIronfanship() bool {
if p.GetIronfanshipUntil() == -1 || p.GetIronfanshipUntil() >= time.Now().Unix() { if p.IsUnlockAdmission() && (p.GetIronfanshipUntil() == -1 || p.GetIronfanshipUntil() >= time.Now().Unix()) {
return true return true
} }
return false return false
} }
func (p *ZoneUnlock) IsUnlockSuperfanship() bool { func (p *ZoneUnlock) IsUnlockSuperfanship() bool {
if p.GetSuperfanshipUntil() == -1 || p.GetSuperfanshipUntil() >= time.Now().Unix() { if p.IsUnlockAdmission() && (p.GetSuperfanshipUntil() == -1 || p.GetSuperfanshipUntil() >= time.Now().Unix()) {
return true return true
} }
return false return false