diff --git a/build.bat b/build.bat index 95ade2e..7dbf141 100644 --- a/build.bat +++ b/build.bat @@ -1,3 +1,4 @@ +go get -u SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 diff --git a/services/red_envelope/red_envelop.go b/services/red_envelope/red_envelop.go index 53096d7..7b9fed4 100644 --- a/services/red_envelope/red_envelop.go +++ b/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)