res_multi_text.go 903 Bytes
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package res_m

import (
	"git.hilo.cn/hilo-common/_const/common"
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/myerr"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
)

type ResMultiText struct {
	mysql.Entity
	MsgId    uint
	Language mysql.Str
	Content  mysql.Str
}

func (r *ResMultiText) Get(db *gorm.DB) error {
	return db.Where(r).First(r).Error
}

func GetResMultiTextBy(model *domain.Model, msgId uint, Language mysql.Str) (*ResMultiText, error) {
	r := ResMultiText{}
	if err := model.DB().Where(&ResMultiText{
		MsgId:    msgId,
		Language: Language,
	}).First(&r).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			if err := model.DB().Where(&ResMultiText{
				MsgId:    msgId,
				Language: common.DEFAULT_LANG,
			}).First(&r).Error; err != nil {
				return nil, myerr.WrapErr(err)
			}
		} else {
			return nil, myerr.WrapErr(err)
		}

	}
	return &r, nil
}