Browse Source

状态改变

master
黄梓健 5 years ago
parent
commit
ce6b9244e3
  1. 6
      controllers/author.go
  2. 2
      controllers/client/reward.go
  3. 17
      controllers/client/shake_red_envelope.go
  4. 4
      controllers/common/im.go
  5. 6
      models/base.go
  6. BIN
      test/123.gif
  7. 3
      utils/code/code.go

6
controllers/author.go

@ -64,7 +64,11 @@ func (t *AuthorCtl) MustGetCustomerId() int64 {
}
func (t *AuthorCtl) MustGetAreaId() int64 {
return t.claims.AreaId
areaId, exist := t.GetInt64("area_id")
if !exist {
areaId = t.claims.AreaId
}
return areaId
}
// 对各种角色进行不同的接口权限限定

2
controllers/client/reward.go

@ -58,7 +58,7 @@ func (t *RewardCtl) Reward() {
_, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
OutTradeNo: res["out_trade_no"].(string),
RewardServerId: rewardServer.Id,
CustomerId: t.MustGetCustomerId(),
CustomerId: activity.CustomerId,
UserId: user.Id,
Amount: amount,
Content: content,

17
controllers/client/shake_red_envelope.go

@ -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)

4
controllers/common/im.go

@ -16,8 +16,8 @@ func (t *ImTestCtl) SendNotice() {
status := t.MustGetInt("status")
im_service.SendGroupCustomMessage(activityId, im.NoticeStatus(status), map[string]interface{}{
"customer_id": 1,
"shake_red_envelope_rule_id": 2,
"customer_id": 16,
"shake_red_envelope_rule_id": 5,
"timestamp": time.Now().Unix(),
})
t.SUCCESS("发送成功")

6
models/base.go

@ -66,9 +66,3 @@ func AliasTableName(bean interface{}, alias string) string {
func GetById(bean interface{}, id int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(bean)
}
// Clone copy all the session's content and return a new session
func CloneSession(session *xorm.Session) *xorm.Session {
var sess = *session
return &sess
}

BIN
test/123.gif

Before

Width: 72  |  Height: 72  |  Size: 6.5 KiB

3
utils/code/code.go

@ -49,7 +49,8 @@ const (
MSG_SHAKERB_NOT_EXIST = 8000 // 摇红包不存在
MSG_SHAKERB_RECORD_NOT_EXIST = 8001 // 摇红包不存在
MSG_SHAKERB_RULE_NOT_EXIST = 8002 // 红包规则不存在
MSG_SHAKERB_NOT_HIT = 8003 // 红包没有命中
MSG_SHAKERB_RECORD_NOT_HIT = 8003 // 红包没有命中
MSG_SHAKERB_RECODE_SKIP = 8004 // 跳过红包
MSG_AUCTION_NOT_EXIST = 9000 // 竞拍不存在
MSG_CALORIE_NOT_EXIST = 10001 // 卡路里轮次不存在
)
Loading…
Cancel
Save