apply.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package model
  2. import (
  3. "gorm.io/gorm"
  4. "project_management/app/e"
  5. "project_management/global"
  6. "strings"
  7. "time"
  8. )
  9. type Apply struct {
  10. gorm.Model
  11. AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id"` // 应用id
  12. AppName string `gorm:"type:varchar(50);index:idx_name,unique" json:"app_name" validate:"required" min:"3" max:"20"` // 应用名称
  13. AppDescription string `gorm:"type:varchar(50);not null;unique" json:"app_description" validate:"required"` // 应用描述
  14. CertificationTime time.Time `gorm:"type:datetime;not null;unique" json:"certification_time"` // 认证到期时间
  15. State int `gorm:"type:int;not null;unique" json:"state"` // 状态 0 正常 1 停用 2 过期 3 禁用
  16. }
  17. func (a Apply) AddApply(apply Apply) e.Rescode {
  18. //TODO implement me
  19. //默认每一应用有一年免费时间
  20. apply.CertificationTime = apply.CreatedAt.Add(time.Hour * 24 * 365)
  21. apply.State = 0
  22. tx := global.DBLink.Create(&apply)
  23. if tx.Error != nil {
  24. errMsg := tx.Error.Error()
  25. if strings.Contains(errMsg, "Duplicate entry") {
  26. return e.Repeat
  27. }
  28. }
  29. if tx.RowsAffected > 0 {
  30. return e.SUCCESS
  31. }
  32. return e.SUCCESS
  33. }
  34. func AppIdISRepeat(id string) bool {
  35. tx := global.DBLink.Where("app_id = ?", id).First(&Apply{})
  36. if tx.RowsAffected > 0 {
  37. return true
  38. }
  39. return false
  40. }