diff --git a/corn/cp_corn/cp.go b/cron/cp_cron/cp_relation.go similarity index 94% rename from corn/cp_corn/cp.go rename to cron/cp_cron/cp_relation.go index aed68b3893ad4c736c4f548f19c44615482b480b..678cc41091caed3ec885893e4af5e8bcbb6252d2 100644 --- a/corn/cp_corn/cp.go +++ b/cron/cp_cron/cp_relation.go @@ -1,4 +1,4 @@ -package cp_corn +package cp_cron import ( "git.hilo.cn/hilo-common/_const/enum/diamond_e" @@ -36,6 +36,7 @@ func CpInviteCancelInit() { return } for _, v := range inviteList { + model := domain.CreateModelContext(model.MyContext) model.Log.Infof("CpInviteCancelInit invite:%+v", v) err = model.Transaction(func(model *domain.Model) error { // 更新邀请记录 @@ -54,7 +55,7 @@ func CpInviteCancelInit() { }) if err != nil { model.Log.Errorf("CpInviteCancelInit invite:%+v, err:%v", v, err) - return + continue } time.Sleep(time.Millisecond * 10) } @@ -66,6 +67,7 @@ func CpInviteCancelInit() { return } for _, v := range cancelList { + model := domain.CreateModelContext(model.MyContext) model.Log.Infof("CpInviteCancelInit cancel:%+v", v) err = model.Transaction(func(model *domain.Model) error { // 更新解除记录 @@ -84,7 +86,7 @@ func CpInviteCancelInit() { }) if err != nil { model.Log.Errorf("CpInviteCancelInit cancel:%+v, err:%v", v, err) - return + continue } time.Sleep(time.Millisecond * 10) } diff --git a/cron/cron.go b/cron/cron.go index f9256e36c67d8b01bc06ea30c12b2e4deeada76d..eeef2b4a420c0a1b6d4b82eb61d2dfb1bcd99752 100644 --- a/cron/cron.go +++ b/cron/cron.go @@ -2,7 +2,6 @@ package cron import ( "git.hilo.cn/hilo-common/resource/config" - "hilo-user/corn/cp_corn" "hilo-user/cron/cp_cron" "hilo-user/cron/gift_cron" ) @@ -15,5 +14,5 @@ func Init() { gift_cron.GiftRemark() // 礼物消息补偿 cp_cron.ClearCpExpire() // 清理过期cp cp_cron.CpAnniversaryNotice() // cp纪念日 - cp_corn.CpInviteCancelInit() // cp邀请、解除到期结算 + cp_cron.CpInviteCancelInit() // cp邀请、解除到期结算 } diff --git a/domain/model/cp_m/cp_relation.go b/domain/model/cp_m/cp_relation.go index 009b7cb79304443fe52dc6fc53230e7b751989d1..29f2c36f70feb4f030ffe90ad06a858e463aa303 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 511e4d06f491b04fb701612a7e7f3e52a8f57319..1c4aa49079fff27120b1ea2c76bdafc884cf6fa8 100644 --- a/domain/service/cp_s/cp_relation.go +++ b/domain/service/cp_s/cp_relation.go @@ -130,22 +130,31 @@ func CancelCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l return err } - // 自己没有cp了 - myCp, err := cp_m.GetCp(model, myUserId) - if err != nil { - return err - } - if myCp.Id == 0 { - return myerr.WrapErr(bizerr.InvalidParameter) - } - // 对方没有cp了 - inviCp, err := cp_m.GetCp(model, userRec.ID) + // 我和对方是否是cp,且cp关系存在 + cpRelation, err := cp_m.GetCpByIds(model, myUserId, userRec.ID) if err != nil { return err } - if inviCp.Id == 0 { + if cpRelation.Id == 0 { + model.Log.Errorf("CancelCpRelation cp关系不存在 id1:%v, id2:%v", myUserId, userRec.ID) return myerr.WrapErr(bizerr.InvalidParameter) } + //// 自己没有cp了 + //myCp, err := cp_m.GetCp(model, myUserId) + //if err != nil { + // return err + //} + //if myCp.Id == 0 { + // return myerr.WrapErr(bizerr.InvalidParameter) + //} + //// 对方没有cp了 + //inviCp, err := cp_m.GetCp(model, userRec.ID) + //if err != nil { + // return err + //} + //if inviCp.Id == 0 { + // return myerr.WrapErr(bizerr.InvalidParameter) + //} // 是否有关于我的cp解除申请,且还未被处理 myCancel, err := cp_m.GetCpCancelWithMe(model, user.ID, cp_e.CpCancel)