package constant import ( "time" "github.com/jinzhu/now" ) // 需要自定义类型的常量放在这里 type General = int // 不在dao层中使用,在dao层使用models.No, models.Yes const ( YES General = 1 // 是 NO General = 2 // 否 ) // UploadFileType 上传文件类型 type UploadFileType = int const ( UploadFileTypePic UploadFileType = 1 // 普通图片 UploadFileTypePdf UploadFileType = 2 // pdf UploadFileTypeExcel UploadFileType = 3 // excel ExportFileTypeExcel UploadFileType = 3 // 导出的excel文件 ) const MaxFileSize int64 = 10 * 1024 * 1024 // ========================================== type SearchDateTimeType string const ( Today SearchDateTimeType = "today" // 今天 Yesterday SearchDateTimeType = "yesterday" // 昨天 ThisWeek SearchDateTimeType = "thisWeek" // 本周 ThisMonth SearchDateTimeType = "thisMonth" // 本月 LastThreeDays SearchDateTimeType = "lastThreeDays" // 近三天 LastSevenDays SearchDateTimeType = "lastSevenDays" // 近七天 LastMonthDays SearchDateTimeType = "lastMonthDays" // 近一个月 ) func (s SearchDateTimeType) GetRangeTime() (startTime, endTime time.Time) { switch s { case Today: return now.BeginningOfDay(), now.EndOfDay() case Yesterday: t := time.Now().AddDate(0, 0, -1) nTime := now.New(t) return nTime.BeginningOfDay(), nTime.EndOfDay() case ThisWeek: return now.BeginningOfWeek(), now.EndOfWeek() case ThisMonth: return now.BeginningOfMonth(), now.EndOfMonth() case LastThreeDays: return now.New(time.Now().AddDate(0, 0, -2)).BeginningOfDay(), now.EndOfDay() case LastSevenDays: return now.New(time.Now().AddDate(0, 0, -6)).BeginningOfDay(), now.EndOfDay() case LastMonthDays: return now.New(time.Now().AddDate(0, 0, -29)).BeginningOfDay(), now.EndOfDay() default: return time.Time{}, time.Time{} } } type PermissionType = int const ( PermissionPathSplit string = ";" PermissionMenu PermissionType = 1 // 菜单权限 PermissionFunc PermissionType = 2 // 功能权限 ) // ExpiredTime 过期时间 type ExpiredTime string const ( ExpiredTimeOneDay ExpiredTime = "oneDay" // 一天;24小时 ExpiredTimeThreeDay ExpiredTime = "threeDay" // 三天 ExpiredTimeSevenDay ExpiredTime = "sevenDay" // 七天 ) func (e ExpiredTime) GetExpiredTime() time.Time { switch e { case ExpiredTimeOneDay: return time.Now().AddDate(0, 0, 1) case ExpiredTimeThreeDay: return time.Now().AddDate(0, 0, 3) case ExpiredTimeSevenDay: return time.Now().AddDate(0, 0, 7) default: return time.Time{} } }