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) {
var (
mid = req.Mid
zid = req.Zid
productId = req.ProductId
calcPrice = int64(0)
uid = int64(0)
@ -123,7 +125,13 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
calcPrice = mpr.Price
uid = mpr.Mid
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)
if err != nil {
@ -135,11 +143,26 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
return nil, err
}
switch productId {
case dbstruct.ProductIdH5ZoneAdmission:
calcPrice = zv.AdmissionPrice
uid = zv.Mid
case dbstruct.ProductIdH5ZoneSuperfanship:
// 是否已开通超粉,不让创建订单
zu, _ := v.CheckZoneUnlockExist(ctx, nil, mid, zid)
if zu.IsUnlockSuperfanship() {
return nil, fmt.Errorf("您已开通该空间超粉")
}
// 获取空间价格相关
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())
@ -147,7 +170,6 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
oid2 = "-1"
}
}
}
createOrderReq := &vasproto.CreateOrderReq{
BaseRequest: req.BaseRequest,
@ -253,12 +275,31 @@ func (v *Vas) UnlockZoneAdmission(ctx *gin.Context, tx *sqlx.Tx, order *dbstruct
return err
}
// 获取空间解锁
zu, _ := v.CheckZoneUnlockExist(ctx, tx, mid, zid)
// 添加到空间成员
err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeNormal)
if err != nil {
logger.Error("AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, 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)

View File

@ -973,14 +973,14 @@ func (p *ZoneUnlock) IsUnlockAdmission() 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 false
}
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 false