This commit is contained in:
Leufolium 2024-08-20 18:08:35 +08:00
parent 47a5557821
commit 36f9cef351
6 changed files with 286 additions and 1 deletions

View File

@ -11,6 +11,8 @@ type EsStreamerAcct struct {
City string `json:"city"` // 所在城市
Constellation string `json:"constellation"` // 星座
LastZoneMomentCreateDayStart int64 `json:"last_zone_moment_create_day_start"` // 最后空间动态创建日始整点
WechatCoinPrice int64 `json:"wechat_coin_price"` // 微信金币价格
ZoneAdmissionPrice int64 `json:"zone_admission_price"` // 空间解锁价格, 单位: 分
Ct int64 `json:"ct"` // 创建时间
Ut int64 `json:"ut"` // 更新时间
DelFlag int64 `json:"del_flag"` // 删除标记0-否1-是

190
dbstruct/vas_mongo.go Normal file
View File

@ -0,0 +1,190 @@
package dbstruct
import (
"math"
"github.com/Leufolium/test/util"
)
// 用户增值信息
const (
UserVasLockTypeOpen = 0 // 公开
UserVasLockTypeLock = 1 // 私密
)
type UserVasInfo struct {
Mid int64 `json:"mid" bson:"_id"`
WechatLockType int32 `json:"wechat_lock_type" bson:"wechat_lock_type"` // 上锁方式见UserVasLockType*
WechatContact string `json:"wechat_contact" bson:"wechat_contact"` // 微信联系方式
WechatCoinPrice int64 `json:"wechat_coin_price" bson:"wechat_coin_price"` // 微信联系方式价格
WechatUt int64 `json:"wechat_ut" bson:"wechat_ut"` // 微信联系方式更新时间
}
func (p UserVasInfo) GetH5WechatCoinPrice() int64 {
return int64(math.Ceil(float64(p.WechatCoinPrice)/9)) * 10
}
func (p UserVasInfo) GetWechatCoinPrice() int64 {
return p.WechatCoinPrice
}
// 金币订单oplog
const (
OrderOpLogActionAdd = "add"
OrderOpLogActionUpdate = "update"
)
const (
OrderOpLogOperatorTypeUser = "user" // 用户
OrderOpLogOperatorTypeOp = "op" // 运营
)
const (
OrderOpLogResultFail = "fail" // 结果失败
OrderOpLogResultOk = "ok" // 结果成功
)
type OplogCoinOrder struct {
OrderId string `json:"order_id" bson:"order_id"`
Mid int64 `json:"mid" bson:"mid"`
Ct int64 `json:"ct" bson:"ct"`
Action string `json:"action" bson:"action"` // 动作
OperatorType string `json:"operator_type" bson:"operator_type"` // 操作人类型见CoinOrderOpLogOperatorType*
Operator string `json:"operator" bson:"operator"` // 操作人
Detail string `json:"detail" bson:"detail"` // 操作详情
Result string `json:"result" bson:"result"` // 结果
BeforeStatus int32 `json:"before_status" bson:"before_status"`
AfterStatus int32 `json:"after_status" bson:"after_status"`
}
type OplogOrder struct {
OrderId string `json:"order_id" bson:"order_id"`
Mid int64 `json:"mid" bson:"mid"`
Ct int64 `json:"ct" bson:"ct"`
Action string `json:"action" bson:"action"` // 动作
OperatorType string `json:"operator_type" bson:"operator_type"` // 操作人类型见CoinOrderOpLogOperatorType*
Operator string `json:"operator" bson:"operator"` // 操作人
Detail string `json:"detail" bson:"detail"` // 操作详情
Result string `json:"result" bson:"result"` // 结果
BeforeStatus int32 `json:"before_status" bson:"before_status"`
AfterStatus int32 `json:"after_status" bson:"after_status"`
}
const (
SuperfanshipValidPeriodEternal = 0 // 永久生效
SuperfanshipValidPeriodMonth = 1 // 31d
SuperfanshipValidPeriodSeason = 2 // 93d
SuperfanshipValidPeriodHalfYear = 3 // 186d
SuperfanshipValidPeriodYear = 4 // 372d
)
// 空间增值相关,空间价格等
type ZoneVas struct {
Zid int64 `json:"zid" bson:"_id"`
Mid int64 `json:"mid" bson:"mid"` // 主播mid
Ct int64 `json:"ct" bson:"ct"` //
Ut int64 `json:"ut" bson:"ut"` //
AdmissionPrice int64 `json:"admission_price" bson:"admission_price"` // 空间解锁价格, 单位: 分
IronfanshipPrice int64 `json:"ironfanship_price" bson:"ironfanship_price"` // 铁粉解锁价格, 单位: 分
IsSuperfanshipEnabled int `json:"is_superfanship_enabled" bson:"is_superfanship_enabled"` // 是否开启超粉空间 0: 关闭, 1: 开启
SuperfanshipPrice int64 `json:"superfanship_price" bson:"superfanship_price"` // 超粉价格, 单位: 分
SuperfanshipValidPeriod int `json:"superfanship_valid_period" bson:"superfanship_valid_period"` // 超粉有效期类型, SuperfanshipValidPeriod*
IsSuperfanshipGiveWechat int `json:"is_superfanship_give_wechat" bson:"is_superfanship_give_wechat"` // 是否开启超粉空间赠送微信 0: 不赠送, 1: 赠送
}
func (p ZoneVas) GetSuperfanshipDurationSecond() int64 {
switch p.SuperfanshipValidPeriod {
case SuperfanshipValidPeriodEternal:
return -1
case SuperfanshipValidPeriodMonth:
return 86400 * 31
case SuperfanshipValidPeriodSeason:
return 86400 * 31 * 3
case SuperfanshipValidPeriodHalfYear:
return 86400 * 31 * 6
case SuperfanshipValidPeriodYear:
return 86400 * 31 * 12
default:
return -1
}
}
func (p ZoneVas) GetSuperfanshipDurationDesc() string {
switch p.SuperfanshipValidPeriod {
case SuperfanshipValidPeriodEternal:
return "永久"
case SuperfanshipValidPeriodMonth:
return "1个月"
case SuperfanshipValidPeriodSeason:
return "3个月"
case SuperfanshipValidPeriodHalfYear:
return "6个月"
case SuperfanshipValidPeriodYear:
return "12个月"
default:
return "永久"
}
}
func (p ZoneVas) GetAdmissionCoinPrice() int64 {
return util.RoundUp(float64(p.AdmissionPrice) / 10.0)
}
func (p ZoneVas) GetIronfanshipCoinPrice() int64 {
return util.RoundUp(float64(p.IronfanshipPrice) / 10.0)
}
func (p ZoneVas) GetSuperfanshipCoinPrice() int64 {
return util.RoundUp(float64(p.SuperfanshipPrice) / 10.0)
}
// 空间动态价格
type ZoneMomentPrice struct {
MomentId int64 `json:"id" bson:"_id"` // 动态id
Zid int64 `json:"zid" bson:"zid"` // 空间id
Mid int64 `json:"mid" bson:"mid"` // 主播mid
Ct int64 `json:"ct" bson:"ct"` //
Ut int64 `json:"ut" bson:"ut"` //
Price int64 `json:"price" bson:"price"` // 动态价格,单位:分
}
// 空间动态数据相关
type ZoneMomentStat struct {
MomentId int64 `json:"id" bson:"_id"` // 动态id
Zid int64 `json:"zid" bson:"zid"` // 空间id
BuyerCnt int64 `json:"buyer_cnt" bson:"buyer_cnt"` // 动态购买人数
Ct int64 `json:"ct" bson:"ct"` //
Ut int64 `json:"ut" bson:"ut"` //
}
// 收入表
type WeekDashboardSt struct {
Date string `json:"date" bson:"date"` // 日期 x轴
Income int64 `json:"income" bson:"income"` // 收入 y轴
}
type IncomeFromDashboardSt struct {
Desc string `json:"desc" bson:"desc"` // 描述
Income int64 `json:"income" bson:"income"` // 收入
}
type UserIncome struct {
Mid int64 `json:"mid" bson:"_id"`
WeekDashboard []WeekDashboardSt `json:"week_dashboard" bson:"week_dashboard"`
WeekFromDashboard []IncomeFromDashboardSt `json:"week_from_dashboard" bson:"week_from_dashboard"`
}
// 提现历史
const (
WithdrawStatusOk = 1
WithdrawStatusFail = 2
)
type WithdrawHis struct {
Id string `json:"id" bson:"_id"`
Mid int64 `json:"mid" bson:"mid"`
Did string `json:"did" bson:"did"`
Status int `json:"status" bson:"status"` // 见: WithdrawStatusOk
Err string `json:"err" bson:"err"`
Ct int64 `json:"ct" bson:"ct"`
}

View File

@ -52,13 +52,33 @@ func ImportStreamerIntoEs() {
for _, zone := range zones {
zoneMp[zone.GetMid()] = zone
}
userInfos, _ := mcli.GetUserVasInfoByMids(ctx, mids)
userInfoMp := make(map[int64]*dbstruct.UserVasInfo)
for _, userInfo := range userInfos {
userInfoMp[userInfo.Mid] = userInfo
}
zids := make([]int64, 0)
for _, zone := range zones {
zids = append(zids, zone.GetId())
}
zoneVases, _ := mcli.GetZoneVasByIds(ctx, zids)
zoneVasMp := make(map[int64]*dbstruct.ZoneVas)
for _, zoneVas := range zoneVases {
zoneVasMp[zoneVas.Zid] = zoneVas
}
streameraccts := make([]*dbstruct.EsStreamerAcct, 0)
for _, streamer := range streamers {
zone, ok := zoneMp[streamer.GetMid()]
lastZoneMomentCreateDay := int64(0)
zoneadmissionprice := int64(-1)
if ok && zone.GetLastZoneMomentCt() != 0 {
lastZoneMomentCreateDay = util.GetDayStartTimeStamp(time.Unix(zone.GetLastZoneMomentCt(), 0))
zoneVas, ok1 := zoneVasMp[zone.GetId()]
if ok1 {
zoneadmissionprice = zoneVas.AdmissionPrice
}
}
name := ""
py := ""
@ -69,6 +89,11 @@ func ImportStreamerIntoEs() {
py = strings.Join(pinyin.LazyConvert(acct.GetName(), nil), "")
userIdString = util.DerefString(acct.UserIdString)
}
wechatcoinprice := int64(0)
userInfo, ok := userInfoMp[streamer.GetMid()]
if ok {
wechatcoinprice = userInfo.WechatCoinPrice
}
streameraccts = append(streameraccts, &dbstruct.EsStreamerAcct{
Mid: streamer.GetMid(),
Name: name,
@ -80,6 +105,8 @@ func ImportStreamerIntoEs() {
City: util.DerefString(streamer.City),
Constellation: util.DerefString(streamer.Constellation),
LastZoneMomentCreateDayStart: lastZoneMomentCreateDay,
WechatCoinPrice: wechatcoinprice,
ZoneAdmissionPrice: zoneadmissionprice,
Ct: time.Now().Unix(),
Ut: time.Now().Unix(),
DelFlag: 0,

View File

@ -52,6 +52,17 @@ const (
DBStreamer = "streamer"
COLStreamer = "streamer"
DBVas = "vas"
COLProduct = "product"
COLUserVasInfo = "user_vas_info"
COLOpLogOrder = "oplog_order_%d"
COLOpLogCoinOrder = "oplog_coin_order_%d"
COLZoneVas = "zone_vas"
COLZoneMomentPrice = "zone_moment_price"
COLZoneMomentStat = "zone_moment_stat"
COLUserIncome = "user_income"
COLWithdrawHis = "withdraw_his"
)
func (m *Mongo) getColUserIdSeq() *qmgo.Collection {
@ -92,6 +103,16 @@ func (m *Mongo) getColStreamer() *qmgo.Collection {
return m.clientMix.Database(DBStreamer).Collection(COLStreamer)
}
// 用户增值信息,微信价格等
func (m *Mongo) getColUserVasInfo() *qmgo.Collection {
return m.clientMix.Database(DBVas).Collection(COLUserVasInfo)
}
// 空间增值信息
func (m *Mongo) getColZoneVas() *qmgo.Collection {
return m.clientMix.Database(DBVas).Collection(COLZoneVas)
}
func (m *Mongo) CreateBatch(ctx context.Context, userIdSeqs []*UserIdMap) error {
col := m.getColUserIdMap()
_, err := col.InsertMany(ctx, userIdSeqs)
@ -268,3 +289,43 @@ func (m *Mongo) GetStreamerList(ctx context.Context, offset, limit int) ([]*dbst
}
return list, err
}
// 用户增值信息
func (m *Mongo) GetUserVasInfoByMids(ctx context.Context, mids []int64) ([]*dbstruct.UserVasInfo, error) {
list := make([]*dbstruct.UserVasInfo, 0)
col := m.getColUserVasInfo()
query := qmgo.M{
"_id": qmgo.M{
"$in": mids,
},
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return list, nil
}
// 空间价格信息
func (m *Mongo) GetZoneVasByIds(ctx context.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).One(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
if err != nil {
return nil, err
}
return list, nil
}

View File

@ -12,7 +12,7 @@ func NewMysqlDB() (*sqlx.DB, error) {
"%s:%s@(%s)/%s?charset=utf8&parseTime=true&timeout=%ds&readTimeout=%ds&writeTimeout=%ds",
"root",
"Wishpal2024",
"rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com:3306",
"172.31.37.71:3306",
"vas",
3,
5,

View File

@ -2,6 +2,7 @@ package util
import (
"fmt"
"math"
"time"
)
@ -18,3 +19,7 @@ func GetDayStartTimeStamp(t time.Time) int64 {
}
return duetimecst.Unix()
}
func RoundUp(num float64) int64 {
return int64(math.Ceil(num))
}