fix: 铁粉刷新,ret 和 errcode 返回

This commit is contained in:
wangxinyu 2024-12-20 16:17:33 +08:00
parent 3442269b49
commit 8909679a8b
5 changed files with 55 additions and 36 deletions
api/errcode
app/mix

View File

@ -189,12 +189,14 @@ var ErrCodeMsgMap = map[ErrCode]string{
ErrCodeAccountCancellationSrvFail: "账户注销服务错误", ErrCodeAccountCancellationSrvFail: "账户注销服务错误",
ErrCodeAccountCancellationNotExist: "账户注销不存在", ErrCodeAccountCancellationNotExist: "账户注销不存在",
ErrCodeZoneSrvFail: "空间服务错误", ErrCodeZoneSrvFail: "空间服务错误",
ErrCodeZoneNotExist: "空间不存在", ErrCodeZoneNotExist: "空间不存在",
ErrCodeUnlockedZone: "访客未解锁该空间", ErrCodeUnlockedZone: "访客未解锁该空间",
ErrCodeZoneDuplicateKey: "您已创建空间", ErrCodeZoneDuplicateKey: "您已创建空间",
ErrcodeZoneIronFansUnLock: "您已解锁空间铁粉", ErrcodeZoneIronFansUnLock: "您已解锁空间铁粉",
ErrcodeZoneIronFansNotUnLock: "暂不满足铁粉条件", ErrcodeZoneIronFansAlreadyUnLock: "您已是空间铁粉",
ErrcodeZoneIronFansNotUnLock: "暂不满足铁粉条件",
ErrcodeZoneIronFansRefreshErr: "铁粉刷新失败,服务错误",
ErrCodeZoneMomentSrvFail: "私密圈动态服务错误", ErrCodeZoneMomentSrvFail: "私密圈动态服务错误",
ErrCodeZoneMomentNotExist: "私密圈动态不存在", ErrCodeZoneMomentNotExist: "私密圈动态不存在",
@ -523,13 +525,15 @@ const (
ErrCodeAccountPunishmentStreamerOnly ErrCode = -32007 // 该账号处罚仅能对主播进行 ErrCodeAccountPunishmentStreamerOnly ErrCode = -32007 // 该账号处罚仅能对主播进行
// Zone: 33xxx // Zone: 33xxx
ErrCodeZoneSrvOk ErrCode = ErrCodeOk ErrCodeZoneSrvOk ErrCode = ErrCodeOk
ErrCodeZoneSrvFail ErrCode = -33001 // 空间服务错误 ErrCodeZoneSrvFail ErrCode = -33001 // 空间服务错误
ErrCodeZoneNotExist ErrCode = -33002 // 空间不存在 ErrCodeZoneNotExist ErrCode = -33002 // 空间不存在
ErrCodeUnlockedZone ErrCode = -33003 // 未解锁的空间 ErrCodeUnlockedZone ErrCode = -33003 // 未解锁的空间
ErrCodeZoneDuplicateKey ErrCode = -33004 // 空间已存在 ErrCodeZoneDuplicateKey ErrCode = -33004 // 空间已存在
ErrcodeZoneIronFansUnLock ErrCode = -33005 // 空间已解锁铁粉 ErrcodeZoneIronFansUnLock ErrCode = -33005 // 空间已解锁铁粉
ErrcodeZoneIronFansNotUnLock ErrCode = -33006 // 空间未解锁铁粉 ErrcodeZoneIronFansNotUnLock ErrCode = -33006 // 空间未解锁铁粉
ErrcodeZoneIronFansAlreadyUnLock ErrCode = -33007 // 已经是空间铁粉
ErrcodeZoneIronFansRefreshErr ErrCode = -33008 // 铁粉刷新服务错误
// ZoneMoment: 34xxx // ZoneMoment: 34xxx
ErrCodeZoneMomentSrvOk ErrCode = ErrCodeOk ErrCodeZoneMomentSrvOk ErrCode = ErrCodeOk

View File

@ -242,12 +242,16 @@ func ApiFansIdentityRefresh(ctx *gin.Context) {
return return
} }
err := service.DefaultService.FansIdentityRefresh(ctx, req) ec, err := service.DefaultService.FansIdentityRefresh(ctx, req)
if err != nil { if err != nil {
logger.Error("ApiFansIdentityRefresh fail, req: %v, err: %v", util.ToJson(req), err) logger.Error("ApiFansIdentityRefresh fail, req: %v, err: %v", util.ToJson(req), err)
ReplyErrCodeMsg(ctx, errcode.ErrcodeZoneIronFansNotUnLock) ReplyErrCodeMsg(ctx, ec)
return return
} }
if ec != errcode.ErrCodeOk {
ReplyErrCodeMsg(ctx, ec)
}
ReplyOk(ctx, nil) ReplyOk(ctx, nil)
} }

