service/app/mix/dao/mongo_vas.go

487 lines
10 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dao
import (
"errors"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
"github.com/qiniu/qmgo/operator"
vasproto "service/api/proto/vas/proto"
"service/dbstruct"
"time"
)
// 订单操作历史
func (m *Mongo) AddOplogOrder(ctx *gin.Context, doc *dbstruct.OplogOrder) error {
col := m.getColOplogOrder(doc.OrderId)
_, err := col.InsertOne(ctx, doc)
return err
}
// 金币订单操作历史
func (m *Mongo) AddOplogCoinOrder(ctx *gin.Context, doc *dbstruct.OplogCoinOrder) error {
col := m.getColOplogCoinOrder(doc.OrderId)
_, err := col.InsertOne(ctx, doc)
return err
}
// 用户增值信息
func (m *Mongo) GetUserVasInfoByMid(ctx *gin.Context, mid int64) (*dbstruct.UserVasInfo, error) {
doc := new(dbstruct.UserVasInfo)
col := m.getColUserVasInfo()
query := qmgo.M{
"_id": mid,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
func (m *Mongo) UpdateUserVasInfo(ctx *gin.Context, req *vasproto.UpdateWechatReq) error {
col := m.getColUserVasInfo()
_, err := col.Bulk().UpsertOne(
qmgo.M{
"_id": req.Mid,
},
qmgo.M{
operator.SetOnInsert: qmgo.M{
"ct": time.Now().Unix(),
},
operator.Set: qmgo.M{
"wechat_lock_type": req.WechatLockType,
"wechat_contact": req.WechatContact,
"wechat_coin_price": req.WechatCoinPrice,
"wechat_ut": time.Now().Unix(),
},
},
).Run(ctx)
if err != nil {
return err
}
return err
}
// 空间价格信息
func (m *Mongo) GetZoneVasById(ctx *gin.Context, zid int64) (*dbstruct.ZoneVas, error) {
doc := new(dbstruct.ZoneVas)
col := m.getColZoneVas()
query := qmgo.M{
"_id": zid,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
// 批量空间价格信息
func (m *Mongo) GetZoneVasByIds(ctx *gin.Context, zids []int64) ([]*dbstruct.ZoneVas, error) {
list := make([]*dbstruct.ZoneVas, 0)
col := m.getColZoneVas()
query := qmgo.M{
"_id": qmgo.M{
"$in": zids,
},
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return make([]*dbstruct.ZoneVas, 0), nil
}
if err != nil {
return make([]*dbstruct.ZoneVas, 0), err
}
return list, nil
}
func (m *Mongo) UpsertZoneVas(ctx *gin.Context, req *dbstruct.ZoneVas) error {
col := m.getColZoneVas()
_, err := col.Bulk().UpsertOne(
qmgo.M{
"_id": req.Zid,
},
qmgo.M{
operator.SetOnInsert: qmgo.M{
"ct": time.Now().Unix(),
"mid": req.Mid,
},
operator.Set: qmgo.M{
"ut": time.Now().Unix(),
"admission_price": req.AdmissionPrice,
"ironfanship_price": req.IronfanshipPrice,
"is_superfanship_enabled": req.IsSuperfanshipEnabled,
"superfanship_price": req.SuperfanshipPrice,
"superfanship_valid_period": req.SuperfanshipValidPeriod,
"is_superfanship_give_wechat": req.IsSuperfanshipGiveWechat,
"superfan_price_list": req.SuperfanPriceList,
},
},
).Run(ctx)
if err != nil {
return err
}
return err
}
// 空间动态价格
func (m *Mongo) GetZoneMomentPriceById(ctx *gin.Context, id int64) (*dbstruct.ZoneMomentPrice, error) {
doc := new(dbstruct.ZoneMomentPrice)
col := m.getColZoneMomentPrice()
query := qmgo.M{
"_id": id,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
// 批量空间动态价格
func (m *Mongo) GetZoneMomentPriceByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.ZoneMomentPrice, error) {
list := make([]*dbstruct.ZoneMomentPrice, 0)
col := m.getColZoneMomentPrice()
query := qmgo.M{
"_id": qmgo.M{
"$in": ids,
},
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return make([]*dbstruct.ZoneMomentPrice, 0), nil
}
if err != nil {
return make([]*dbstruct.ZoneMomentPrice, 0), err
}
return list, nil
}
func (m *Mongo) UpsertZoneMomentPrice(ctx *gin.Context, req *dbstruct.ZoneMomentPrice) error {
col := m.getColZoneMomentPrice()
_, err := col.Bulk().UpsertOne(
qmgo.M{
"_id": req.MomentId,
},
qmgo.M{
operator.SetOnInsert: qmgo.M{
"ct": time.Now().Unix(),
"mid": req.Mid,
},
operator.Set: qmgo.M{
"ut": time.Now().Unix(),
"price": req.Price,
},
},
).Run(ctx)
if err != nil {
return err
}
return err
}
// 增加动态购买人数
func (m *Mongo) IncZoneMomentBuyerCnt(ctx *gin.Context, zid, momentId int64) error {
col := m.getColZoneMomentStat()
_, err := col.Bulk().UpsertOne(
qmgo.M{
"_id": momentId,
},
qmgo.M{
operator.SetOnInsert: qmgo.M{
"ct": time.Now().Unix(),
"zid": zid,
},
operator.Set: qmgo.M{
"ut": time.Now().Unix(),
},
operator.Inc: qmgo.M{
"buyer_cnt": 1,
},
},
).Run(ctx)
if err != nil {
return err
}
return err
}
// 减少动态购买人数
func (m *Mongo) DecZoneMomentBuyerCnt(ctx *gin.Context, zid, momentId int64) error {
col := m.getColZoneMomentStat()
_, err := col.Bulk().UpsertOne(
qmgo.M{
"_id": momentId,
},
qmgo.M{
operator.SetOnInsert: qmgo.M{
"ct": time.Now().Unix(),
"zid": zid,
},
operator.Set: qmgo.M{
"ut": time.Now().Unix(),
},
operator.Inc: qmgo.M{
"buyer_cnt": -1,
},
},
).Run(ctx)
if err != nil {
return err
}
return err
}
// 获取动态的数据
func (m *Mongo) GetZoneMomentStatByIds(ctx *gin.Context, momentIds []int64) ([]*dbstruct.ZoneMomentStat, error) {
list := make([]*dbstruct.ZoneMomentStat, 0)
col := m.getColZoneMomentStat()
query := qmgo.M{
"_id": qmgo.M{
"$in": momentIds,
},
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return make([]*dbstruct.ZoneMomentStat, 0), nil
}
if err != nil {
return make([]*dbstruct.ZoneMomentStat, 0), err
}
return list, nil
}
// 获取收入看板
func (m *Mongo) GetZoneUserIncome(ctx *gin.Context, mid int64) (*dbstruct.UserIncome, error) {
doc := new(dbstruct.UserIncome)
col := m.getColUserIncome()
query := qmgo.M{
"_id": mid,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
// 收入历史
func (m *Mongo) AddWithdrawHis(ctx *gin.Context, doc *dbstruct.WithdrawHis) error {
col := m.getColWithdrawHis()
_, err := col.InsertOne(ctx, doc)
return err
}
// 提现冻结
func (m *Mongo) AddWithdrawFreeze(ctx *gin.Context, doc *dbstruct.WithdrawFreeze) error {
col := m.getColWithdrawFreeze()
_, err := col.InsertOne(ctx, doc)
return err
}
func (m *Mongo) DelWithdrawFreeze(ctx *gin.Context, userId int64) error {
col := m.getColWithdrawFreeze()
err := col.RemoveId(ctx, userId)
return err
}
func (m *Mongo) GetWithdrawFreezeList(ctx *gin.Context) ([]*dbstruct.WithdrawFreeze, error) {
list := make([]*dbstruct.WithdrawFreeze, 0)
col := m.getColWithdrawFreeze()
query := qmgo.M{}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return make([]*dbstruct.WithdrawFreeze, 0), nil
}
if err != nil {
return make([]*dbstruct.WithdrawFreeze, 0), err
}
return list, nil
}
func (m *Mongo) GetWithdrawFreezeByUserId(ctx *gin.Context, userId int64) (*dbstruct.WithdrawFreeze, error) {
doc := new(dbstruct.WithdrawFreeze)
col := m.getColWithdrawFreeze()
query := qmgo.M{
"_id": userId,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
func (m *Mongo) GetWithdrawFreezeByMid(ctx *gin.Context, mid int64) (*dbstruct.WithdrawFreeze, error) {
doc := new(dbstruct.WithdrawFreeze)
col := m.getColWithdrawFreeze()
query := qmgo.M{
"mid": mid,
}
err := col.Find(ctx, query).One(&doc)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return doc, nil
}
// 用户退款表:查询主播审核列表
func (m *Mongo) GetZoneRefundList(ctx *gin.Context, bMid int64, refundsStatusList []int64) ([]*dbstruct.RefundInfo, error) {
list := make([]*dbstruct.RefundInfo, 0)
doc := m.GetZoneRefund()
query := qmgo.M{
"b_mid": bMid,
"refunds_status": qmgo.M{
"$in": refundsStatusList,
},
}
err := doc.Find(ctx, query).All(&list)
if errors.Is(err, qmgo.ErrNoSuchDocuments) {
err = nil
return nil, err
}
if err != nil {
return nil, err
}
return list, nil
}
// 用户退款表:查询主播审核详情页
func (m *Mongo) GetZoneRefundInfo(ctx *gin.Context, auditId string) (*dbstruct.RefundInfo, error) {
doc := new(dbstruct.RefundInfo)
col := m.GetZoneRefund()
query := qmgo.M{
"_id": auditId,
}
err := col.Find(ctx, query).One(&doc)
if errors.Is(err, qmgo.ErrNoSuchDocuments) {
err = nil
return nil, err
}
if err != nil {
return nil, err
}
return doc, nil
}
// 用户退款表:主播审核
func (m *Mongo) SetZoneRefundAuditInfo(ctx *gin.Context, auditId string, refundsStatus int64) error {
col := m.GetZoneRefund()
_, err := col.Bulk().UpdateOne(
qmgo.M{
"_id": auditId,
},
qmgo.M{
operator.Set: qmgo.M{
"refunds_status": refundsStatus,
"ut": time.Now().Unix(),
},
},
).Run(ctx)
if errors.Is(err, qmgo.ErrNoSuchDocuments) {
err = nil
return err
}
if err != nil {
return err
}
return nil
}
// 用户退款表2小时内自动通过
func (m *Mongo) AddZoneRefundAutomatic(ctx *gin.Context, doc *dbstruct.RefundInfo) error {
col := m.GetZoneRefund()
_, err := col.InsertOne(ctx, doc)
if err != nil {
return err
}
return nil
}
// 用户退款表:主播超过 24 小时未审核列表
func (m *Mongo) GetRefundAudit(ctx *gin.Context) ([]*dbstruct.RefundInfo, error) {
list := make([]*dbstruct.RefundInfo, 0)
col := m.GetZoneRefund()
at := time.Now().Unix() - 24*3600
query := qmgo.M{
"ct": qmgo.M{
"$gte": at - 5*60, // >=
"$lte": at, // <=
},
}
err := col.Find(ctx, query).All(&list)
if errors.Is(err, qmgo.ErrNoSuchDocuments) {
err = nil
return nil, err
}
if err != nil {
return nil, err
}
return list, nil
}
func (m *Mongo) SetRefundAudit(ctx *gin.Context, ids []string) error {
col := m.GetZoneRefund()
query := qmgo.M{
"_id": qmgo.M{
"$in": ids,
},
}
_, err := col.Bulk().UpdateAll(
query,
qmgo.M{
operator.Set: qmgo.M{
"refunds_status": dbstruct.RefundsOvertime,
"ut": time.Now().Unix(),
},
},
).Run(ctx)
if errors.Is(err, qmgo.ErrNoSuchDocuments) {
err = nil
return err
}
if err != nil {
return err
}
return nil
}