diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index 547d458abc40ee40494cfab6975361df1b6df28c..f7a6f0464e1180b98a31167a06875213c868237e 100644 --- a/domain/model/cp_m/level.go +++ b/domain/model/cp_m/level.go @@ -126,6 +126,7 @@ func InitCpLevel(model *domain.Model, cpId, userId1, userId2 mysql.ID) error { } // 增加cp等级积分 +// 此函数并发不安全,利用mysql事件串行执行保证顺序 // 送礼1钻石=1点数 // condition // 1.记录不存在,首充加points计算level增加90天有效期 @@ -137,6 +138,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelation, points mysql.N defer func() { model.Log.Infof("AddCpLevelPoints cost:%v,err:%v", time.Now().Sub(start), err) }() + var oldLevel cp_e.CpLevel var cpLevel CpLevel var cpLevelDetails []CpLevelDetail if err := model.DB().Model(CpLevel{}).Where("cp_id = ?", cpRelation.Id).First(&cpLevel).Error; err != nil { @@ -200,7 +202,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelation, points mysql.N AftNum: cpLevel.Points, Remark: fmt.Sprintf("send %d gift diamonds", points), }) - oldLevel := cpLevel.Level + oldLevel = cpLevel.Level levelPoint := cp_e.CpLevelPoints[oldLevel] // 已经用于升级的积分 for level := cp_e.CpLevelMax; level > oldLevel; level-- { if cp_e.CpLevelPoints[level] <= cpLevel.Points+levelPoint { @@ -269,6 +271,10 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelation, points mysql.N return myerr.WrapErr(err) } } + // 赠送cp头像头饰 + if oldLevel < 3 && cpLevel.Level >= 3 { + //headwear_tx.SendHeadwear() // todo headwear id ! + } return cpLevel.Persistence(model) }