add primaryKey ID field
This commit is contained in:
parent
956942419b
commit
f572bdb1e0
@ -29,8 +29,7 @@ func BindUser(m *tb.Message, ClientId, ClientSecret string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var u = &model.Client{
|
var u = &model.Client{
|
||||||
TgId: m.Chat.ID,
|
TgId: m.Chat.ID,
|
||||||
//TG的Data传递最高64bytes,一些MsId超过了报错BUTTON_DATA_INVALID (0),采取md5
|
|
||||||
RefreshToken: cli.RefreshToken,
|
RefreshToken: cli.RefreshToken,
|
||||||
MsId: util.Get16MD5Encode(gjson.Get(info, "id").String()),
|
MsId: util.Get16MD5Encode(gjson.Get(info, "id").String()),
|
||||||
Alias: Alias,
|
Alias: Alias,
|
||||||
|
|||||||
@ -45,9 +45,9 @@ func bMy(m *tb.Message) {
|
|||||||
var inlineKeys [][]tb.InlineButton
|
var inlineKeys [][]tb.InlineButton
|
||||||
for _, u := range data {
|
for _, u := range data {
|
||||||
inlineBtn := tb.InlineButton{
|
inlineBtn := tb.InlineButton{
|
||||||
Unique: "my" + u.MsId,
|
Unique: "my" + strconv.Itoa(u.ID),
|
||||||
Text: u.Alias,
|
Text: u.Alias,
|
||||||
Data: u.MsId,
|
Data: strconv.Itoa(u.ID),
|
||||||
}
|
}
|
||||||
bot.Handle(&inlineBtn, bMyInlineBtn)
|
bot.Handle(&inlineBtn, bMyInlineBtn)
|
||||||
inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn})
|
inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn})
|
||||||
@ -59,7 +59,7 @@ func bMy(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
func bMyInlineBtn(c *tb.Callback) {
|
func bMyInlineBtn(c *tb.Callback) {
|
||||||
var u *model.Client
|
var u *model.Client
|
||||||
model.DB.Where("ms_id = ?", c.Data).First(&u)
|
model.DB.Where("id = ?", c.Data).First(&u)
|
||||||
bot.Send(c.Message.Chat,
|
bot.Send(c.Message.Chat,
|
||||||
fmt.Sprintf("信息\n别名:%s\nMS_ID(MD5): %s\nclient_id: %s\nclient_secret: %s\n最近更新时间: %s",
|
fmt.Sprintf("信息\n别名:%s\nMS_ID(MD5): %s\nclient_id: %s\nclient_secret: %s\n最近更新时间: %s",
|
||||||
u.Alias,
|
u.Alias,
|
||||||
@ -105,9 +105,9 @@ func bUnBind(m *tb.Message) {
|
|||||||
|
|
||||||
for _, u := range data {
|
for _, u := range data {
|
||||||
inlineBtn := tb.InlineButton{
|
inlineBtn := tb.InlineButton{
|
||||||
Unique: "unbind" + u.MsId,
|
Unique: "unbind" + strconv.Itoa(u.ID),
|
||||||
Text: u.Alias,
|
Text: u.Alias,
|
||||||
Data: u.MsId,
|
Data: strconv.Itoa(u.ID),
|
||||||
}
|
}
|
||||||
bot.Handle(&inlineBtn, bUnBindInlineBtn)
|
bot.Handle(&inlineBtn, bUnBindInlineBtn)
|
||||||
inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn})
|
inlineKeys = append(inlineKeys, []tb.InlineButton{inlineBtn})
|
||||||
@ -119,10 +119,10 @@ func bUnBind(m *tb.Message) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
func bUnBindInlineBtn(c *tb.Callback) {
|
func bUnBindInlineBtn(c *tb.Callback) {
|
||||||
if result := model.DB.Where("ms_id = ?", c.Data).Delete(&model.Client{}); result.Error != nil {
|
if result := model.DB.Where("id = ?", c.Data).Delete(&model.Client{}); result.Error != nil {
|
||||||
zap.S().Errorw("failed to delete db data",
|
zap.S().Errorw("failed to delete db data",
|
||||||
"error", result.Error,
|
"error", result.Error,
|
||||||
"ms_id", c.Data,
|
"id", c.Data,
|
||||||
)
|
)
|
||||||
bot.Send(c.Message.Chat, "解绑失败!")
|
bot.Send(c.Message.Chat, "解绑失败!")
|
||||||
return
|
return
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
ID int `gorm:"unique;primaryKey;not null"`
|
||||||
TgId int64 `gorm:"not null"`
|
TgId int64 `gorm:"not null"`
|
||||||
RefreshToken string `gorm:"not null"`
|
RefreshToken string `gorm:"not null"`
|
||||||
MsId string `gorm:"not null"`
|
MsId string `gorm:"not null"`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user