|
|
@ -34,6 +34,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() { |
|
|
|
customerId := t.MustGetInt64("customer_id") |
|
|
|
ruleId := t.MustGetInt64("shake_red_envelope_rule_id") |
|
|
|
userId := t.MustGetUID() |
|
|
|
areaId := t.MustGetAreaId() |
|
|
|
|
|
|
|
// 查询摇红包规则
|
|
|
|
rule := new(models.ShakeRedEnvelopeRule) |
|
|
@ -43,9 +44,9 @@ func (t *ShakeRedEnvelopeCtl) Shake() { |
|
|
|
t.CheckRunning(rule.ShakeRedEnvelopeStatus) |
|
|
|
|
|
|
|
area := new(models.AreaStore) |
|
|
|
exist, err = area.GetAreaStoreById(t.MustGetAreaId()) |
|
|
|
exist, err = models.GetById(area, areaId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_SHAKERB_NOT_EXIST, "摇红包不存在") |
|
|
|
t.Assert(exist, code.MSG_SHAKERB_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
// 查询摇红包活动主id, is_pay=1给钱了,给摇
|
|
|
|
envelope := new(models.ShakeRedEnvelopeActivity) |
|
|
@ -67,16 +68,17 @@ func (t *ShakeRedEnvelopeCtl) Shake() { |
|
|
|
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { // 剔除摇过红包的用户
|
|
|
|
exist, err = record.ExistRecord(activity.RehearsalId, activity.Id, rule.Id, envelope.Id, userId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(!exist, code.MSG_SHAKERB_RECORD_NOT_EXIST, "您已经摇过红包了,请等待下一轮.") // 不存在继续往下走
|
|
|
|
t.Assert(!exist, code.MSG_SHAKERB_RECORD_NOT_HIT, "您已经摇过红包了,请等待下一轮.") // 不存在继续往下走
|
|
|
|
} |
|
|
|
|
|
|
|
// done: 增加概率, 修改概率
|
|
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
|
t.Assert(r.Float64()*100 <= rule.Probability, code.MSG_ERR, "您与红包擦肩而过") // 必须在红包概率以内才能获取
|
|
|
|
t.Assert(r.Float64()*100 <= rule.Probability, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 必须在红包概率以内才能获取
|
|
|
|
|
|
|
|
// 增加session 或者乐观锁
|
|
|
|
exist, err = record.GetByRuleId(ruleId, activity.RehearsalId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_SHAKERB_RECORD_NOT_EXIST, "红包已经派发完毕") |
|
|
|
t.Assert(exist, code.MSG_SHAKERB_RECORD_NOT_HIT, "红包已经派发完毕") |
|
|
|
|
|
|
|
// 查询用户
|
|
|
|
user := new(models.User) |
|
|
@ -86,9 +88,6 @@ func (t *ShakeRedEnvelopeCtl) Shake() { |
|
|
|
|
|
|
|
// 记录红包 ---> 非彩排才能
|
|
|
|
if activity.RehearsalId == 0 { |
|
|
|
//res, err := pay_service.SendRedPack("欧轩互动", user.Openid, fmt.Sprintf("感谢您参加%s", activity.Name),
|
|
|
|
// "", rule.Model, "摇得越快抢得越多", int(record.Amount*100), 1, 1)
|
|
|
|
|
|
|
|
record.TransferType = 1 // 微信转账
|
|
|
|
record.PartnerTradeNo = utils.RandomStr(32) |
|
|
|
// 加入延迟队列
|
|
|
@ -101,7 +100,7 @@ func (t *ShakeRedEnvelopeCtl) Shake() { |
|
|
|
record.Name = activity.Name |
|
|
|
row, err := record.UpdateAllColsById(record.Id) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(row == 1, code.MSG_ERR, "您与红包擦肩而过") // 那么 row == 1 为已经成功抢到
|
|
|
|
t.Assert(row == 1, code.MSG_SHAKERB_RECORD_NOT_HIT, "您与红包擦肩而过") // 那么 row == 1 为已经成功抢到
|
|
|
|
|
|
|
|
// 通知大屏
|
|
|
|
total, err := new(models.ShakeRedEnvelopeRecord).Total(activity.Id, activity.RehearsalId, envelope.Id, rule.Id) |
|
|
|