service/app/mix/dao/mongo_vas.go

154 lines
3.4 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package dao
import (
"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
}
2024-04-12 10:01:49 +08:00
if err != nil {
return nil, err
}
2023-12-21 22:17:40 +08:00
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
}
2024-04-12 10:01:49 +08:00
// 空间增值信息
func (m *Mongo) GetZoneVasById(ctx *gin.Context, id int64) (*dbstruct.ZoneVas, error) {
doc := new(dbstruct.ZoneVas)
col := m.getColZoneVas()
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) 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,
},
},
).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) 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
}