by Robin at 20240820

This commit is contained in:
Leufolium 2024-08-20 17:35:50 +08:00
parent 5abd6883d4
commit 58e5c6ab1d
8 changed files with 133 additions and 16 deletions

View File

@ -49,6 +49,8 @@ type OpFilterReq struct {
Fans *util.Int64Filter `json:"fans"`
Height *util.Int64Filter `json:"height"`
Weight *util.Int64Filter `json:"weight"`
WechatCoinPrice *util.Int64Filter `json:"wechat_coin_price"`
ZoneAdmissionPrice *util.Int64Filter `json:"zone_admission_price"`
City *string `json:"city"`
Constellation *string `json:"constellation"`
IsActiveWithinAWeek *int64 `json:"is_active_within_a_week"`

View File

@ -9,6 +9,12 @@ import (
type OpCreateReq struct {
base.BaseRequest
*dbstruct.Zone
AdmissionPrice int64 `json:"admission_price"` // 空间解锁价格, 单位: 分
IronfanshipPrice int64 `json:"ironfanship_price"` // 铁粉解锁价格, 单位: 分
IsSuperfanshipEnabled int `json:"is_superfanship_enabled"` // 是否开启超粉空间 0: 关闭, 1: 开启
SuperfanshipPrice int64 `json:"superfanship_price"` // 超粉价格, 单位: 分
SuperfanshipValidPeriod int `json:"superfanship_valid_period"` // 超粉有效期类型, SuperfanshipValidPeriod*
IsSuperfanshipGiveWechat int `json:"is_superfanship_give_wechat"` // 是否开启超粉空间赠送微信 0: 不赠送, 1: 赠送
}
type OpCreateData struct {

View File

@ -7,6 +7,8 @@ type StreamerFilterCfg struct {
Fans *util.Int64Filter `json:"fans"`
Height *util.Int64Filter `json:"height"`
Weight *util.Int64Filter `json:"weight"`
WechatCoinPrice *util.Int64Filter `json:"wechat_coin_price"`
ZoneAdmissionPrice *util.Int64Filter `json:"zone_admission_price"`
CityWeight float64 `json:"city_weight"`
ConstellationWeight float64 `json:"constellation_weight"`
IsActiveWithinAWeekWeight float64 `json:"is_active_within_a_week_weight"`

View File

@ -193,12 +193,14 @@ func (es *ElasticSearch) FilterStreamerAcctList(ctx *gin.Context, req *streamera
funcScoreQuery.MaxBoost(3.4028235e38)
funcScoreQuery.Boost(1.0)
// 写入关于年龄、粉丝量、身高、体重的高斯衰减打分
// 写入关于年龄、粉丝量、身高、体重、微信价格、空间价格的高斯衰减打分
matchall := elastic.NewMatchAllQuery().Boost(1.0)
agefunc := util.CreateGaussDecayFunction("age", req.Age, req.RefStreamerFilter.Age)
fansfunc := util.CreateGaussDecayFunction("fans", req.Fans, req.RefStreamerFilter.Fans)
heightfunc := util.CreateGaussDecayFunction("height", req.Height, req.RefStreamerFilter.Height)
weightfunc := util.CreateGaussDecayFunction("weight", req.Weight, req.RefStreamerFilter.Weight)
wechatcoinpricefunc := util.CreateGaussDecayFunction("wechat_coin_price", req.WechatCoinPrice, req.RefStreamerFilter.WechatCoinPrice)
zoneadmissionpricefunc := util.CreateGaussDecayFunction("zone_admission_price", req.ZoneAdmissionPrice, req.RefStreamerFilter.ZoneAdmissionPrice)
if agefunc != nil {
funcScoreQuery.Add(matchall, agefunc)
@ -216,6 +218,14 @@ func (es *ElasticSearch) FilterStreamerAcctList(ctx *gin.Context, req *streamera
funcScoreQuery.Add(matchall, weightfunc)
fullscore += 1.0
}
if wechatcoinpricefunc != nil {
funcScoreQuery.Add(matchall, wechatcoinpricefunc)
fullscore += 1.0
}
if zoneadmissionpricefunc != nil {
funcScoreQuery.Add(matchall, zoneadmissionpricefunc)
fullscore += 1.0
}
// 写入关于城市、星座的脚本打分
if req.City != nil {

View File

@ -2645,8 +2645,9 @@ func (s *Service) ApiCreateZone(ctx *gin.Context, req *zoneproto.ApiCreateReq) (
req.Zone.VideoCount = goproto.Int64(0)
req.Zone.IsZoneThirdPartnerHided = goproto.Int64(consts.IsHided_No)
req.Zone.Profile = goproto.String(defaultZoneText)
err, zid := _DefaultZone.OpCreate(ctx, &zoneproto.OpCreateReq{
err, zid := _DefaultZoneDecrtByEs.OpCreate(ctx, &zoneproto.OpCreateReq{
Zone: req.Zone,
AdmissionPrice: req.AdmissionPrice,
})
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
@ -2725,8 +2726,9 @@ func (s *Service) ApiUpdateZone(ctx *gin.Context, req *zoneproto.ApiUpdateReq) (
profile := req.Zone.GetProfile()
req.Zone.Profile = nil
err = _DefaultZone.OpUpdate(ctx, &zoneproto.OpUpdateReq{
err = _DefaultZoneDecrtByEs.OpUpdate(ctx, &zoneproto.OpUpdateReq{
Zone: req.Zone,
AdmissionPrice: req.AdmissionPrice,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeZoneNotExist
@ -2767,7 +2769,7 @@ func (s *Service) ApiUpdateZone(ctx *gin.Context, req *zoneproto.ApiUpdateReq) (
func (s *Service) ApiDeleteZone(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneSrvOk
err := _DefaultZone.OpDelete(ctx, id)
err := _DefaultZoneDecrtByEs.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeZoneSrvFail

View File

@ -38,6 +38,7 @@ func (p *StreamerDecrtByEs) OpUpdate(ctx *gin.Context, req *streamerproto.OpUpda
Weight: req.Streamer.Weight,
City: req.Streamer.City,
Constellation: req.Streamer.Constellation,
WechatCoinPrice: req.Streamer.WechatCoinPrice,
}); err != nil {
logger.Error("OpUpdateSelectively fail, req: %v, err: %v", util.ToJson(req), err)
return err
@ -57,6 +58,67 @@ func NewZoneDecrtByEs(streamerAcct *StreamerAcct, zone *Zone) *ZoneDecrtByEs {
}
}
func (p *ZoneDecrtByEs) OpCreate(ctx *gin.Context, req *zoneproto.OpCreateReq) (error, int64) {
err, id := p.Zone.OpCreate(ctx, req)
if err != nil {
logger.Error("CreateZone fail, req: %v, err: %v", util.ToJson(req), err)
return err, id
}
// 更新es
if err := p.StreamerAcct.OpUpdateSelectively(ctx, &dbstruct.EsStreamerAcctUpdater{
Mid: req.Zone.Mid,
ZoneAdmissionPrice: goproto.Int64(req.AdmissionPrice),
}); err != nil {
logger.Error("OpUpdateSelectively fail, req: %v, err: %v", util.ToJson(req), err)
return err, id
}
return nil, id
}
func (p *ZoneDecrtByEs) OpUpdate(ctx *gin.Context, req *zoneproto.OpUpdateReq) error {
err := p.Zone.OpUpdate(ctx, req)
if err != nil {
logger.Error("UpdateZone fail, err: %v", err)
return err
}
// 更新es
if err := p.StreamerAcct.OpUpdateSelectively(ctx, &dbstruct.EsStreamerAcctUpdater{
Mid: goproto.Int64(req.BaseRequest.Mid),
ZoneAdmissionPrice: goproto.Int64(req.AdmissionPrice),
}); err != nil {
logger.Error("OpUpdateSelectively fail, req: %v, err: %v", util.ToJson(req), err)
return err
}
return nil
}
func (p *ZoneDecrtByEs) OpDelete(ctx *gin.Context, id int64) error {
zone, err := p.Zone.GetById(ctx, id)
if err != nil {
logger.Error("Zone GetById fail, err: %v", err)
return err
}
err = p.Zone.OpDelete(ctx, id)
if err != nil {
logger.Error("DeleteZone fail, err: %v", err)
return err
}
// 更新es
if err := p.StreamerAcct.OpUpdateSelectively(ctx, &dbstruct.EsStreamerAcctUpdater{
Mid: zone.Mid,
ZoneAdmissionPrice: goproto.Int64(-1),
}); err != nil {
logger.Error("OpUpdateSelectively fail, err: %v", err)
return err
}
return nil
}
func (p *ZoneDecrtByEs) OpUpdateByIds(ctx *gin.Context, req *zoneproto.OpUpdateReq, ids []int64) error {
err := p.Zone.OpUpdateByIds(ctx, req, ids)
if err != nil {

View File

@ -1891,7 +1891,7 @@ func (s *Service) OpApproveStreamerAuthApproval(ctx *gin.Context, req *streamera
return
}
streamerAccts := make([]*dbstruct.EsStreamerAcct, 0)
for _, streamer := range streamerList {
for i, streamer := range streamerList {
acct := accountMp[streamer.GetMid()]
streamerAccts = append(streamerAccts, &dbstruct.EsStreamerAcct{
Mid: acct.GetMid(),
@ -1904,6 +1904,8 @@ func (s *Service) OpApproveStreamerAuthApproval(ctx *gin.Context, req *streamera
City: streamer.GetCity(),
Constellation: streamer.GetConstellation(),
LastZoneMomentCreateDayStart: 0,
WechatCoinPrice: util.DerefInt64(list[i].WechatCoinPrice),
ZoneAdmissionPrice: -1, // es只用于过滤搜索设置为-1不影响付款
Ct: acct.GetCt(),
Ut: acct.GetUt(),
DelFlag: acct.GetDelFlag(),
@ -2264,6 +2266,8 @@ func (s *Service) OpApproveStreamerAuthApprovalDetails(ctx *gin.Context, req *st
City: streamer.GetCity(),
Constellation: streamer.GetConstellation(),
LastZoneMomentCreateDayStart: 0,
WechatCoinPrice: util.DerefInt64(streamerAuthApprovalDetails.WechatCoinPrice),
ZoneAdmissionPrice: -1, // es只用于过滤搜索设置为-1不影响付款
Ct: acct.GetCt(),
Ut: acct.GetUt(),
DelFlag: acct.GetDelFlag(),
@ -3877,7 +3881,7 @@ func (s *Service) OpGetAccountCancellationList(ctx *gin.Context, req *account_ca
func (s *Service) OpCreateZone(ctx *gin.Context, req *zoneproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneSrvOk
req.Zone.IsZoneThirdPartnerHided = goproto.Int64(consts.IsHided_No)
err, _ := _DefaultZone.OpCreate(ctx, req)
err, _ := _DefaultZoneDecrtByEs.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneSrvFail
@ -3888,7 +3892,32 @@ func (s *Service) OpCreateZone(ctx *gin.Context, req *zoneproto.OpCreateReq) (ec
func (s *Service) OpUpdateZone(ctx *gin.Context, req *zoneproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneSrvOk
err := _DefaultZone.OpUpdate(ctx, req)
// 转为更新自己空间请求
selfReq := &zoneproto.OpUpdateReq{
BaseRequest: req.BaseRequest,
Zone: req.Zone,
AdmissionPrice: req.AdmissionPrice,
IronfanshipPrice: req.IronfanshipPrice,
IsSuperfanshipEnabled: req.IsSuperfanshipEnabled,
SuperfanshipPrice: req.SuperfanshipPrice,
SuperfanshipValidPeriod: req.SuperfanshipValidPeriod,
IsSuperfanshipGiveWechat: req.IsSuperfanshipGiveWechat,
}
zone, err := _DefaultZone.GetById(ctx, req.Zone.GetId())
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeZoneNotExist
err = nil
return
}
if err != nil {
logger.Error("Zone GetById fail, err: %v", err)
ec = errcode.ErrCodeZoneSrvFail
return
}
selfReq.BaseRequest.Mid = zone.GetMid()
err = _DefaultZoneDecrtByEs.OpUpdate(ctx, selfReq)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeZoneNotExist
err = nil
@ -3924,7 +3953,7 @@ func (s *Service) OpUpdateZone(ctx *gin.Context, req *zoneproto.OpUpdateReq) (ec
func (s *Service) OpDeleteZone(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneSrvOk
err := _DefaultZone.OpDelete(ctx, id)
err := _DefaultZoneDecrtByEs.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeZoneSrvFail

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-是
@ -27,6 +29,8 @@ type EsStreamerAcctUpdater struct {
City *string `json:"city" bson:"city"` // 所在城市
Constellation *string `json:"constellation" bson:"constellation"` // 星座
LastZoneMomentCreateDayStart *int64 `json:"last_zone_moment_create_day_start" bson:"last_zone_moment_create_day_start"` // 最后空间动态创建日始整点
WechatCoinPrice *int64 `json:"wechat_coin_price"` // 微信金币价格
ZoneAdmissionPrice *int64 `json:"zone_admission_price"` // 空间解锁价格, 单位: 分
}
func (p *EsStreamerAcctUpdater) GetMid() int64 {