12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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"`
- 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"`
- }
- func (a Apply) AddApply(apply Apply) e.Rescode {
-
-
- 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
- }
|