Browse Source

red envelope

master
黄梓健 5 years ago
parent
commit
444bdd115f
  1. 2
      config.json
  2. 6
      controllers/client/live.go
  3. 6
      services/red_envelope/red_envelop.go

2
config.json

@ -1,6 +1,6 @@
{
"port": "20181",
"host": "192.168.1.103",
"host": "127.0.0.1",
"cross_domain": "*",
"post_max_memory": 1024000,
"api_router": "/PcClient/*",

6
controllers/client/live.go

@ -127,7 +127,7 @@ func (t *LiveCtl) SendLiveRedPack() {
t.CheckErr(err)
}
rule := models.LiveRedEnvelopeRule{}
rule := new(models.LiveRedEnvelopeRule)
rule.OutTradeNo = res["out_trade_no"].(string) // 彩排为空
rule.ActivityId = activityId
rule.RehearsalId = activity.RehearsalId
@ -144,7 +144,7 @@ func (t *LiveCtl) SendLiveRedPack() {
}
rule.UpdatedAt = time.Now()
rule.CreatedAt = time.Now()
_, err = rule.Add()
_, err = models.Add(rule)
t.CheckErr(err)
if activity.RehearsalId != 0 { // 彩排不过钱
@ -171,7 +171,7 @@ func (t *LiveCtl) SendLiveRedPack() {
record.Amount = utils.Float64CusDecimal(float64(v)/float64(100), 2)
record.CreatedAt = time.Now()
record.UpdatedAt = time.Now()
_, err = record.Add()
_, err = models.Add(record)
t.CheckErr(err)
}

6
services/red_envelope/red_envelop.go

@ -45,14 +45,14 @@ func GetCurrentRB(aid, uid, rid int64) (map[string]interface{}, error) {
}
const (
MinRedPackAmount = 1
MaxRedPackAmount = 499
MinRedPackAmount = 30 // 分钱
MaxRedPackAmount = 49900 // 4990
)
func GenRedPack(amount, num int) []int {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
sumMoney := 0
redPacks := make([]int, num)
redPacks := make([]int, 0)
for i := 0; i < num; i++ {
money := r.Int()*2*(amount-sumMoney)/num - i
if money <= MinRedPackAmount {

Loading…
Cancel
Save