From 4bf3a744b391fa0f6c833f563e079c04b33afa6a Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Tue, 14 May 2024 10:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=91=A8=E8=BF=AD=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/errcode/errcode.go | 1 + api/errs/error.go | 7 +++---- app/mix/controller/init.go | 1 + app/mix/controller/vas.go | 6 +++++- app/mix/controller/zone_vas_api.go | 28 ++++++++++++++++++++++++++++ app/mix/dao/mysql_zone.go | 24 ++++++++++++++++++++++++ app/mix/service/logic/vas_zone.go | 22 ++++++++++++++++++++++ app/mix/service/service.go | 4 ++-- app/mix/service/vasservice.go | 28 ++++++++++++++++++++++++++++ 9 files changed, 114 insertions(+), 7 deletions(-) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index 16fdf437..2ca10d49 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -294,6 +294,7 @@ const ( ErrCodeVasInvalidVerifycode ErrCode = -7020 // 提现验证码错误 ErrCodeVasAlipayUniTransferFail ErrCode = -7021 // 支付宝提现失败 ErrCodeVasOverTodayWithdrawCnt ErrCode = -7022 // 今天提现次数到达上限 + ErrCodeVasOverRefundLimit ErrCode = -7023 // 退款次数达上限 // Moment: 8xxx ErrCodeMomentSrvOk ErrCode = ErrCodeOk diff --git a/api/errs/error.go b/api/errs/error.go index 80e88a7a..683cf0e0 100644 --- a/api/errs/error.go +++ b/api/errs/error.go @@ -8,12 +8,9 @@ import ( func DealVasErr(err error) (errcode.ErrCode, error) { var ( ec = errcode.ErrCodeVasSrvOk - ok bool ) if err != nil { - ec, ok = ErrEcMap[err] - err = errors.Wrap(err, "VasError") - if ok { + if ec, ok := ErrEcMap[err]; ok { return ec, err } ec = errcode.ErrCodeVasSrvFail @@ -41,6 +38,7 @@ var ErrEcMap = map[error]errcode.ErrCode{ ErrVasNoEnoughWithdrawDias: errcode.ErrCodeVasNoEnoughWithdrawDias, ErrVasAlipayUniTransferFail: errcode.ErrCodeVasAlipayUniTransferFail, ErrVasOverTodayWithdrawCnt: errcode.ErrCodeVasOverTodayWithdrawCnt, + ErrVasRefundLimit: errcode.ErrCodeVasOverRefundLimit, } var ( @@ -62,4 +60,5 @@ var ( ErrVasNoEnoughWithdrawDias = errors.New("no enough withdraw dias") ErrVasAlipayUniTransferFail = errors.New("alipay uni transfer fail") ErrVasOverTodayWithdrawCnt = errors.New("over today withdraw cnt") + ErrVasRefundLimit = errors.New("账号已受限,解限请联系客服") ) diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 280caffa..21902fa2 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -227,6 +227,7 @@ func Init(r *gin.Engine) { apiZoneGroup.POST("member_list", middleware.JSONParamValidator(vasproto.GetZoneMemberListReq{}), ZoneMemberList) apiZoneGroup.POST("free_join", middleware.JSONParamValidator(vasproto.ZoneFreeJoinReq{}), ZoneFreeJoin) apiZoneGroup.POST("exit", middleware.JSONParamValidator(vasproto.ZoneExitReq{}), ZoneExit) + apiZoneGroup.POST("moment_order_list", middleware.JSONParamValidator(vasproto.ZoneMomentOrderListReq{}), ZoneMomentOrderList) // 私密圈动态 apiZoneMomentGroup := r.Group("/api/zone_moment", PrepareToC()) diff --git a/app/mix/controller/vas.go b/app/mix/controller/vas.go index 5fa10d03..4bee0099 100644 --- a/app/mix/controller/vas.go +++ b/app/mix/controller/vas.go @@ -50,9 +50,13 @@ func CreateOrder(ctx *gin.Context) { ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) return } - data, ec := service.DefaultService.CreateOrder(ctx, req) + data, ec, err := service.DefaultService.CreateOrder(ctx, req) if ec != errcode.ErrCodeVasSrvOk { logger.Error("CreateOrder fail, req: %v, ec: %v", util.ToJson(req), ec) + if ec == errcode.ErrCodeVasSrvFail && err != nil { + ReplyErrorMsg(ctx, err.Error()) + return + } ReplyErrCodeMsg(ctx, ec) return } diff --git a/app/mix/controller/zone_vas_api.go b/app/mix/controller/zone_vas_api.go index e0ad9ad2..9a335cd6 100644 --- a/app/mix/controller/zone_vas_api.go +++ b/app/mix/controller/zone_vas_api.go @@ -155,3 +155,31 @@ func ZoneExit(ctx *gin.Context) { } ReplyOk(ctx, nil) } + +func ZoneMomentOrderList(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*vasproto.ZoneMomentOrderListReq) + if req.Mid <= 0 || req.MomentId <= 0 { + logger.Error("ZoneExit, invalid param, req: %v", util.ToJson(req)) + ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) + return + } + list, ec, err := service.DefaultService.ZoneMomentOrderList(ctx, req) + if ec != errcode.ErrCodeVasSrvOk { + logger.Error("ZoneExit fail, req: %v, ec: %v", util.ToJson(req), ec) + if ec == errcode.ErrCodeVasSrvFail && err != nil { + ReplyErrorMsg(ctx, err.Error()) + return + } + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &vasproto.ZoneMomentOrderListData{ + List: list, + Offset: req.Offset + len(list), + } + if len(list) >= req.Limit { + data.More = 1 + } + ReplyOk(ctx, nil) +} diff --git a/app/mix/dao/mysql_zone.go b/app/mix/dao/mysql_zone.go index fc8322a1..de24837d 100644 --- a/app/mix/dao/mysql_zone.go +++ b/app/mix/dao/mysql_zone.go @@ -499,3 +499,27 @@ func (m *Mysql) GetZoneRefundHisList(ctx *gin.Context, tx *sqlx.Tx, mid, zid int } return } + +// 获取空间动态购买记录 +func (m *Mysql) GetZoneMomentUnlockList(ctx *gin.Context, tx *sqlx.Tx, momentId int64, offset, limit int) (list []*dbstruct.ZoneMomentUnlock, err error) { + list = make([]*dbstruct.ZoneMomentUnlock, 0) + var ( + sqlStr string + args = make([]any, 0) + ) + sqlStr = fmt.Sprintf("select * from %s where moment_id=%d limit %d offset %d", TableVasZoneMomentUnlock, momentId, limit, offset) + if tx != nil { + err = tx.SelectContext(ctx, &list, sqlStr, args...) + } else { + db := m.getDBVas() + err = db.SelectContext(ctx, &list, sqlStr, args...) + } + if err == sql.ErrNoRows { + err = nil + return + } + if err != nil { + return + } + return +} diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index 9fd108c2..2c2d7db9 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -14,6 +14,7 @@ import ( "service/bizcommon/util" "service/dbstruct" "service/library/logger" + "service/library/redis" "time" ) @@ -911,7 +912,20 @@ func (v *Vas) ZoneGetRefundPage(ctx *gin.Context, req *vasproto.ZoneRefundPageRe } // 空间退款 +func getCheckZoneRefundFreqKey(mid int64) string { + return fmt.Sprintf("zone_refund_freq_%d", mid) +} + func (v *Vas) ZoneRefund(ctx *gin.Context, req *vasproto.ZoneRefundReq) error { + redisKey := getCheckZoneRefundFreqKey(req.Mid) + redisCli := redis.GetRedisClient() + // 获取上次退款时间 + t, _ := redisCli.GetInt64(redisKey) + logger.Info("ZoneRefund check freq, key: %v, t: %v", redisKey, t) + if time.Now().Unix()-t < 3600*12 { + return fmt.Errorf("12小时内您最多只能进行1次退款") + } + // 获取解锁信息 zv, err := v.store.GetZoneUnlock(ctx, nil, req.Mid, req.Zid) if err == sql.ErrNoRows || zv == nil { @@ -951,6 +965,9 @@ func (v *Vas) ZoneRefund(ctx *gin.Context, req *vasproto.ZoneRefundReq) error { return err } + // redis记录退款时间 + _ = redisCli.Set(redisKey, time.Now().Unix(), 86400) + return nil } @@ -1184,3 +1201,8 @@ func (v *Vas) ZoneExit(ctx *gin.Context, mid, zid int64) error { return nil } + +// 获取动态解锁记录 +func (v *Vas) GetZoneMomentUnlockList(ctx *gin.Context, momentId int64, offset, limit int) (list []*dbstruct.ZoneMomentUnlock, err error) { + return v.store.GetZoneMomentUnlockList(ctx, nil, momentId, offset, limit) +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index a2131b30..71f07397 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -1015,7 +1015,7 @@ func (s *Service) GetMembershipProductList(ctx *gin.Context, req *vasproto.GetMe return } -func (s *Service) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data *vasproto.CreateOrderData, ec errcode.ErrCode) { +func (s *Service) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data *vasproto.CreateOrderData, ec errcode.ErrCode, err error) { switch req.ProductId { case dbstruct.ProductIdMembership: req.ReturnUrl = "https://tiefen.fun/vip" @@ -1023,7 +1023,7 @@ func (s *Service) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (d req.ReturnUrl = "https://tiefen.fun/pay" } - data, err := _DefaultVas.CreateOrder(ctx, req) + data, err = _DefaultVas.CreateOrder(ctx, req) ec, err = errs.DealVasErr(err) if err != nil { logger.Error("CreateOrder fail, err: %v", err) diff --git a/app/mix/service/vasservice.go b/app/mix/service/vasservice.go index 051660fe..5e1c1f01 100644 --- a/app/mix/service/vasservice.go +++ b/app/mix/service/vasservice.go @@ -1040,3 +1040,31 @@ func (s *Service) OpZoneRefundList(ctx *gin.Context, req *zoneproto.OpZoneRefund } return } + +func (s *Service) ZoneMomentOrderList(ctx *gin.Context, req *vasproto.ZoneMomentOrderListReq) (list []*vasproto.ZoneMomentOrderVO, ec errcode.ErrCode, err error) { + list = make([]*vasproto.ZoneMomentOrderVO, 0) + // 空间动态解锁历史 + zmuList, err := _DefaultVas.GetZoneMomentUnlockList(ctx, req.MomentId, req.Offset, req.Limit) + ec, err = errs.DealVasErr(err) + if err != nil { + return + } + + // 获取账号 + mids := make([]int64, 0) + for _, zmu := range zmuList { + mids = append(mids, zmu.GetMid()) + } + acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids) + + // 组装 + for _, zmu := range zmuList { + item := &vasproto.ZoneMomentOrderVO{ + Account: acntMap[zmu.GetMid()], + BuyTime: zmu.GetCt(), + OrderId: zmu.GetOrderId(), + } + list = append(list, item) + } + return +}