From 86b72f1a5cd0462dfd920c7e2b2436bf187a436d Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 14 Jun 2023 18:21:08 +0800 Subject: [PATCH] =?UTF-8?q?=20=E8=B5=A0=E9=80=81cp=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E5=A4=B4=E9=A5=B0=20todo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/cp_m/level.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index 547d458..f7a6f04 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) } -- 2.22.0