Commit 9deac2a7 authored by chenweijian's avatar chenweijian

im check

parent a0d100e4
......@@ -4,3 +4,6 @@ type CheckCpRelationRes struct {
Diamond uint32 `json:"diamond"`
Msg string `json:"msg"`
}
type CheckCpImRes struct {
}
......@@ -31,6 +31,8 @@ type CpInviteMessage struct {
Msg string `json:"msg"`
Tip string `json:"tip"`
Sender *user_m.UserTiny `json:"sender"`
MsgType int `json:"msgType"`
MsgId uint64 `json:"msgId"`
}
// 发送私信-接受邀请
......@@ -62,6 +64,8 @@ type CpCancelMessage struct {
Msg string `json:"msg"`
Tip string `json:"tip"`
Sender *user_m.UserTiny `json:"sender"`
MsgType int `json:"msgType"`
MsgId uint64 `json:"msgId"`
}
// 发送私信-撤销解除、接受解除
......@@ -145,6 +149,19 @@ func GetCpInvite(model *domain.Model, userId, userIdInvite uint64, status cp_e.C
return res, nil
}
func GetCpInviteById(model *domain.Model, id uint64, status cp_e.CpInviteStatus) (*CpInvite, error) {
res := new(CpInvite)
err := model.DB().Model(CpInvite{}).Where(CpInvite{Id: id, Status: status}).First(&res).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
}
model.Log.Errorf("GetCpInviteById id:%d, err:%v", id, err)
return nil, err
}
return res, nil
}
func CreateCpInvite(model *domain.Model, userId, userIdInvite uint64, diamondNum uint32) (uint64, error) {
cpInvite := CpInvite{UserId: userId, InviteUserId: userIdInvite, DiamondNum: diamondNum, Status: cp_e.CpInvite}
err := model.DB().Model(CpInvite{}).Create(&cpInvite).Error
......@@ -192,6 +209,19 @@ func GetCpCancel(model *domain.Model, userIds []uint64, status cp_e.CpCancelStat
return res, nil
}
func GetCpCancelById(model *domain.Model, id uint64, status cp_e.CpCancelStatus) (*CpCancel, error) {
res := new(CpCancel)
err := model.DB().Model(CpCancel{}).Where("status = ? and id = ?", status, id).First(&res).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
}
model.Log.Errorf("GetCpCancelById id:%d, err:%v", id, err)
return nil, err
}
return res, nil
}
func GetCpCancelWithMe(model *domain.Model, userId uint64, status cp_e.CpCancelStatus) (*CpCancel, error) {
res := new(CpCancel)
err := model.DB().Model(CpCancel{}).Where("status = ? and (user_id = ? or rec_user_id = ?)", status, userId, userId).First(&res).Error
......
......@@ -87,6 +87,8 @@ func InviteCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l
Msg: content,
Tip: tip,
Sender: user_m.ToUserTiny(user),
MsgType: 1,
MsgId: cpInvId,
})
if err := tencentyun.BatchSendCustomMsg(model, 1, user.ExternalId, []string{userInvite.ExternalId}, string(data), "cp邀请"); err != nil {
model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
......@@ -157,7 +159,7 @@ func CancelCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l
err = model.Transaction(func(model *domain.Model) error {
// 创建邀请记录
_, err = cp_m.CreateCpCancel(model, myUserId, userRec.ID)
cancelId, err := cp_m.CreateCpCancel(model, myUserId, userRec.ID)
if err != nil {
model.Log.Errorf("CancelCpRelation myUserId:%d, err:%v", myUserId, err)
return err
......@@ -168,6 +170,8 @@ func CancelCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l
Msg: content,
Tip: tip,
Sender: user_m.ToUserTiny(user),
MsgType: 2,
MsgId: cancelId,
})
if err := tencentyun.BatchSendCustomMsg(model, 1, user.ExternalId, []string{userRec.ExternalId}, string(data), "cp解除"); err != nil {
model.Log.Errorf("CancelCpRelation BatchSendCustomMsg fail:%v", err)
......
......@@ -448,3 +448,58 @@ func CpDetailPage(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, res)
return myCtx, nil
}
// @Tags cp关系
// @Summary 检查cp的im是否失效
// @Param msgType query int true "类型"
// @Param msgId query int true "消息id"
// @Success 200 {object} cp_cv.CheckCpImRes
// @Router /v2/cp/im/check [get]
func CheckCpImExpire(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
userId, lang, err := req.GetUserIdLang(c, myCtx)
if err != nil {
return myCtx, err
}
msgType, err := strconv.Atoi(c.Query("msgType"))
if err != nil {
return myCtx, err
}
if msgType < 1 || msgType > 2 {
return myCtx, bizerr.InvalidParameter
}
msgId, err := strconv.ParseUint(c.Query("msgId"), 10, 64)
if err != nil {
return myCtx, err
}
if msgId <= 0 {
return myCtx, bizerr.InvalidParameter
}
model := domain.CreateModelContext(myCtx)
switch msgType {
case 1: // 邀请的消息im检查是否过期
cpRecord, err := cp_m.GetCpInviteById(model, msgId, cp_e.CpInvite)
if err != nil {
model.Log.Errorf("CheckCpImExpire userId:%d, msgType:%d, msgId:%d, err:%v", userId, msgType, msgId, err)
return myCtx, err
}
if cpRecord == nil || cpRecord.Id == 0 {
return myCtx, myerr.ToLocal(msg.GetErrByLanguage(model, common.MSG_ID_ALREADY_EXPIRED, lang, comerr.AlreadyExpired))
}
case 2: // 解除的消息im检查是否过期
cpCancel, err := cp_m.GetCpCancelById(model, msgId, cp_e.CpCancel)
if err != nil {
model.Log.Errorf("CheckCpImExpire userId:%d, msgType:%d, msgId:%d, err:%v", userId, msgType, msgId, err)
return myCtx, err
}
if cpCancel == nil || cpCancel.Id == 0 {
return myCtx, myerr.ToLocal(msg.GetErrByLanguage(model, common.MSG_ID_ALREADY_EXPIRED, lang, comerr.AlreadyExpired))
}
}
resp.ResponseOk(c, cp_cv.CheckCpImRes{})
return myCtx, nil
}
......@@ -48,6 +48,7 @@ func InitRouter() *gin.Engine {
cp.POST("/relation/invite/reply", wrapper(cp_r.ReplyCpInvite))
cp.POST("/relation/cancel/reply", wrapper(cp_r.ReplyCpCancel))
cp.GET("/relation/detail", wrapper(cp_r.CpDetailPage))
cp.GET("/im/check", wrapper(cp_r.CheckCpImExpire))
}
inner := r.Group("/inner")
inner.Use(ExceptionHandle, LoggerHandle)
......
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