Browse Source

fix:bug

master
黄梓健 5 years ago
parent
commit
619bdd1f63
  1. 1
      build.bat
  2. 13
      services/red_envelope/red_envelop.go

1
build.bat

@ -1,3 +1,4 @@
go get -u
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64

13
services/red_envelope/red_envelop.go

@ -45,11 +45,14 @@ func GetCurrentRB(aid, uid, rid int64) (map[string]interface{}, error) {
}
const (
MinRedPackAmount = 1 // 分
MaxRedPackAmount = 20000 // 4990
MinRedPackAmount = 100 // 1块
MaxRedPackAmount = 20000 // 200块钱
)
func GenRedPack(amount, num int) []int {
func GenRedPack(amount, num int) ([]int, error) {
if amount/num <= 100 {
return nil, errors.New("每个红包的平均金额必须在1.00元到200.00元之间")
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
sumMoney := 0
redPacks := make([]int, 0)
@ -75,17 +78,15 @@ func GenRedPack(amount, num int) []int {
sumMoney += money
redPacks = append(redPacks, money)
}
return redPacks
return redPacks, nil
}
// 提前生成红包
func GenRedEnvelope(aid int64, name string, rid int64, rule *models.ShakeRedEnvelopeRule) error {
// 判断红包是否存在
// 根据算法提前生成红包
r := rand.New(rand.NewSource(time.Now().UnixNano()))
if rule.Model == define.SHAKERB_RULE_RANDOM { // 随机红包
// 检测红包是否存在
for i := 0; i < rule.RedEnvelopeNum; i++ {
randSum := int(rule.RandSum * 100)

Loading…
Cancel
Save