by Robin at 20240501

This commit is contained in:
Leufolium 2024-05-01 03:52:59 +08:00
parent 6824e26e90
commit 74e6f9a9f5
4 changed files with 83 additions and 50 deletions

View File

@ -37,6 +37,12 @@ type OpDeleteResp struct {
type OpUpdateReq struct { type OpUpdateReq struct {
base.BaseRequest base.BaseRequest
*dbstruct.Zone *dbstruct.Zone
AdmissionPrice int64 `json:"admission_price"` // 空间解锁价格, 单位: 分
IronfanshipPrice int64 `json:"ironfanship_price"` // 铁粉解锁价格, 单位: 分
IsSuperfanshipEnabled int `json:"is_superfanship_enabled"` // 是否开启超粉空间 0: 关闭, 1: 开启
SuperfanshipPrice int64 `json:"superfanship_price"` // 超粉价格, 单位: 分
SuperfanshipValidPeriod int `json:"superfanship_valid_period"` // 超粉有效期类型, SuperfanshipValidPeriod*
IsSuperfanshipGiveWechat int `json:"is_superfanship_give_wechat"` // 是否开启超粉空间赠送微信 0: 不赠送, 1: 赠送
} }
type OpUpdateData struct { type OpUpdateData struct {

View File

@ -2654,38 +2654,25 @@ func (s *Service) ApiDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
} }
// 查看空间最后更新时间是否需要回退 // 查看空间最后更新时间是否需要回退
list, err := _DefaultZoneMoment.OpListByMid(ctx, &zonemomentproto.OpListByMidReq{ if zonemoment.GetStatus() == consts.ZoneMoment_Public {
BaseRequest: req.BaseRequest, list, err := _DefaultZoneMoment.OpListByMid(ctx, &zonemomentproto.OpListByMidReq{
Limit: 1, BaseRequest: req.BaseRequest,
Sort: []string{"-ut"}, Status: goproto.Int64(consts.ZoneMoment_Public),
}) Limit: 1,
if err != nil { Sort: []string{"-ut"},
logger.Error("OpListByMid fail, err: %v", err) })
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 已经没有动态最后更新时间回退到0
if len(list) == 0 {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: goproto.Int64(zid),
LastZoneMomentCt: goproto.Int64(0),
},
}, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
logger.Error("OpUpdate fail, err: %v", err) logger.Error("OpListByMid fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return return
} }
} else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨 // 已经没有动态最后更新时间回退到0
lastzonemoment := list[0] if len(list) == 0 {
if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{ err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{ Zone: &dbstruct.Zone{
Id: goproto.Int64(zid), Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut, LastZoneMomentCt: goproto.Int64(0),
}, },
}, zone.GetLastZoneMomentCt()) }, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
@ -2693,6 +2680,22 @@ func (s *Service) ApiDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return return
} }
} else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨
lastzonemoment := list[0]
if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut,
},
}, zone.GetLastZoneMomentCt())
if err != nil {
logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
}
} }
} }

View File

@ -37,6 +37,7 @@ func (p *Zone) OpCreate(ctx *gin.Context, req *zoneproto.OpCreateReq) (error, in
req.Zone.Ct = goproto.Int64(time.Now().Unix()) req.Zone.Ct = goproto.Int64(time.Now().Unix())
req.Zone.Ut = goproto.Int64(time.Now().Unix()) req.Zone.Ut = goproto.Int64(time.Now().Unix())
req.Zone.DelFlag = goproto.Int64(consts.Exist) req.Zone.DelFlag = goproto.Int64(consts.Exist)
req.Zone.LastZoneMomentCt = goproto.Int64(0)
err = p.store.CreateZone(ctx, req.Zone) err = p.store.CreateZone(ctx, req.Zone)
if err != nil { if err != nil {
logger.Error("CreateZone fail, err: %v", err) logger.Error("CreateZone fail, err: %v", err)

View File

@ -3181,6 +3181,26 @@ func (s *Service) OpUpdateZone(ctx *gin.Context, req *zoneproto.OpUpdateReq) (ec
ec = errcode.ErrCodeZoneSrvFail ec = errcode.ErrCodeZoneSrvFail
return return
} }
err = _DefaultVas.UpdateZoneVasInfo(ctx, &vasproto.UpdateZoneVasReq{
ZoneVas: &dbstruct.ZoneVas{
Zid: *req.Zone.Id,
Mid: req.BaseRequest.Mid,
Ct: time.Now().Unix(),
Ut: time.Now().Unix(),
AdmissionPrice: req.AdmissionPrice,
IronfanshipPrice: req.IronfanshipPrice,
IsSuperfanshipEnabled: req.IsSuperfanshipEnabled,
SuperfanshipPrice: req.SuperfanshipPrice,
SuperfanshipValidPeriod: req.SuperfanshipValidPeriod,
IsSuperfanshipGiveWechat: req.IsSuperfanshipGiveWechat,
},
})
if err != nil {
logger.Error("UpdateZoneVasInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneSrvFail
return
}
return return
} }
@ -3397,38 +3417,25 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
} }
// 查看空间最后更新时间是否需要回退 // 查看空间最后更新时间是否需要回退
list, err := _DefaultZoneMoment.OpListByMid(ctx, &zonemomentproto.OpListByMidReq{ if zonemoment.GetStatus() == consts.ZoneMoment_Public {
BaseRequest: req.BaseRequest, list, err := _DefaultZoneMoment.OpListByMid(ctx, &zonemomentproto.OpListByMidReq{
Limit: 1, BaseRequest: req.BaseRequest,
Sort: []string{"-ut"}, Status: goproto.Int64(consts.ZoneMoment_Public),
}) Limit: 1,
if err != nil { Sort: []string{"-ut"},
logger.Error("OpListByMid fail, err: %v", err) })
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 已经没有动态最后更新时间回退到0
if len(list) == 0 {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: goproto.Int64(zid),
LastZoneMomentCt: goproto.Int64(0),
},
}, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
logger.Error("OpUpdate fail, err: %v", err) logger.Error("OpListByMid fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return return
} }
} else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨 // 已经没有动态最后更新时间回退到0
lastzonemoment := list[0] if len(list) == 0 {
if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{ err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{ Zone: &dbstruct.Zone{
Id: goproto.Int64(zid), Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut, LastZoneMomentCt: goproto.Int64(0),
}, },
}, zone.GetLastZoneMomentCt()) }, zone.GetLastZoneMomentCt())
if err != nil { if err != nil {
@ -3436,6 +3443,22 @@ func (s *Service) OpDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.OpDe
ec = errcode.ErrCodeZoneMomentSrvFail ec = errcode.ErrCodeZoneMomentSrvFail
return return
} }
} else {
//还有动态,看最后一条更新的动态的更新时间是否比删除的那条动态更早,若更早,则需要把空间的更新时间回拨
lastzonemoment := list[0]
if lastzonemoment.GetUt() < zonemoment.GetUt() {
err = _DefaultZone.OpUpdateByIdAndLastZoneMomentCt(ctx, &zoneproto.OpUpdateReq{
Zone: &dbstruct.Zone{
Id: goproto.Int64(zid),
LastZoneMomentCt: lastzonemoment.Ut,
},
}, zone.GetLastZoneMomentCt())
if err != nil {
logger.Error("OpUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
}
} }
} }