|
|
|
@ -3,6 +3,7 @@ package im_mysql_model
|
|
|
|
|
import (
|
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
|
"errors"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -71,32 +72,43 @@ func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
|
|
|
|
|
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error {
|
|
|
|
|
func InsertFriendApplication(friendRequest *db.FriendRequest) error {
|
|
|
|
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friendRequest.CreateTime = time.Now()
|
|
|
|
|
args["create_time"] = friendRequest.CreateTime
|
|
|
|
|
u := dbConn.Model(friendRequest).Updates(args)
|
|
|
|
|
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
|
|
|
|
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
|
|
|
|
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
|
|
|
|
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
|
|
|
|
if u.RowsAffected != 0 {
|
|
|
|
|
if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if friendRequest.CreateTime.Unix() < 0 {
|
|
|
|
|
friendRequest.CreateTime = time.Now()
|
|
|
|
|
}
|
|
|
|
|
if friendRequest.HandleTime.Unix() < 0 {
|
|
|
|
|
friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
|
|
|
|
}
|
|
|
|
|
err = dbConn.Table("friend_requests").Create(friendRequest).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
t := dbConn.Model(friendRequest).Select("*").Updates(*friendRequest)
|
|
|
|
|
if t.RowsAffected == 0 {
|
|
|
|
|
return utils.Wrap(errors.New("RowsAffected == 0"), "no update")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
return utils.Wrap(t.Error, "")
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//friendRequest.CreateTime = time.Now()
|
|
|
|
|
//args["create_time"] = friendRequest.CreateTime
|
|
|
|
|
//u := dbConn.Model(friendRequest).Updates(args)
|
|
|
|
|
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
|
|
|
|
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
|
|
|
|
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
|
|
|
|
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
|
|
|
|
//if u.RowsAffected != 0 {
|
|
|
|
|
// return nil
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//if friendRequest.CreateTime.Unix() < 0 {
|
|
|
|
|
// friendRequest.CreateTime = time.Now()
|
|
|
|
|
//}
|
|
|
|
|
//if friendRequest.HandleTime.Unix() < 0 {
|
|
|
|
|
// friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
|
|
|
|
//}
|
|
|
|
|
//err = dbConn.Table("friend_requests").Create(friendRequest).Error
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
//}
|
|
|
|
|
//return nil
|
|
|
|
|
}
|
|
|
|
|