medal.go 668 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
package medal_tx

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/internal/model/user_m"
	"git.hilo.cn/hilo-common/resource/mysql"
	"time"
)

func SendMedal(model *domain.Model, userId, medalId mysql.ID, day int) error {
	endTime := time.Now().AddDate(0, 0, day)
	um := user_m.UserMedal{
		UserId:  userId,
		MedalId: uint32(medalId),
		EndTime: &endTime,
	}
hujiebin's avatar
hujiebin committed
17
	if err := um.Create(model.DB(), day); err != nil {
hujiebin's avatar
hujiebin committed
18 19 20 21
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
22 23 24 25

func DelMedal(model *domain.Model, userId, medalId mysql.ID) error {
	return model.DB().Model(user_m.UserMedal{}).Where("user_id = ? AND medal_id = ?", userId, medalId).Delete(&user_m.UserMedal{}).Error
}