From 8db2ce1071a6c5448a38efeb0146b51825b12d5a Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Sun, 28 Apr 2024 17:59:57 +0800 Subject: [PATCH] fix --- api/proto/zone/proto/zone_op.go | 12 +++++++ app/mix/controller/init.go | 2 ++ app/mix/controller/zone_op.go | 22 ++++++++++++ app/mix/service/logic/vas.go | 61 +++++++++++++++++++++++++++++++++ app/mix/service/service.go | 38 ++++++++++++++++++++ 5 files changed, 135 insertions(+) diff --git a/api/proto/zone/proto/zone_op.go b/api/proto/zone/proto/zone_op.go index 6fbe62a2..9d1278d5 100644 --- a/api/proto/zone/proto/zone_op.go +++ b/api/proto/zone/proto/zone_op.go @@ -83,3 +83,15 @@ type OpListByUserIdResp struct { base.BaseResponse Data *OpListByUserIdData `json:"data"` } + +// op 代运营解锁主播所有空间 +type OpZoneUnlockThirdPartnersParam struct { + ThirdPartMids []int64 `json:"third_part_mids"` // 代运营的mid + StreamerMid int64 `json:"streamer_mid"` // 主播的mid +} + +// op 代运营解锁主播所有空间 +type OpZoneUnlockCollaboratorsParam struct { + CollaboratorMids []int64 `json:"collaborator_mids"` // 协作者的mids + StreamerMid int64 `json:"streamer_mid"` // 主播的mid +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 0dafd2ce..a42ab38d 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -494,6 +494,8 @@ func Init(r *gin.Engine) { opZoneGroup.POST("delete", middleware.JSONParamValidator(zoneproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteZone) opZoneGroup.POST("list", middleware.JSONParamValidator(zoneproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetZoneList) opZoneGroup.POST("list_by_user_id", middleware.JSONParamValidator(zoneproto.OpListByUserIdReq{}), middleware.JwtAuthenticator(), OpGetZoneListByUserId) + opZoneGroup.POST("unlock_third_partners", middleware.JSONParamValidator(zoneproto.OpZoneUnlockThirdPartnersParam{}), OpZoneUnlockThirdPartners) + opZoneGroup.POST("unlock_collaborators", middleware.JSONParamValidator(zoneproto.OpZoneUnlockCollaboratorsParam{}), OpZoneUnlockCollaborators) // 私密圈动态 opZoneMomentGroup := r.Group("/op/zone_moment", PrepareOp()) diff --git a/app/mix/controller/zone_op.go b/app/mix/controller/zone_op.go index d2ab8f35..7475f3ca 100644 --- a/app/mix/controller/zone_op.go +++ b/app/mix/controller/zone_op.go @@ -96,3 +96,25 @@ func OpGetZoneListByUserId(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func OpZoneUnlockThirdPartners(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*zoneproto.OpZoneUnlockThirdPartnersParam) + err := service.DefaultService.OpZoneUnlockThirdPartners(ctx, req) + if err != nil { + logger.Error("OpZoneUnlockThirdPartners fail, req: %v, err: %v", util.ToJson(req), err) + ReplyErrorMsg(ctx, err.Error()) + return + } + ReplyOk(ctx, nil) +} + +func OpZoneUnlockCollaborators(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*zoneproto.OpZoneUnlockCollaboratorsParam) + err := service.DefaultService.OpZoneUnlockCollaborators(ctx, req) + if err != nil { + logger.Error("OpZoneUnlockCollaborators fail, req: %v, err: %v", util.ToJson(req), err) + ReplyErrorMsg(ctx, err.Error()) + return + } + ReplyOk(ctx, nil) +} diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 97a8320b..4c754426 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1787,6 +1787,67 @@ func (v *Vas) DealOneOrder(ctx *gin.Context, orderId string) (err error) { switch order.GetProductId() { case dbstruct.ProductIdMembership: return v.dealOneMembershipOrder(ctx, tx, order) + case dbstruct.ProductIdH5ZoneAdmission, dbstruct.ProductIdH5ZoneMoment, dbstruct.ProductIdH5ZoneSuperfanship: + return v.dealOneZoneOrder(ctx, tx, order) + } + return +} + +// 结算空订单 +func (v *Vas) dealOneZoneOrder(ctx *gin.Context, tx *sqlx.Tx, order *dbstruct.Order) (err error) { + // 把订单对应的收入记录拿出来 + chList, err := v.store.GetIncomeCHList(ctx, tx, order.GetID()) + if err != nil { + logger.Error("GetIncomeCHList fail, orderId: %v, err: %v", order.GetID(), err) + return + } + + // 处理 + for _, ch := range chList { + if ch.GetMid() == common.OfficialMid { + continue + } + + // 获取钱包 + wallet, errIn := v.store.GetWalletForUpdate(ctx, tx, ch.GetMid()) + if errIn != nil { + logger.Error("GetWalletForUpdate fail, mid: %v, err: %v", ch.GetMid(), errIn) + err = errIn + return + } + + // 添加记录 + h := &dbstruct.WithdrawDiamondsHis{ + Mid: goproto.Int64(ch.GetMid()), + IncomeChId: goproto.Int64(ch.GetId()), + OrderId: goproto.String(ch.GetOrderId()), + Ct: goproto.Int64(time.Now().Unix()), + BeforeWithdrawDiamonds: goproto.Int64(wallet.GetWithdrawDiamonds()), + AfterWithdrawDiamonds: goproto.Int64(wallet.GetWithdrawDiamonds() + ch.GetChange()), + Change: goproto.Int64(ch.GetChange()), + ProductId: goproto.String(order.GetProductId()), + } + errIn = v.store.CreateWithdrawDiamondsHis(ctx, tx, h) + if errIn != nil { + logger.Error("CreateWithdrawDiamondsHis fail, mid: %v, err: %v", ch.GetMid(), errIn) + err = errIn + return + } + + // 更新钱包 + errIn = v.store.IncWithdrawDiamonds(ctx, tx, ch.GetMid(), ch.GetChange()) + if errIn != nil { + logger.Error("IncWithdrawDiamonds fail, mid: %v, change: %v, err: %v", ch.GetMid(), ch.GetChange(), errIn) + err = errIn + return + } + } + + // 更新订单状态 + err = v.store.UpdateOrderStatus(ctx, tx, order.GetID(), dbstruct.VasOrderStatusPaySuccess, dbstruct.VasOrderStatusFinish) + if err != nil { + logger.Error("UpdateOrderStatus fail, orderId: %v, err: %v", order.GetID(), err) + return } return } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 6201517a..b1cebdfa 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3566,3 +3566,41 @@ func (s *Service) OpGetZoneCollaboratorList(ctx *gin.Context, req *zone_collabor } return } + +func (s *Service) OpZoneUnlockThirdPartners(ctx *gin.Context, req *zoneproto.OpZoneUnlockThirdPartnersParam) error { + zone, err := _DefaultZone.GetByMid(ctx, req.StreamerMid) + if err != nil { + return err + } + if zone == nil { + err = fmt.Errorf("GetByMid nil") + return err + } + + for _, mid := range req.ThirdPartMids { + err = _DefaultVas.ZoneFreeJoinThirdPartner(ctx, mid, zone.GetId()) + if err != nil { + return err + } + } + return nil +} + +func (s *Service) OpZoneUnlockCollaborators(ctx *gin.Context, req *zoneproto.OpZoneUnlockCollaboratorsParam) error { + zone, err := _DefaultZone.GetByMid(ctx, req.StreamerMid) + if err != nil { + return err + } + if zone == nil { + err = fmt.Errorf("GetByMid nil") + return err + } + + for _, mid := range req.CollaboratorMids { + err = _DefaultVas.ZoneFreeJoinCollaborator(ctx, mid, zone.GetId()) + if err != nil { + return err + } + } + return nil +}