service/app/mix/service/vasservice.go

364 lines
10 KiB
Go

package service
import (
"fmt"
"github.com/gin-gonic/gin"
"service/api/errcode"
"service/api/errs"
vasproto "service/api/proto/vas/proto"
"service/bizcommon/util"
"service/dbstruct"
"service/library/logger"
)
// 一键解锁
func (s *Service) OneStepUnlockContact(ctx *gin.Context, req *vasproto.OneStepUnlockContactReq) (data *vasproto.OneStepUnlockContactData, ec errcode.ErrCode) {
// 获取uid的邀请人
req.InviterMid = s.getUidInviterMid(ctx, req.Uid)
lockType, orderId, contact, err := _DefaultVas.OneStepUnlockContact(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("OneStepUnlockContact fail, req: %v, err: %v", util.ToJson(req), err)
return
}
data = &vasproto.OneStepUnlockContactData{
LockType: lockType,
OrderId: orderId,
Contact: contact,
}
return
}
func (s *Service) getUidInviterMid(ctx *gin.Context, uid int64) int64 {
mp, _ := _DefaultStreamer.GetStreamerMapByMids(ctx, []int64{uid})
if mp[uid] == nil {
return 0
}
if mp[uid].Inviters != nil && len(*mp[uid].Inviters) > 0 {
return (*mp[uid].Inviters)[0]
}
return 0
}
// 填写联系方式
func (s *Service) ConsumerFillContact(ctx *gin.Context, req *vasproto.ConsumerFillContactReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
var ok bool
err := _DefaultVas.ConsumerFillContact(ctx, req)
if err != nil {
logger.Error("ConsumerFillContact fail, req: %v, err: %v", util.ToJson(req), err)
ec, ok = errs.ErrEcMap[err]
if ok {
return
}
ec = errcode.ErrCodeVasSrvFail
return
}
return
}
// 添加微信列表
func (s *Service) GetAddWechatList(ctx *gin.Context, req *vasproto.GetAddWechatListReq) (data *vasproto.GetAddWechatListData, ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
coinOrders, err := _DefaultVas.GetAddWechatCoinOrders(ctx, req.Mid, req.Offset, req.Limit, req.Tab)
if err != nil {
logger.Error("GetAddWechatCoinOrders fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeVasSrvFail
return
}
logger.Info("GetAddWechatCoinOrders len: %v", len(coinOrders))
// 获取用户
mids := make([]int64, 0)
for _, co := range coinOrders {
mids = append(mids, co.GetMid())
}
acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids)
logger.Info("GetAccountMapByMids mids: %v, len: %v", mids, len(mids))
// 组装
list := make([]*vasproto.AddWechatSt, 0)
for _, co := range coinOrders {
acnt, ok := acntMap[co.GetMid()]
if !ok {
continue
}
item := &vasproto.AddWechatSt{
Account: acnt,
OrderId: co.GetID(),
OrderStatus: util.DerefInt32(co.OrderStatus),
Ct: util.DerefInt64(co.Ct),
ConsumerWechat: util.DerefString(co.Wechat),
ConsumerNote: util.DerefString(co.Note),
}
list = append(list, item)
}
data = &vasproto.GetAddWechatListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
return
}
// 确定添加微信
func (s *Service) ConfirmAddWechat(ctx *gin.Context, req *vasproto.ConfirmAddWechatReq) (data *vasproto.GetAddWechatListData, ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
var ok bool
err := _DefaultVas.ConfirmAddWechat(ctx, req.Mid, req.OrderId)
if err != nil {
logger.Error("ConfirmAddWechat fail, req: %v, err: %v", util.ToJson(req), err)
ec, ok = errs.ErrEcMap[err]
if ok {
return
}
ec = errcode.ErrCodeVasSrvFail
return
}
return
}
// 已解锁微信列表
func (s *Service) GetUnlockWechatList(ctx *gin.Context, req *vasproto.GetUnlockWechatListReq) (data *vasproto.GetUnlockWechatListData, ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
unlockList, err := _DefaultVas.GetUnlockWechatList(ctx, req.Mid, req.Offset, req.Limit)
if err != nil {
logger.Error("GetUnlockWechatList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeVasSrvFail
return
}
// 获取用户
mids := make([]int64, 0)
for _, uu := range unlockList {
mid := util.DerefInt64(uu.Uid)
if mid > 0 {
mids = append(mids, mid)
}
}
acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids)
streamerMap, _ := _DefaultStreamer.GetStreamerMapByMids(ctx, mids)
// 组装
list := make([]*vasproto.UnlockWechatSt, 0)
for _, uu := range unlockList {
acnt, ok := acntMap[uu.GetUid()]
if !ok {
continue
}
streamer, ok := streamerMap[uu.GetUid()]
if !ok {
continue
}
coinOrderId := uu.GetOrderId()
coinOrder, _ := _DefaultVas.GetCoinOrderById(ctx, coinOrderId)
item := &vasproto.UnlockWechatSt{
Streamer: streamer,
Account: acnt,
LockType: uu.GetLockType(),
OrderId: coinOrderId,
OrderStatus: coinOrder.GetOrderStatus(),
}
list = append(list, item)
}
data = &vasproto.GetUnlockWechatListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
return
}
func (s *Service) GetCHList(ctx *gin.Context, req *vasproto.GetCHListReq) (data *vasproto.GetCHListData, ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
chList, err := _DefaultVas.GetCHList(ctx, req.Mid, req.Type, req.Offset, req.Limit)
if err != nil {
logger.Error("GetUnlockWechatList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeVasSrvFail
return
}
var list = make([]*vasproto.CHSt, 0)
switch req.Type {
case dbstruct.CHTypeCost:
list = s.chListCost(ctx, chList)
case dbstruct.CHTypeCharge:
list = s.chListCharge(ctx, chList)
case dbstruct.CHTypeIncome:
list = s.chListIncome(ctx, chList)
case dbstruct.CHTypeWithdraw:
list = s.chListWithdraw(ctx, chList)
}
data = &vasproto.GetCHListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
return
}
func (s *Service) chListCost(ctx *gin.Context, chList []*dbstruct.ConsumeHistory) (list []*vasproto.CHSt) {
// 获取用户
mids := make([]int64, 0)
for _, chDB := range chList {
mid := util.DerefInt64(chDB.Uid)
if mid > 0 {
mids = append(mids, mid)
}
}
acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids)
// 组装
list = make([]*vasproto.CHSt, 0)
for _, chDB := range chList {
mid := util.DerefInt64(chDB.Uid)
acnt, ok := acntMap[mid]
if !ok {
continue
}
item := &vasproto.CHSt{
Ct: util.DerefInt64(chDB.Ct),
}
changeMark := "-"
if chDB.GetChange() > 0 {
changeMark = "+"
}
switch chDB.GetSType() {
case dbstruct.CHSTypeCostContact:
item.Desc = fmt.Sprintf("购买\"%s\"微信", util.DerefString(acnt.Name))
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
if chDB.GetChange() < 0 {
item.Change = fmt.Sprintf("%d金币", chDB.GetChange())
}
case dbstruct.CHSTypeCostRefund:
item.Desc = fmt.Sprintf("购买\"%s\"微信退款", util.DerefString(acnt.Name))
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
}
list = append(list, item)
}
return
}
func (s *Service) chListCharge(ctx *gin.Context, chList []*dbstruct.ConsumeHistory) (list []*vasproto.CHSt) {
// 组装
list = make([]*vasproto.CHSt, 0)
for _, chDB := range chList {
item := &vasproto.CHSt{
Ct: util.DerefInt64(chDB.Ct),
}
changeMark := "-"
if chDB.GetChange() > 0 {
changeMark = "+"
}
switch chDB.GetSType() {
case dbstruct.CHSTypeChargeUser:
item.Desc = "充值"
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
case dbstruct.CHSTypeChargeOp:
item.Desc = "运营充值"
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
case dbstruct.CHSTypeChargeRefund:
item.Desc = "退款"
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
}
list = append(list, item)
}
return
}
func (s *Service) chListIncome(ctx *gin.Context, chList []*dbstruct.ConsumeHistory) (list []*vasproto.CHSt) {
// 组装
list = make([]*vasproto.CHSt, 0)
for _, chDB := range chList {
item := &vasproto.CHSt{
Ct: util.DerefInt64(chDB.Ct),
}
changeMark := "-"
if chDB.GetChange() > 0 {
changeMark = "+"
}
switch chDB.GetSType() {
case dbstruct.CHSTypeIncomeContact:
item.Desc = "解锁微信"
item.Change = changeMark + fmt.Sprintf("%d钻石", chDB.GetChange())
case dbstruct.CHSTypeIncomeInvite:
item.Desc = "邀请收益"
item.Change = changeMark + fmt.Sprintf("%d钻石", chDB.GetChange())
}
list = append(list, item)
}
return
}
func (s *Service) chListWithdraw(ctx *gin.Context, chList []*dbstruct.ConsumeHistory) (list []*vasproto.CHSt) {
// 组装
list = make([]*vasproto.CHSt, 0)
for _, chDB := range chList {
item := &vasproto.CHSt{
Ct: util.DerefInt64(chDB.Ct),
}
changeMark := "-"
if chDB.GetChange() > 0 {
changeMark = "+"
}
switch chDB.GetSType() {
case dbstruct.CHSTypeWithdrawDiamond:
item.Desc = "提现"
item.Change = changeMark + fmt.Sprintf("%d钻石", chDB.GetChange())
}
list = append(list, item)
}
return
}
// 更新微信
func (s *Service) UpdateWechat(ctx *gin.Context, req *vasproto.UpdateWechatReq) (ec errcode.ErrCode) {
err := _DefaultVas.UpdateWechat(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("UpdateWechat fail, req: %v, err: %v", util.ToJson(req), err)
return
}
return
}
// 查看网红微信
func (s *Service) QueryWechat(ctx *gin.Context, req *vasproto.QueryWechatReq) (isUnlock, lockType int32, wechat string, ec errcode.ErrCode) {
isUnlock, lockType, wechat, err := _DefaultVas.QueryWechat(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("UpdateWechat fail, req: %v, err: %v", util.ToJson(req), err)
return
}
return
}
// h5直接解锁微信
func (s *Service) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectUnlockWechatReq) (data *vasproto.H5DirectUnlockWechatData, ec errcode.ErrCode) {
data, err := _DefaultVas.H5DirectUnlockWechat(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("H5DirectUnlockWechat fail, req: %v, err: %v", util.ToJson(req), err)
return
}
return
}
// 支付宝回调
func (s *Service) AlipayCallback(ctx *gin.Context, req *vasproto.AlipayCallbackParamIn) (data *vasproto.H5DirectUnlockWechatData, ec errcode.ErrCode) {
_DefaultVas.AlipayCallback(ctx, req)
return
}