diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 4aacae31..f68f680e 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -597,7 +597,7 @@ func (v *Vas) OneStepUnlockContact(ctx *gin.Context, req *vasproto.OneStepUnlock v.CheckWalletExist(ctx, nil, common.OfficialMid) // 是否已经解锁过 - unlockInfo, _ := v.store.GetUserVasUnlock(ctx, nil, mid, uid, contactProductId) + unlockInfo, _ := v.store.GetUserVasUnlock(ctx, nil, mid, uid, dbstruct.ProductIdContactWechat) if unlockInfo != nil { err = errs.ErrVasAlreadyUnlock return @@ -831,6 +831,108 @@ func (v *Vas) OneStepUnlockContact(ctx *gin.Context, req *vasproto.OneStepUnlock return } +// 超粉解锁微信 +func (v *Vas) SuperfanUnlockContact(ctx *gin.Context, tx *sqlx.Tx, mid, streamerMid int64, superfanOrderId string) (err error) { + var ( + uid = streamerMid + contactProductId = dbstruct.ProductIdContactWechat // 要解锁的联系方式 + ) + + // 是否已经解锁过 + unlockInfo, _ := v.store.GetUserVasUnlock(ctx, nil, mid, uid, dbstruct.ProductIdContactWechat) + if unlockInfo != nil { + err = errs.ErrVasAlreadyUnlock + return + } + + // 获取uid增值信息 + uVasInfo, err := v.store.GetUserVasInfoByMid(ctx, uid) + if err != nil { + logger.Error("GetUserVasInfoByMid fail, mid: %v, uid: %v, err: %v", mid, uid, err) + return + } + if uVasInfo == nil { + err = errs.ErrVasUserVasNotExist + logger.Warn("no user_vas info, mid: %v, uid: %v, err: %v", mid, uid, err) + return + } + + var ( + timeNow = time.Now().Unix() + coinOrderId = idgenerator.GenCoinOrderId() + coinOrder *dbstruct.CoinOrder + ) + + // 生成金币订单 + coinOrder = &dbstruct.CoinOrder{ + ID: goproto.String(coinOrderId), + Mid: goproto.Int64(mid), + Uid: goproto.Int64(uid), + Oid2: goproto.String(superfanOrderId), + Oid3: goproto.String(dbstruct.ProductIdSuperfanGiftContactWechat), + ProductId: goproto.String(contactProductId), + Coins: goproto.Int64(0), + Ct: goproto.Int64(timeNow), + Ut: goproto.Int64(timeNow), + } + switch uVasInfo.WechatLockType { + case dbstruct.UserVasLockTypeOpen: + coinOrder.OrderStatus = goproto.Int32(dbstruct.VasCoinOrderStatusWaitDeal) + case dbstruct.UserVasLockTypeLock: + coinOrder.OrderStatus = goproto.Int32(dbstruct.VasCoinOrderStatusNotFill) + } + err = v.store.CreateCoinOrder(ctx, tx, coinOrder) + if err != nil { + logger.Error("CreateCoinOrder fail, order: %v, err: %v", util.ToJson(coinOrder), err) + return + } + + // 增加金币消费历史 + ch := &dbstruct.ConsumeHistory{ + Mid: goproto.Int64(mid), + Uid: goproto.Int64(uid), + Did: goproto.String(""), + Type: goproto.Int32(dbstruct.CHTypeCost), + SType: goproto.Int32(dbstruct.CHSTypeCostContact), + TypeId: goproto.String(contactProductId), + OrderId: goproto.String(coinOrderId), + Change: goproto.Int64(-0), + Before: goproto.Int64(0), + After: goproto.Int64(0), + Ct: goproto.Int64(timeNow), + } + err = v.store.CreateConsumeHistory(ctx, tx, ch) + if err != nil { + logger.Error("CreateConsumeHistory fail, ch: %v, err: %v", util.ToJson(ch), err) + return + } + + // 解锁记录 + userVasUnlock := &dbstruct.UserVasUnlock{ + Mid: goproto.Int64(mid), + Uid: goproto.Int64(uid), + ProductId: goproto.String(contactProductId), + Ct: goproto.Int64(timeNow), + LockType: goproto.Int32(uVasInfo.WechatLockType), + Means: goproto.String(dbstruct.UserVasUnlockMeansCoins), + OrderId: goproto.String(coinOrderId), + } + switch uVasInfo.WechatLockType { + case dbstruct.UserVasLockTypeOpen: + userVasUnlock.Status = goproto.Int32(dbstruct.UserVasUnlockStatusFinish) + case dbstruct.UserVasLockTypeLock: + userVasUnlock.Status = goproto.Int32(dbstruct.UserVasUnlockStatusWait) + } + err = v.store.CreateUserVasUnlock(ctx, tx, userVasUnlock) + if err != nil { + logger.Error("CreateUserVasUnlock fail, userVasUnlock: %v, err: %v", util.ToJson(userVasUnlock), err) + return + } + + logger.Info("OneStepUnlockContact superfan success, mid: %v, uid: %v, coinOrderId: %v", mid, uid, coinOrderId) + return +} + // 用户填写联系方式 func (v *Vas) ConsumerFillContact(ctx *gin.Context, req *vasproto.ConsumerFillContactReq) (err error) { var ( diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index a785cadd..816398ee 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -3,7 +3,6 @@ package logic import ( "database/sql" "fmt" - "service/api/base" "service/api/errs" vasproto "service/api/proto/vas/proto" zone_collaborator_proto "service/api/proto/zone_collaborator/proto" @@ -451,16 +450,9 @@ func (v *Vas) UnlockZoneSuperfanship(ctx *gin.Context, tx *sqlx.Tx, order *dbstr if zv.IsSuperfanshipGiveWechat != 1 { return nil } - _, _, _, _err = v.OneStepUnlockContact(ctx, &vasproto.OneStepUnlockContactReq{ - BaseRequest: base.BaseRequest{ - Mid: mid, - }, - ContactProductId: dbstruct.ProductIdSuperfanGiftContactWechat, - Uid: zv.Mid, - Oid2: orderId, - }) + _err = v.SuperfanUnlockContact(ctx, tx, mid, zv.Mid, orderId) if _err != nil { - logger.Error("OneStepUnlockContact fail, mid: %v, zid: %v, uid: %v, orderId: %v, err: %v", mid, zid, zv.Mid, orderId, _err) + logger.Error("SuperfanUnlockContact fail, mid: %v, zid: %v, uid: %v, orderId: %v, err: %v", mid, zid, zv.Mid, orderId, _err) } return nil