Commit 401c2680 authored by chenweijian's avatar chenweijian

cp绑定

parent 6701cffc
...@@ -49,7 +49,7 @@ type CpCancelMessage struct { ...@@ -49,7 +49,7 @@ type CpCancelMessage struct {
func CreateCp(model *domain.Model, userId1, userId2 uint64) error { func CreateCp(model *domain.Model, userId1, userId2 uint64) error {
userIds := []uint64{userId1, userId2} userIds := []uint64{userId1, userId2}
result := model.DB().Exec("insert into cp_relation(user_id1, user_id2) values(?,?) where not exists (select user_id1 from cp_relation where user_id1 in (?) or user_id2 in (?));", userId1, userId2, userIds, userIds) result := model.DB().Exec("insert into cp_relation(user_id1, user_id2) select ?,? where not exists (select user_id1 from cp_relation where user_id1 in (?) or user_id2 in (?));", userId1, userId2, userIds, userIds)
if result.Error != nil { if result.Error != nil {
model.Log.Errorf("CreateCp user1:%d, user2:%d, err:%v", userId1, userId2, result.Error) model.Log.Errorf("CreateCp user1:%d, user2:%d, err:%v", userId1, userId2, result.Error)
return result.Error return result.Error
...@@ -89,7 +89,7 @@ func GetCpInvite(model *domain.Model, userId, userIdInvite uint64, status cp_e.C ...@@ -89,7 +89,7 @@ func GetCpInvite(model *domain.Model, userId, userIdInvite uint64, status cp_e.C
func CreateCpInvite(model *domain.Model, userId, userIdInvite uint64, diamondNum uint32) (uint64, error) { func CreateCpInvite(model *domain.Model, userId, userIdInvite uint64, diamondNum uint32) (uint64, error) {
cpInvite := CpInvite{UserId: userId, InviteUserId: userIdInvite, DiamondNum: diamondNum, Status: cp_e.CpInvite} cpInvite := CpInvite{UserId: userId, InviteUserId: userIdInvite, DiamondNum: diamondNum, Status: cp_e.CpInvite}
err := model.DB().Model(CpInvite{}).Create(cpInvite).Error err := model.DB().Model(CpInvite{}).Create(&cpInvite).Error
if err != nil { if err != nil {
model.Log.Errorf("CreateCpInvite user1:%d, user2:%d, diamondNum:%d, err:%v", userId, userIdInvite, diamondNum, err) model.Log.Errorf("CreateCpInvite user1:%d, user2:%d, diamondNum:%d, err:%v", userId, userIdInvite, diamondNum, err)
return 0, err return 0, err
...@@ -113,7 +113,7 @@ func UpdateStatusCpInvite(model *domain.Model, id uint64, status cp_e.CpInviteSt ...@@ -113,7 +113,7 @@ func UpdateStatusCpInvite(model *domain.Model, id uint64, status cp_e.CpInviteSt
func CreateCpCancel(model *domain.Model, userId, recUserId uint64) (uint64, error) { func CreateCpCancel(model *domain.Model, userId, recUserId uint64) (uint64, error) {
cpCancel := CpCancel{UserId: userId, RecUserId: recUserId, Status: cp_e.CpCancel} cpCancel := CpCancel{UserId: userId, RecUserId: recUserId, Status: cp_e.CpCancel}
err := model.DB().Model(CpCancel{}).Create(cpCancel).Error err := model.DB().Model(CpCancel{}).Create(&cpCancel).Error
if err != nil { if err != nil {
model.Log.Errorf("CreateCpCancel user1:%d, user2:%d, err:%v", userId, recUserId, err) model.Log.Errorf("CreateCpCancel user1:%d, user2:%d, err:%v", userId, recUserId, err)
return 0, err return 0, err
......
...@@ -37,6 +37,10 @@ func CheckUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -37,6 +37,10 @@ func CheckUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err return myCtx, err
} }
if externalId == "" {
return myCtx, bizerr.InvalidParameter
}
model := domain.CreateModelContext(myCtx) model := domain.CreateModelContext(myCtx)
user, err := user_m.GetUserByExtId(model, externalId) user, err := user_m.GetUserByExtId(model, externalId)
if err != nil { if err != nil {
...@@ -48,7 +52,7 @@ func CheckUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -48,7 +52,7 @@ func CheckUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err return myCtx, err
} }
if cp.Id > 0 { if cp.Id > 0 {
return myCtx, msg.GetErrByLanguage(model, 0, lang, comerr.InvalidParameter) return myCtx, msg.GetErrByLanguage(model, 0, lang, comerr.InvalidParameter) // cwj----
} }
resp.ResponseOk(c, cp_cv.CheckCpRelationRes{}) resp.ResponseOk(c, cp_cv.CheckCpRelationRes{})
...@@ -208,7 +212,7 @@ func ReplyCpInvite(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -208,7 +212,7 @@ func ReplyCpInvite(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err return myCtx, err
} }
resp.ResponseOk(c, cp_cv.CheckCpRelationRes{}) resp.ResponseOk(c, nil)
return myCtx, nil return myCtx, nil
} }
...@@ -338,9 +342,10 @@ func CpDetailPage(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -338,9 +342,10 @@ func CpDetailPage(c *gin.Context) (*mycontext.MyContext, error) {
GradeName string `json:"gradeName"` // 等级称号 GradeName string `json:"gradeName"` // 等级称号
CreatedTime int64 `json:"createdTime"` // cp创建时间 CreatedTime int64 `json:"createdTime"` // cp创建时间
} }
res := new(CpDetail) var res *CpDetail
if cp.Id > 0 { if cp.Id > 0 {
res = new(CpDetail)
if cp.UserId1 == user.ID { if cp.UserId1 == user.ID {
res.Avatar1 = user.Avatar res.Avatar1 = user.Avatar
res.Nick1 = user.Nick res.Nick1 = user.Nick
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment