From 4b98c331ef93d88d9ea5a96f5ab46db8819d005c Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Thu, 13 Jul 2023 11:35:13 +0800 Subject: [PATCH] =?UTF-8?q?cp=E8=A7=A3=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/cp_m/cp_relation.go | 16 +++++++++++++++- domain/service/cp_s/cp_relation.go | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/domain/model/cp_m/cp_relation.go b/domain/model/cp_m/cp_relation.go index 009b7cb..29f2c36 100644 --- a/domain/model/cp_m/cp_relation.go +++ b/domain/model/cp_m/cp_relation.go @@ -130,7 +130,21 @@ func GetCp(model *domain.Model, userId uint64) (*CpRelation, error) { if err == gorm.ErrRecordNotFound { return res, nil } - model.Log.Errorf("CreateCp userId:%d, err:%v", userId, err) + model.Log.Errorf("GetCp userId:%d, err:%v", userId, err) + return nil, err + } + return res, nil +} + +func GetCpByIds(model *domain.Model, userId1, userId2 uint64) (*CpRelation, error) { + ids := []uint64{userId1, userId2} + res := new(CpRelation) + err := model.DB().Model(CpRelation{}).Where("user_id1 in (?) and user_id2 in (?)", ids, ids).First(&res).Error + if err != nil { + if err == gorm.ErrRecordNotFound { + return res, nil + } + model.Log.Errorf("GetCpByIds userId1:%d, userId2:%d, err:%v", userId1, userId2, err) return nil, err } return res, nil diff --git a/domain/service/cp_s/cp_relation.go b/domain/service/cp_s/cp_relation.go index 511e4d0..bc60eee 100644 --- a/domain/service/cp_s/cp_relation.go +++ b/domain/service/cp_s/cp_relation.go @@ -146,6 +146,15 @@ func CancelCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l if inviCp.Id == 0 { return myerr.WrapErr(bizerr.InvalidParameter) } + // 我和对方是否是cp,且cp关系存在 + cpRelation, err := cp_m.GetCpByIds(model, myUserId, userRec.ID) + if err != nil { + return err + } + if cpRelation.Id == 0 { + model.Log.Errorf("CancelCpRelation cp关系不存在 id1:%v, id2:%v", myUserId, userRec.ID) + return myerr.WrapErr(bizerr.InvalidParameter) + } // 是否有关于我的cp解除申请,且还未被处理 myCancel, err := cp_m.GetCpCancelWithMe(model, user.ID, cp_e.CpCancel) -- 2.22.0