本周迭代

This commit is contained in:
lwl0608 2024-05-14 10:55:49 +08:00
parent a9f7be9f7b
commit 4bf3a744b3
9 changed files with 114 additions and 7 deletions

View File

@ -294,6 +294,7 @@ const (
ErrCodeVasInvalidVerifycode ErrCode = -7020 // 提现验证码错误
ErrCodeVasAlipayUniTransferFail ErrCode = -7021 // 支付宝提现失败
ErrCodeVasOverTodayWithdrawCnt ErrCode = -7022 // 今天提现次数到达上限
ErrCodeVasOverRefundLimit ErrCode = -7023 // 退款次数达上限
// Moment: 8xxx
ErrCodeMomentSrvOk ErrCode = ErrCodeOk

View File

@ -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("账号已受限,解限请联系客服")
)

View File

@ -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())

View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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
}