Commit 92b6d007 authored by chenweijian's avatar chenweijian

cp

parent 1f3e3ad1
......@@ -5,6 +5,7 @@ import (
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"hilo-user/_const/enum/cp_e"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr"
"time"
)
......@@ -24,13 +25,26 @@ type CpInvite struct {
Status cp_e.CpInviteStatus `json:"status"`
}
// 发送私信
// 发送私信-发起邀请
type CpInviteMessage struct {
Identifier string `json:"identifier"`
Msg string `json:"msg"`
Status uint8 `json:"status"` //1.发起邀请2.接受3.拒接
Avatar1 string `json:"avatar1"`
Avatar2 string `json:"avatar2"`
Identifier string `json:"identifier"`
Msg string `json:"msg"`
Sender *user_m.UserTiny `json:"sender"`
}
// 发送私信-接受邀请
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 {
......
......@@ -6,6 +6,7 @@ import (
"hilo-user/_const/enum/user_e"
"hilo-user/myerr"
"hilo-user/myerr/bizerr"
"time"
)
//用户信息
......@@ -106,3 +107,31 @@ func GetUserByExtId(model *domain.Model, externalId string) (*User, error) {
user.Model = model
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
model.Log.Errorf("InviteCpRelation myUserId:%d, err:%v", myUserId, err)
return err
}
// 发送私信
// 发送私信-邀请
data, _ := json.Marshal(cp_m.CpInviteMessage{
Identifier: "CpInviteMessage",
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 {
model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
......
......@@ -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)
// return err
//}
// 私信
msgData, _ = json.Marshal(cp_m.CpInviteMessage{
Identifier: "CpInviteMessage",
// 私信-接受
msgData, _ = json.Marshal(cp_m.CpAcceptInviteMessage{
Identifier: "CpAcceptInviteMessage",
Msg: "We are already CP!",
Status: uint8(cp_e.CpInviteAccept),
Avatar1: userSender.Avatar,
Avatar2: user.Avatar,
Sender: user_m.ToUserTiny(userSender),
Receiver: user_m.ToUserTiny(user),
})
} else { // 拒
} else { // 拒
// 退费
err = diamond_m.ChangeDiamondAccountDetail(model, diamond_e.CpInviteRefund, cpRecord.Id, cpRecord.UserId, cpRecord.DiamondNum)
if err != nil {
model.Log.Errorf("ReplyCpInvite UserId:%d, err:%v", cpRecord.UserId, err)
return err
}
// 私信
msgData, _ = json.Marshal(cp_m.CpInviteMessage{
Identifier: "CpInviteMessage",
// 私信-拒绝
msgData, _ = json.Marshal(cp_m.CpDenyInviteMessage{
Identifier: "CpDenyInviteMessage",
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 {
......
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