Commit 92b6d007 authored by chenweijian's avatar chenweijian

cp

parent 1f3e3ad1
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"git.hilo.cn/hilo-common/utils" "git.hilo.cn/hilo-common/utils"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-user/_const/enum/cp_e" "hilo-user/_const/enum/cp_e"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr" "hilo-user/myerr/bizerr"
"time" "time"
) )
...@@ -24,13 +25,26 @@ type CpInvite struct { ...@@ -24,13 +25,26 @@ type CpInvite struct {
Status cp_e.CpInviteStatus `json:"status"` Status cp_e.CpInviteStatus `json:"status"`
} }
// 发送私信 // 发送私信-发起邀请
type CpInviteMessage struct { type CpInviteMessage struct {
Identifier string `json:"identifier"` Identifier string `json:"identifier"`
Msg string `json:"msg"` Msg string `json:"msg"`
Status uint8 `json:"status"` //1.发起邀请2.接受3.拒接 Sender *user_m.UserTiny `json:"sender"`
Avatar1 string `json:"avatar1"` }
Avatar2 string `json:"avatar2"`
// 发送私信-接受邀请
type CpAcceptInviteMessage struct {
Identifier string `json:"identifier"`
Msg string `json:"msg"`
Sender *user_m.UserTiny `json:"sender"`
Receiver *user_m.UserTiny `json:"receiver"`
}
// 发送私信-拒绝邀请
type CpDenyInviteMessage struct {
Identifier string `json:"identifier"`
Msg string `json:"msg"`
Sender *user_m.UserTiny `json:"sender"`
} }
type CpCancel struct { type CpCancel struct {
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"hilo-user/_const/enum/user_e" "hilo-user/_const/enum/user_e"
"hilo-user/myerr" "hilo-user/myerr"
"hilo-user/myerr/bizerr" "hilo-user/myerr/bizerr"
"time"
) )
//用户信息 //用户信息
...@@ -106,3 +107,31 @@ func GetUserByExtId(model *domain.Model, externalId string) (*User, error) { ...@@ -106,3 +107,31 @@ func GetUserByExtId(model *domain.Model, externalId string) (*User, error) {
user.Model = model user.Model = model
return &user, nil return &user, nil
} }
func ToUserTiny(user *User) *UserTiny {
return &UserTiny{
ID: user.ID,
ExternalId: user.ExternalId,
Avatar: user.Avatar,
Nick: user.Nick,
Sex: user.Sex,
Code: user.Code,
Description: user.Description,
Country: user.Country,
CountryIcon: user.CountryIcon,
IsPrettyCode: user.IsPrettyCode(),
IsLogout: IfLogout(user.LogoutTime),
Birthday: BirthdayToUint64(&user.Birthday),
}
}
func IfLogout(logoutTime int64) bool {
return logoutTime > 0 && time.Now().Unix() > logoutTime
}
func BirthdayToUint64(birthday *mysql.Timestamp) *uint64 {
if *birthday == 0 {
return nil
}
return (*uint64)(birthday)
}
...@@ -67,11 +67,11 @@ func InviteCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l ...@@ -67,11 +67,11 @@ func InviteCpRelation(myCtx *mycontext.MyContext, myUserId uint64, externalId, l
model.Log.Errorf("InviteCpRelation myUserId:%d, err:%v", myUserId, err) model.Log.Errorf("InviteCpRelation myUserId:%d, err:%v", myUserId, err)
return err return err
} }
// 发送私信 // 发送私信-邀请
data, _ := json.Marshal(cp_m.CpInviteMessage{ data, _ := json.Marshal(cp_m.CpInviteMessage{
Identifier: "CpInviteMessage", Identifier: "CpInviteMessage",
Msg: "Do you want to be CP with me?", Msg: "Do you want to be CP with me?",
Status: uint8(cp_e.CpInvite), Sender: user_m.ToUserTiny(user),
}) })
if err := tencentyun.BatchSendCustomMsg(model, 1, user.ExternalId, []string{userInvite.ExternalId}, string(data), "cp邀请"); err != nil { if err := tencentyun.BatchSendCustomMsg(model, 1, user.ExternalId, []string{userInvite.ExternalId}, string(data), "cp邀请"); err != nil {
model.Log.Errorf("BatchSendCustomMsg fail:%v", err) model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
......
...@@ -188,26 +188,25 @@ func ReplyCpInvite(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -188,26 +188,25 @@ func ReplyCpInvite(c *gin.Context) (*mycontext.MyContext, error) {
// model.Log.Errorf("ReplyCpInvite userSender:%d, user:%d, status:%d, err:%v", userSender.ID, user.ID, updateStatus, err) // model.Log.Errorf("ReplyCpInvite userSender:%d, user:%d, status:%d, err:%v", userSender.ID, user.ID, updateStatus, err)
// return err // return err
//} //}
// 私信 // 私信-接受
msgData, _ = json.Marshal(cp_m.CpInviteMessage{ msgData, _ = json.Marshal(cp_m.CpAcceptInviteMessage{
Identifier: "CpInviteMessage", Identifier: "CpAcceptInviteMessage",
Msg: "We are already CP!", Msg: "We are already CP!",
Status: uint8(cp_e.CpInviteAccept), Sender: user_m.ToUserTiny(userSender),
Avatar1: userSender.Avatar, Receiver: user_m.ToUserTiny(user),
Avatar2: user.Avatar,
}) })
} else { // 拒 } else { // 拒
// 退费 // 退费
err = diamond_m.ChangeDiamondAccountDetail(model, diamond_e.CpInviteRefund, cpRecord.Id, cpRecord.UserId, cpRecord.DiamondNum) err = diamond_m.ChangeDiamondAccountDetail(model, diamond_e.CpInviteRefund, cpRecord.Id, cpRecord.UserId, cpRecord.DiamondNum)
if err != nil { if err != nil {
model.Log.Errorf("ReplyCpInvite UserId:%d, err:%v", cpRecord.UserId, err) model.Log.Errorf("ReplyCpInvite UserId:%d, err:%v", cpRecord.UserId, err)
return err return err
} }
// 私信 // 私信-拒绝
msgData, _ = json.Marshal(cp_m.CpInviteMessage{ msgData, _ = json.Marshal(cp_m.CpDenyInviteMessage{
Identifier: "CpInviteMessage", Identifier: "CpDenyInviteMessage",
Msg: fmt.Sprintf("%s have declined the CP invitation", user.Nick), Msg: fmt.Sprintf("%s have declined the CP invitation", user.Nick),
Status: uint8(cp_e.CpInviteRefuse), Sender: user_m.ToUserTiny(user),
}) })
} }
if err := tencentyun.BatchSendCustomMsg(model, 1, userSender.ExternalId, []string{user.ExternalId}, string(msgData), "cp邀请"); err != nil { if err := tencentyun.BatchSendCustomMsg(model, 1, userSender.ExternalId, []string{user.ExternalId}, string(msgData), "cp邀请"); err != nil {
......
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