|
|
|
package msg_handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/kafka"
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/logger"
|
|
|
|
"github.com/jinzhu/now"
|
|
|
|
"live-gateway/config"
|
|
|
|
"live-gateway/pb/mq"
|
|
|
|
pbVars "live-gateway/pb/vars"
|
|
|
|
kfk "live-gateway/pkg/kafka"
|
|
|
|
"live-gateway/pkg/timex"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GuardBuyOfficial struct {
|
|
|
|
UserInfo userInfo `json:"user_info"` // 用户信息
|
|
|
|
GuardLevel int64 `json:"guard_level"` // 大航海等级 1总督 2提督 3舰长
|
|
|
|
GuardNum int64 `json:"guard_num"` // 大航海数量
|
|
|
|
GuardUnit string `json:"guard_unit"` // 大航海单位 (个月)
|
|
|
|
FansMedalLevel int64 `json:"fans_medal_level"` // 粉丝勋章等级
|
|
|
|
FansMedalName string `json:"fans_medal_name"` // 粉丝勋章名
|
|
|
|
FansMedalWearingStatus bool `json:"fans_medal_wearing_status"` // 佩戴的粉丝勋章佩戴状态
|
|
|
|
RoomId int64 `json:"room_id"` // 房间号
|
|
|
|
MsgId string `json:"msg_id"` // 消息唯一id
|
|
|
|
Timestamp int64 `json:"timestamp"` // 上舰时间秒级时间戳
|
|
|
|
}
|
|
|
|
|
|
|
|
type userInfo struct {
|
|
|
|
Uid int64 `json:"uid"` // 用户uid
|
|
|
|
Uname string `json:"uname"` // 用户昵称
|
|
|
|
Uface string `json:"uface"` // 用户头像
|
|
|
|
}
|
|
|
|
|
|
|
|
type GuardBuyOfficialHandler struct {
|
|
|
|
producer *kafka.Producer
|
|
|
|
liveRoomId int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGuardBuyOfficialHandler(liveRoomId int64) *GuardBuyOfficialHandler {
|
|
|
|
cfg := config.Config.Kafka.GuardBuy
|
|
|
|
return &GuardBuyOfficialHandler{
|
|
|
|
producer: kafka.NewKafkaProducer(kfk.DefaultProducerConfig, cfg.Addr, cfg.Topic),
|
|
|
|
liveRoomId: liveRoomId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *GuardBuyOfficialHandler) CMD() string {
|
|
|
|
return "GUARD_BUY"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *GuardBuyOfficialHandler) HandlerMessage(data []byte) {
|
|
|
|
var baseMsg struct {
|
|
|
|
CMD string `json:"cmd"`
|
|
|
|
Data *GuardBuyOfficial `json:"data"`
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &baseMsg); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
d := baseMsg.Data
|
|
|
|
|
|
|
|
logger.SLog.Infof("%s 购买 %d %d%s", d.UserInfo.Uname, d.GuardLevel, d.GuardNum, d.GuardUnit)
|
|
|
|
|
|
|
|
dmMsg := &pbMq.MqNobilityBuy{
|
|
|
|
Platform: pbVars.Platform_name[int32(pbVars.Platform_Bilibili)],
|
|
|
|
LiveRoomId: h.liveRoomId,
|
|
|
|
Uid: d.UserInfo.Uid,
|
|
|
|
Uname: d.UserInfo.Uname,
|
|
|
|
Avatar: d.UserInfo.Uface,
|
|
|
|
MsgId: d.MsgId,
|
|
|
|
NobilityLevel: d.GuardLevel,
|
|
|
|
Price: 0, // 自己算
|
|
|
|
StartTime: d.Timestamp,
|
|
|
|
EndTime: 0, // 自己算
|
|
|
|
FansMedalWearingStatus: d.FansMedalWearingStatus,
|
|
|
|
FansMedalName: d.FansMedalName,
|
|
|
|
FansMedalLevel: d.FansMedalLevel,
|
|
|
|
}
|
|
|
|
switch d.GuardLevel {
|
|
|
|
case 1:
|
|
|
|
dmMsg.Price = 19998 * 1000 // 金瓜子
|
|
|
|
case 2:
|
|
|
|
dmMsg.Price = 1998 * 1000
|
|
|
|
case 3:
|
|
|
|
dmMsg.Price = 138 * 1000 // 应该没有人会不用连续包月然后取消吧?
|
|
|
|
}
|
|
|
|
// 计算时间
|
|
|
|
switch d.GuardUnit {
|
|
|
|
case "月":
|
|
|
|
dmMsg.EndTime = now.With(timex.TimestampToTime(d.Timestamp)).
|
|
|
|
AddDate(0, 1, 0).Unix()
|
|
|
|
case "年":
|
|
|
|
dmMsg.EndTime = now.With(timex.TimestampToTime(d.Timestamp)).
|
|
|
|
AddDate(1, 0, 0).Unix()
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
|
|
|
|
}
|