diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index 7259eafc..826b47a5 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -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,17 +143,31 @@ 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: - calcPrice = zv.SuperfanshipPrice - uid = zv.Mid - oid2 = fmt.Sprintf("%d", time.Now().Unix()+zv.GetSuperfanshipDurationSecond()) - if zv.SuperfanshipValidPeriod == dbstruct.SuperfanshipValidPeriodEternal { - oid2 = "-1" - } + 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()) + 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 } + // 获取空间解锁 + 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) diff --git a/dbstruct/vas_mysql.go b/dbstruct/vas_mysql.go index 655fd6fe..32c05e12 100644 --- a/dbstruct/vas_mysql.go +++ b/dbstruct/vas_mysql.go @@ -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