|
|
|
@ -5,6 +5,7 @@ import "time"
|
|
|
|
|
type Welcome struct {
|
|
|
|
|
ID uint `gorm:"primary_key" json:"id"`
|
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
|
Keyword string `json:"keyword"`
|
|
|
|
|
Content string `json:"content"`
|
|
|
|
|
IsDefault uint `json:"is_default"`
|
|
|
|
|
Ctime time.Time `json:"ctime"`
|
|
|
|
@ -18,23 +19,24 @@ func CreateWelcome(userId string, content string) uint {
|
|
|
|
|
UserId: userId,
|
|
|
|
|
Content: content,
|
|
|
|
|
Ctime: time.Now(),
|
|
|
|
|
Keyword: "welcome",
|
|
|
|
|
}
|
|
|
|
|
DB.Create(w)
|
|
|
|
|
return w.ID
|
|
|
|
|
}
|
|
|
|
|
func UpdateWelcome(userId string,id string, content string) uint {
|
|
|
|
|
func UpdateWelcome(userId string, id string, content string) uint {
|
|
|
|
|
if userId == "" || content == "" {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
w := &Welcome{
|
|
|
|
|
Content: content,
|
|
|
|
|
}
|
|
|
|
|
DB.Model(w).Where("user_id = ? and id = ?", userId,id).Update(w)
|
|
|
|
|
DB.Model(w).Where("user_id = ? and id = ?", userId, id).Update(w)
|
|
|
|
|
return w.ID
|
|
|
|
|
}
|
|
|
|
|
func FindWelcomeByUserId(userId interface{}) Welcome {
|
|
|
|
|
func FindWelcomeByUserIdKey(userId interface{}, keyword interface{}) Welcome {
|
|
|
|
|
var w Welcome
|
|
|
|
|
DB.Where("user_id = ? and is_default=?", userId, 1).First(&w)
|
|
|
|
|
DB.Where("user_id = ? and keyword=?", userId, keyword).First(&w)
|
|
|
|
|
return w
|
|
|
|
|
}
|
|
|
|
|
func FindWelcomesByUserId(userId interface{}) []Welcome {
|
|
|
|
@ -42,6 +44,11 @@ func FindWelcomesByUserId(userId interface{}) []Welcome {
|
|
|
|
|
DB.Where("user_id = ?", userId).Find(&w)
|
|
|
|
|
return w
|
|
|
|
|
}
|
|
|
|
|
func FindWelcomesByKeyword(userId interface{}, keyword interface{}) []Welcome {
|
|
|
|
|
var w []Welcome
|
|
|
|
|
DB.Where("user_id = ? and keyword=?", userId, keyword).Find(&w)
|
|
|
|
|
return w
|
|
|
|
|
}
|
|
|
|
|
func DeleteWelcome(userId interface{}, id string) {
|
|
|
|
|
DB.Where("user_id = ? and id = ?", userId, id).Delete(Welcome{})
|
|
|
|
|
}
|
|
|
|
|