rollback z refund

This commit is contained in:
lwl0608 2024-08-27 16:57:50 +08:00
parent 087eaaf786
commit d5f00f015d
6 changed files with 104 additions and 0 deletions

View File

@ -146,3 +146,8 @@ type OpRollbackZoneExitStatusParam struct {
Userid int64 `json:"userid"`
StreamerUserid int64 `json:"streamer_userid"`
}
type OpRollbackZoneRefundStatusParam struct {
Userid int64 `json:"userid"`
StreamerUserid int64 `json:"streamer_userid"`
}

View File

@ -345,6 +345,7 @@ func Init(r *gin.Engine) {
opVasPayGroup.POST("zone_refund_list", middleware.JSONParamValidator(zoneproto.OpZoneRefundListParam{}), OpZoneRefundList)
opVasPayGroup.POST("manual_unlock_wechat", middleware.JSONParamValidator(zoneproto.OpManualUnlockWechatParam{}), OpManualUnlockWechat)
opVasPayGroup.POST("rollback_zone_exit_status", middleware.JSONParamValidator(zoneproto.OpRollbackZoneExitStatusParam{}), OpRollbackZoneAdmissionExitStatus)
opVasPayGroup.POST("rollback_zone_refund_status", middleware.JSONParamValidator(zoneproto.OpRollbackZoneRefundStatusParam{}), OpRollbackZoneRefundExitStatus)
// 慧用工
extHvyogoGroup := r.Group("/ext/hvyogo")

View File

@ -90,3 +90,18 @@ func OpRollbackZoneAdmissionExitStatus(ctx *gin.Context) {
}
ReplyOk(ctx, nil)
}
func OpRollbackZoneRefundExitStatus(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zoneproto.OpRollbackZoneRefundStatusParam)
ec, err := service.DefaultService.OpRollbackZoneRefundStatus(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("OpRollbackZoneAdmissionExitStatus fail, req: %v, ec: %v", util.ToJson(req), ec)
if err != nil {
ReplyErrorMsg(ctx, err.Error())
return
}
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}

View File

@ -607,3 +607,20 @@ func (m *Mysql) RollbackZoneAdmissionExitStatus(ctx *gin.Context, tx *sqlx.Tx, o
}
return err
}
// 回滚空间退出状态
func (m *Mysql) RollbackZoneAdmissionRefundStatus(ctx *gin.Context, tx *sqlx.Tx, mid, zid int64) error {
var err error
sqlStr := "update " + TableVasZoneUnlock + " set admission_ct=?, admission_until=?, admission_unlock_type=?, admission_order_id=? where mid=? and zid=?"
args := []any{0, 0, 0, "", mid, zid}
if tx != nil {
_, err = tx.ExecContext(ctx, sqlStr, args...)
} else {
db := m.getDBVas()
_, err = db.ExecContext(ctx, sqlStr, args...)
}
if err != nil {
return err
}
return err
}

View File

@ -1301,3 +1301,7 @@ func (v *Vas) ZoneGetIncomePage(ctx *gin.Context, mid int64) (*vasproto.IncomePa
func (v *Vas) RollbackZoneAdmissionExitStatus(ctx *gin.Context, ct, mid, zid int64) (err error) {
return v.store.RollbackZoneAdmissionExitStatus(ctx, nil, ct, mid, zid)
}
func (v *Vas) RollbackZoneAdmissionRefundStatus(ctx *gin.Context, mid, zid int64) (err error) {
return v.store.RollbackZoneAdmissionRefundStatus(ctx, nil, mid, zid)
}

View File

@ -1257,3 +1257,65 @@ func (s *Service) OpRollbackZoneAdmissionExitStatus(ctx *gin.Context, req *zonep
logger.Info("RollbackZoneAdmissionExitStatus success, uid: %v, suid: %v, mid: %v, sMid: %v, zu: %v", req.Userid, req.StreamerUserid, uMid, sMid, util.ToJson(zu))
return
}
func (s *Service) OpRollbackZoneRefundStatus(ctx *gin.Context, req *zoneproto.OpRollbackZoneRefundStatusParam) (ec errcode.ErrCode, err error) {
defer func() {
ec, err = errs.DealVasErr(err)
}()
// 获取用户mid
userAcnt, _ := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{UserId: goproto.Int64(req.Userid)})
// 获取主播mid
streamerAcnt, _ := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{UserId: goproto.Int64(req.StreamerUserid)})
// 获取主播空间id
zone, _ := _DefaultZone.GetByMid(ctx, streamerAcnt.GetMid())
var (
uMid = userAcnt.GetMid()
sMid = streamerAcnt.GetMid()
zid = zone.GetId()
)
zuMap, err := _DefaultVas.GetZoneUnlockMapByMidZids(ctx, uMid, []int64{zid})
if err != nil {
logger.Error("GetZoneUnlockMapByMidZids fail, mid: %v, sMid: %v, zid: %v, err: %v", uMid, sMid, zid, err)
return
}
zu := zuMap[zid]
if zu == nil {
err = fmt.Errorf("无对应解锁记录")
logger.Error("invalid zu, mid: %v, sMid: %v, zid: %v", uMid, sMid, zid)
return
}
// 检查是否主动退出
if zu.GetAdmissionUnlockType() != dbstruct.ZoneUnlockTypeRefund {
err = fmt.Errorf("该用户没有退款空间, typ:%v, 订单id: %v", zu.GetAdmissionUnlockType(), zu.GetAdmissionOrderId())
logger.Error("%v, mid: %v, sMid: %v, zid: %v, zu: %v", err, uMid, sMid, zid, util.ToJson(zu))
return
}
// 检查订单状态
orderId := zu.GetAdmissionOrderId()
order, err := _DefaultVas.GetOrderById(ctx, nil, orderId)
if err != nil {
logger.Error("GetOrderById fail, mid: %v, sMid: %v, zid: %v, orderId: %v, err: %v", uMid, sMid, zid, orderId, err)
return
}
if !util.InInt32Slice([]int32{dbstruct.VasOrderStatusRefund}, order.GetOrderStatus()) {
err = fmt.Errorf("订单状态异常, oderrId:%v", orderId)
logger.Error("%v, mid: %v, sMid: %v, zid: %v, order: %v", err, uMid, sMid, zid, util.ToJson(order))
return
}
// 回滚
err = _DefaultVas.RollbackZoneAdmissionRefundStatus(ctx, uMid, zid)
if err != nil {
logger.Error("RollbackZoneAdmissionRefundStatus fail, mid: %v, sMid: %v, zid: %v, zu: %v, err: %v", uMid, sMid, zid, util.ToJson(zu), err)
err = fmt.Errorf("回滚失败")
return
}
logger.Info("RollbackZoneAdmissionRefundStatus success, uid: %v, suid: %v, mid: %v, sMid: %v, zu: %v", req.Userid, req.StreamerUserid, uMid, sMid, util.ToJson(zu))
return
}