package model import ( "gorm.io/gorm" "project_management/app/e" "project_management/global" "strings" "time" ) type Apply struct { gorm.Model AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id"` // 应用id AppName string `gorm:"type:varchar(50);index:idx_name,unique" json:"app_name" validate:"required" min:"3" max:"20"` // 应用名称 AppDescription string `gorm:"type:varchar(50);not null;unique" json:"app_description" validate:"required"` // 应用描述 CertificationTime time.Time `gorm:"type:datetime;not null;unique" json:"certification_time"` // 认证到期时间 State int `gorm:"type:int;not null;unique" json:"state"` // 状态 0 正常 1 停用 2 过期 3 禁用 } func (a Apply) AddApply(apply Apply) e.Rescode { //TODO implement me //默认每一应用有一年免费时间 apply.CertificationTime = apply.CreatedAt.Add(time.Hour * 24 * 365) apply.State = 0 tx := global.DBLink.Create(&apply) if tx.Error != nil { errMsg := tx.Error.Error() if strings.Contains(errMsg, "Duplicate entry") { return e.Repeat } } if tx.RowsAffected > 0 { return e.SUCCESS } return e.SUCCESS } func AppIdISRepeat(id string) bool { tx := global.DBLink.Where("app_id = ?", id).First(&Apply{}) if tx.RowsAffected > 0 { return true } return false }