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.
|
|
|
package gift
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
"live-service/app/user_center/rpc/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func calcCoin(cfg *config.GameConfig, platform string, isPaid bool, price float64, num int64) int64 {
|
|
|
|
giftToRMBRadio, _ := cfg.Coin.GiftToRMB[platform]
|
|
|
|
freeToRadio, _ := cfg.Coin.FreeToCoin[platform]
|
|
|
|
rmbTo := cfg.Coin.RMBToCoin
|
|
|
|
|
|
|
|
var newPrice float64
|
|
|
|
if isPaid {
|
|
|
|
newPrice = price * giftToRMBRadio
|
|
|
|
} else {
|
|
|
|
newPrice = price * freeToRadio
|
|
|
|
}
|
|
|
|
|
|
|
|
decimal.DivisionPrecision = 2
|
|
|
|
|
|
|
|
resp := decimal.NewFromFloat(newPrice).
|
|
|
|
Mul(decimal.NewFromInt(num))
|
|
|
|
if isPaid {
|
|
|
|
resp = resp.Mul(decimal.NewFromFloat(rmbTo))
|
|
|
|
}
|
|
|
|
return resp.Round(0).IntPart()
|
|
|
|
}
|