feat(exchange): add exchange rate handling and scheduled updates
This commit is contained in:
@@ -347,6 +347,11 @@ func (l *PurchaseCheckoutLogic) queryExchangeRate(to string, src int64) (amount
|
||||
// Convert cents to decimal amount
|
||||
amount = float64(src) / float64(100)
|
||||
|
||||
if l.svcCtx.ExchangeRate != 0 && to == "CNY" {
|
||||
amount = amount * l.svcCtx.ExchangeRate
|
||||
return amount, nil
|
||||
}
|
||||
|
||||
// Retrieve system currency configuration
|
||||
currency, err := l.svcCtx.SystemModel.GetCurrencyConfig(l.ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,10 +32,12 @@ import (
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
DB *gorm.DB
|
||||
Redis *redis.Client
|
||||
Config config.Config
|
||||
Queue *asynq.Client
|
||||
DB *gorm.DB
|
||||
Redis *redis.Client
|
||||
Config config.Config
|
||||
Queue *asynq.Client
|
||||
ExchangeRate float64
|
||||
|
||||
//NodeCache *cache.NodeCacheClient
|
||||
AuthModel auth.Model
|
||||
AdsModel ads.Model
|
||||
@@ -82,10 +84,11 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
}
|
||||
authLimiter := limit.NewPeriodLimit(86400, 15, rds, config.SendCountLimitKeyPrefix, limit.Align())
|
||||
srv := &ServiceContext{
|
||||
DB: db,
|
||||
Redis: rds,
|
||||
Config: c,
|
||||
Queue: NewAsynqClient(c),
|
||||
DB: db,
|
||||
Redis: rds,
|
||||
Config: c,
|
||||
Queue: NewAsynqClient(c),
|
||||
ExchangeRate: 1.0,
|
||||
//NodeCache: cache.NewNodeCacheClient(rds),
|
||||
AuthLimiter: authLimiter,
|
||||
AdsModel: ads.NewModel(db, rds),
|
||||
|
||||
Reference in New Issue
Block a user