View File

@ -15,6 +15,7 @@ import (
"net/http" "net/http"
"service/api/adapter/dingtalkapi" "service/api/adapter/dingtalkapi"
"service/api/base" "service/api/base"
"service/api/errcode"
"service/api/errs" "service/api/errs"
"service/api/message/response" "service/api/message/response"
accountproto "service/api/proto/account/proto" accountproto "service/api/proto/account/proto"
@ -4297,13 +4298,13 @@ func (v *Vas) UnilaterallyWithdrawAccomplish(ctx *gin.Context, orderId string) (
return return
} }
func (v *Vas) FansIdentityRefresh(ctx *gin.Context, mid, zid int64) error { func (v *Vas) FansIdentityRefresh(ctx *gin.Context, mid, zid int64) (errcode.ErrCode, error) {
err := v.UnlockZoneIronfanshipRefresh(ctx, mid, zid, 0) ec, err := v.UnlockZoneIronfanshipRefresh(ctx, mid, zid, 0)
if err != nil { if err != nil {
logger.Error("vas FansIdentityRefresh UnlockZoneIronFanShipRefresh fail, mid: %v, zid: %v, err: %v", mid, zid, err) logger.Error("vas FansIdentityRefresh UnlockZoneIronFanShipRefresh fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err return ec, err
} }
return nil return ec, nil
} }

View File

@ -3,6 +3,7 @@ package logic
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"service/api/errcode"
"service/api/errs" "service/api/errs"
vasproto "service/api/proto/vas/proto" vasproto "service/api/proto/vas/proto"
zone_collaborator_proto "service/api/proto/zone_collaborator/proto" zone_collaborator_proto "service/api/proto/zone_collaborator/proto"
@ -530,13 +531,14 @@ func (v *Vas) UnlockZoneIronfanshipReachConsume(ctx *gin.Context, tx *sqlx.Tx, m
} }
// 铁粉刷新(主播涨价降价后逻辑后更新逻辑) // 铁粉刷新(主播涨价降价后逻辑后更新逻辑)
func (v *Vas) UnlockZoneIronfanshipRefresh(ctx *gin.Context, mid, zid, streamerMid int64) error { func (v *Vas) UnlockZoneIronfanshipRefresh(ctx *gin.Context, mid, zid, streamerMid int64) (errcode.ErrCode, error) {
ec := errcode.ErrCodeOk
// 开启事务 // 开启事务
tx, err := v.store.VasBegin(ctx) tx, err := v.store.VasBegin(ctx)
if err != nil { if err != nil {
logger.Error("vas begin fail, err: %v", err) logger.Error("vas begin fail, err: %v", err)
return err ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, err
} }
defer func() { defer func() {
@ -548,8 +550,9 @@ func (v *Vas) UnlockZoneIronfanshipRefresh(ctx *gin.Context, mid, zid, streamerM
}() }()
if tx == nil { if tx == nil {
ec = errcode.ErrcodeZoneIronFansRefreshErr
err := fmt.Errorf("nil tx") err := fmt.Errorf("nil tx")
return err return ec, err
} }
// 获取zid // 获取zid
@ -561,47 +564,54 @@ func (v *Vas) UnlockZoneIronfanshipRefresh(ctx *gin.Context, mid, zid, streamerM
} }
} }
if zid <= 0 { if zid <= 0 {
return fmt.Errorf("zone not exist, mid: %v, streamerMid: %v", mid, streamerMid) ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, fmt.Errorf("zone not exist, mid: %v, streamerMid: %v", mid, streamerMid)
} }
// 获取空间价格 // 获取空间价格
zVas, _ := v.store.GetZoneVasById(ctx, zid) zVas, _ := v.store.GetZoneVasById(ctx, zid)
if zVas == nil { if zVas == nil {
return fmt.Errorf("zone vas not exist, zid: %v", zid) ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, fmt.Errorf("zone vas not exist, zid: %v", zid)
} }
// 获取空间消费信息 // 获取空间消费信息
zUnlock, exists := v.CheckZoneUnlockExist(ctx, tx, mid, zid) zUnlock, exists := v.CheckZoneUnlockExist(ctx, tx, mid, zid)
if !exists { if !exists {
return fmt.Errorf("zone unlock not exist, mid: %v, zid: %v", mid, zid) ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, fmt.Errorf("zone unlock not exist, mid: %v, zid: %v", mid, zid)
} }
// 主播涨价后,原用户是否是铁粉 // 主播涨价后,原用户是否是铁粉
if zUnlock.IsUnlockIronfanship() { if zUnlock.IsUnlockIronfanship() {
logger.Info("UnlockZoneIronFanShipRefresh, users are already iron fans") logger.Info("UnlockZoneIronFanShipRefresh, users are already iron fans, mid: %v, streamerMid: %v", mid, streamerMid)
return nil ec = errcode.ErrcodeZoneIronFansAlreadyUnLock
return ec, nil
} }
if zUnlock.GetConsume() < zVas.IronfanshipPrice { if zUnlock.GetConsume() < zVas.IronfanshipPrice {
// 主播降价后消费额是否达到了解锁铁粉的消费额 // 主播降价后消费额是否达到了解锁铁粉的消费额
return fmt.Errorf("not reach ironfan unlock consume, mid: %v, zid: %v", mid, zid) ec = errcode.ErrcodeZoneIronFansNotUnLock
return ec, nil
} }
// 解锁铁粉 // 解锁铁粉
err = v.MustUnlockIronfanship(ctx, tx, mid, zid, -1, "ironfan", dbstruct.ZoneUnlockTypeReachConsume) err = v.MustUnlockIronfanship(ctx, tx, mid, zid, -1, "ironfan", dbstruct.ZoneUnlockTypeReachConsume)
if err != nil { if err != nil {
logger.Error("UnlockZoneIronfanshipRefresh MustUnlockIronfanship fail, mid: %v, zid: %v, err: %v", mid, zid, err) logger.Error("UnlockZoneIronfanshipRefresh MustUnlockIronfanship fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, err
} }
// 添加到空间成员 // 添加到空间成员
err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeIronfan) err = v.store.AddZoneMember(ctx, tx, mid, zid, dbstruct.ZoneMemberTypeIronfan)
if err != nil { if err != nil {
logger.Error("UnlockZoneIronfanshipRefresh AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err) logger.Error("UnlockZoneIronfanshipRefresh AddZoneMember normal fail, mid: %v, zid: %v, err: %v", mid, zid, err)
return err ec = errcode.ErrcodeZoneIronFansRefreshErr
return ec, err
} }
return nil return ec, nil
} }
type IncomeInfo struct { type IncomeInfo struct {

View File

@ -2209,13 +2209,13 @@ func (s *Service) UtilEncryptVideosForZoneMomentVOs(ctx *gin.Context, list []*zo
} }
} }
func (s *Service) FansIdentityRefresh(ctx *gin.Context, req *zonemomentproto.ApiFansIdentityRefreshReq) error { func (s *Service) FansIdentityRefresh(ctx *gin.Context, req *zonemomentproto.ApiFansIdentityRefreshReq) (errcode.ErrCode, error) {
err := _DefaultVas.FansIdentityRefresh(ctx, req.Mid, req.Zid) ec, err := _DefaultVas.FansIdentityRefresh(ctx, req.Mid, req.Zid)
if err != nil { if err != nil {
logger.Error("util service FansIdentityRefresh failed, err: %v", err) logger.Error("util service FansIdentityRefresh failed, err: %v", err)
return err return ec, err
} }
return nil return ec, nil
} }