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() }