2024-06-07 11:11:04 +08:00
|
|
|
package svc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
"trasfer_middleware/cmd/rpc/internal/config"
|
2024-06-07 14:28:29 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/market"
|
2024-06-07 11:11:04 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx"
|
|
|
|
"trasfer_middleware/genModel"
|
|
|
|
"trasfer_middleware/genModel/marketReseller"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceContext struct {
|
|
|
|
Config config.Config
|
|
|
|
RedisClient *redis.Redis
|
|
|
|
DbRead *Model
|
|
|
|
DbWrite *Model
|
|
|
|
DbReseller *MarkerReseller
|
|
|
|
|
|
|
|
ZltxOrder *zltx.ZltxOrder
|
2024-06-07 14:28:29 +08:00
|
|
|
Market *market.Market
|
2024-06-07 11:11:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
|
|
return &ServiceContext{
|
|
|
|
Config: c,
|
|
|
|
RedisClient: redis.MustNewRedis(redis.RedisConf{
|
|
|
|
Host: c.Redis.Host,
|
|
|
|
Type: c.Redis.Type,
|
|
|
|
Pass: c.Redis.Pass,
|
|
|
|
}),
|
|
|
|
DbRead: DbModel(c.DB.Master.DataSource, c),
|
|
|
|
DbWrite: DbModel(c.DB.Slave.DataSource, c),
|
|
|
|
DbReseller: ResellerModel(c.DB.MarketReseller.DataSource, c),
|
|
|
|
ZltxOrder: zltx.NewZltxOrder(c.ZLTX),
|
2024-06-07 14:28:29 +08:00
|
|
|
Market: market.NewMarket(c.Market),
|
2024-06-07 11:11:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DbModel(datasource string, c config.Config) *Model {
|
|
|
|
sqlConn := sqlx.NewMysql(datasource)
|
|
|
|
return &Model{
|
|
|
|
ClientModel: genModel.NewServerClientModel(sqlConn, c.Cache),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Model struct {
|
|
|
|
ClientModel genModel.ServerClientModel
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResellerModel(datasource string, c config.Config) *MarkerReseller {
|
|
|
|
sqlConn := sqlx.NewMysql(datasource)
|
|
|
|
return &MarkerReseller{
|
|
|
|
ResellerMerchant: marketReseller.NewResellerMerchantModel(sqlConn, c.Cache),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MarkerReseller struct {
|
|
|
|
ResellerMerchant marketReseller.ResellerMerchantModel
|
|
|
|
}
|