diff --git a/domain/model/cp_m/old_cp.go b/domain/model/cp_m/old_cp.go index 260c2e150e4732b4b85c2fb5b7f6630211ea7929..e1f93c59b91ae91c9bd8e7f73698180bb5f722ae 100644 --- a/domain/model/cp_m/old_cp.go +++ b/domain/model/cp_m/old_cp.go @@ -35,17 +35,19 @@ func (OldCp) TableName() string { return "cp" } -func GetOldCpOrNil(model *domain.Model, tmpUserId1 mysql.ID, tmpUserId2 mysql.ID) (*Cp, error) { +// 获取旧的绑定中的cp +func GetOldConnectCp(model *domain.Model, tmpUserId1 mysql.ID, tmpUserId2 mysql.ID) (*OldCp, error) { userId1 := tmpUserId1 userId2 := tmpUserId2 if tmpUserId1 < tmpUserId2 { userId1 = tmpUserId2 userId2 = tmpUserId1 } - cp := Cp{} - if err := model.Db.Where(&Cp{ + cp := OldCp{} + if err := model.Db.Where(&OldCp{ UserId1: userId1, UserId2: userId2, + Status: Connect, }).First(&cp).Error; err != nil { if err == gorm.ErrRecordNotFound { return nil, nil diff --git a/route/user_r/inner.go b/route/user_r/inner.go index 25ab65929eeae4a1a35a57aed2005b46535e4e14..d08d5d45cdec228e93075beb381a87b7cecb45b0 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -158,7 +158,7 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) { title = cp_cv.GetTranslate(msgId, req.Language) } var oldScore uint32 - if oldCp, _ := cp_m.GetOldCpOrNil(model, cpRelation.UserId1, cpRelation.UserId2); oldCp != nil { + if oldCp, _ := cp_m.GetOldConnectCp(model, cpRelation.UserId1, cpRelation.UserId2); oldCp != nil { oldScore = uint32(oldCp.Score) } response = cp_cv.CvCp{ diff --git a/test/cp_test.go b/test/cp_test.go index b7ebf80af2bfc92af5de3a7170a6a17ddbdbd9ef..19e623f4d4f58a9c43bbad29137a133a49b605bd 100644 --- a/test/cp_test.go +++ b/test/cp_test.go @@ -33,7 +33,7 @@ func TestCalLoc(t *testing.T) { func TestSumCpScore(t *testing.T) { model := domain.CreateModelNil() - old, err := cp_m.GetOldCpOrNil(model, 76421, 4549) + old, err := cp_m.GetOldConnectCp(model, 7642, 4549) t.Logf("%v-%v", old, err) n := cp_m.SumCpPoints(model, 1) t.Logf("%v", n)