package service import ( "fmt" "log" "time" "app.yhyue.com/moapp/MessageCenter/entity" "app.yhyue.com/moapp/MessageCenter/rpc/message" ) func SendMsg(this message.SendMsgRequest) (int64, string) { orm := entity.Engine.NewSession() defer orm.Close() err := orm.Begin() fmt.Println(err) count, _ := orm.Table("conversation").Select("*").Where("user_id = ? or user_id = ?", this.ReceiveUserId, this.SendUserId).Count() if count < 1 { conversation := entity.Conversation{ AppId: this.Appid, ReceiveId: this.ReceiveUserId, ReceiveName: this.ReceiveName, SendId: this.SendUserId, SendName: this.SendName, CreateTime: time.Now(), Sort: 0, UserId: this.SendUserId, Key: "", } _, err = orm.Table("conversation").Insert(&conversation) if err != nil { log.Panicln("会话创建失败:", err) orm.Rollback() return -1, "会话创建失败" } conversations := entity.Conversation{ AppId: this.Appid, ReceiveId: this.ReceiveUserId, ReceiveName: this.ReceiveName, SendId: this.SendUserId, SendName: this.SendName, CreateTime: time.Now(), Sort: 0, UserId: this.ReceiveUserId, Key: "", } _, err = orm.Table("conversation").Insert(&conversations) if err != nil { log.Panicln("会话创建失败:", err) orm.Rollback() return -1, "会话创建失败" } } message := entity.Message{ AppId: this.Appid, ReceiveUserid: this.ReceiveUserId, ReceiveName: this.ReceiveName, SendUserid: this.SendUserId, SendName: this.SendName, CreateTime: time.Now(), Title: this.Title, MsgType: int(this.MsgType), Link: this.Link, CiteId: int(this.CiteId), Content: this.Content, IsRead: 0, Isdel: 1, } _, err = orm.Table("message").Insert(&message) if err != nil { log.Panicln("消息发送失败:", err) orm.Rollback() return -1, "消息发送失败" } orm.Commit() return 1, "消息发送成功" }