package gift import ( "github.com/shopspring/decimal" "live-service/app/user_center/rpc/internal/config" ) func calcIntegral(cfg config.Config, platform string, isPaid bool, price float64, num int64) int64 { giftToRMBRadio, _ := cfg.Integral.GiftToRMB[platform] freeToIntegralRadio, _ := cfg.Integral.FreeToIntegral[platform] rmbToIntegral := cfg.Integral.RMBToIntegral var newPrice float64 if isPaid { newPrice = price * giftToRMBRadio } else { newPrice = price * freeToIntegralRadio } decimal.DivisionPrecision = 2 return decimal.NewFromFloat(newPrice). Mul(decimal.NewFromInt(num)). Mul(decimal.NewFromFloat(rmbToIntegral)). Round(0).IntPart() }