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.
26 lines
674 B
Go
26 lines
674 B
Go
3 years ago
|
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()
|
||
|
}
|