You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.5 KiB
Go

package svc
import (
3 years ago
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/common/coin_manager"
"live-service/app/user_center/rpc/internal/common/grade"
"live-service/app/user_center/rpc/internal/config"
"live-service/app/user_center/rpc/internal/mq"
3 years ago
"log"
"os"
"time"
)
type ServiceContext struct {
Config *config.Config
GameConfig *config.GameConfig
Db *gorm.DB
UserModel model.UserModel
UserPlatformModel model.UserPlatformModel
UserGiftModel model.UserGiftModel
UserIntegralModel model.UserIntegralModel
UserCoinModel model.UserCoinModel
UserNobilityModel model.UserNobilityModel
UserCheckInModel model.UserCheckInModel
UserGradeModel model.UserGradeModel
UserEliteModel model.UserEliteModel
UserTitleModel model.UserTitleModel
ZhgUserDetailsModel model.ZhgUserDetailsModel
StatisticsPvpModel model.StatisticsPvpModel
RankPvpModel model.RankPvpModel
GiftModel model.GiftModel
////////////// mq
UserMq *mq.UserMq // 用户MQ
RewardPoolMq *mq.RewardPool // 奖池MQ
//RewardPoolManager *reward_pool.PoolManager
CoinManager *coin_manager.Manager
GradeManager *grade.Manager
}
func NewServiceContext(c *config.Config, cg *config.GameConfig) *ServiceContext {
var logLevel logger.LogLevel
if c.Log.Mode == "console" {
logLevel = logger.Info
} else {
logLevel = logger.Warn
}
gormDb, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{
Logger: logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{
SlowThreshold: 5 * time.Second,
LogLevel: logLevel,
IgnoreRecordNotFoundError: true,
Colorful: true,
},
),
})
3 years ago
if err != nil {
log.Fatal(err)
}
userPlatformModel := model.NewUserPlatformModel(gormDb)
userIntegralModel := model.NewUserIntegralModel(gormDb)
userCoinModel := model.NewUserCoinModel(gormDb)
userGradeModel := model.NewUserGradeModel(gormDb)
userMq := mq.NewUserMq(userPlatformModel, c.Kafka)
rewardPoolMq := mq.NewRewardPoolMq(c.Kafka)
//rewardPoolManager := reward_pool.NewRewardPoolManager(
// c.Integral.RewardPool.InitReward,
// reward_pool.Ratio{
// Ratio: c.Integral.RewardPool.Ratio,
// BattleRatio: c.Integral.RewardPool.BattleRatio,
// GiftRatio: c.Integral.RewardPool.GiftRatio,
// ReturnRatio: c.Integral.RewardPool.ReturnRatio,
// WelfareRatio: c.Integral.RewardPool.WelfareRatio,
// },
// rewardPoolMq)
return &ServiceContext{
Config: c,
GameConfig: cg,
Db: gormDb,
UserModel: model.NewUserModel(gormDb),
UserPlatformModel: userPlatformModel,
UserGiftModel: model.NewUserGiftModel(gormDb),
UserIntegralModel: userIntegralModel,
UserCoinModel: userCoinModel,
UserNobilityModel: model.NewUserNobilityModel(gormDb),
UserCheckInModel: model.NewUserCheckInModel(gormDb),
UserGradeModel: userGradeModel,
UserEliteModel: model.NewUserEliteModel(gormDb),
UserTitleModel: model.NewUserTitleModel(gormDb),
ZhgUserDetailsModel: model.NewZhgUserDetailsModel(gormDb),
StatisticsPvpModel: model.NewStatisticsPvpModel(gormDb),
RankPvpModel: model.NewRankPvpModel(gormDb),
GiftModel: model.NewGiftModel(gormDb),
UserMq: userMq,
RewardPoolMq: rewardPoolMq,
//RewardPoolManager: rewardPoolManager,
CoinManager: coin_manager.NewCoinManager(userCoinModel, userMq),
GradeManager: grade.NewUserGradeManager(cg, userGradeModel),
}
}