175 lines
4.8 KiB
Go
175 lines
4.8 KiB
Go
package model
|
||
|
||
import (
|
||
config2 "SciencesServer/app/basic/config"
|
||
"SciencesServer/config"
|
||
"SciencesServer/utils"
|
||
"strings"
|
||
"time"
|
||
)
|
||
|
||
type Gender struct {
|
||
Gender GenderKind `gorm:"column:gender;type:tinyint(1);default:1;comment:性别(1:男,2:女)" json:"gender"` // 性别(1:男,2:女)
|
||
}
|
||
|
||
type GenderKind int
|
||
|
||
const (
|
||
// GenderKindForMale 男性
|
||
GenderKindForMale GenderKind = iota + 1
|
||
// GenderKindForFemale 女性
|
||
GenderKindForFemale
|
||
)
|
||
|
||
func (m *Gender) GenderTitle() string {
|
||
if m.Gender == GenderKindForMale {
|
||
return "男"
|
||
} else if m.Gender == GenderKindForFemale {
|
||
return "女"
|
||
}
|
||
return ""
|
||
}
|
||
|
||
// Image 单一图片信息
|
||
type Image struct {
|
||
Image string `gorm:"column:image;type:varchar(255);default:'';comment:图片" json:"image"`
|
||
}
|
||
|
||
func (m *Image) Analysis(domain string) string {
|
||
if m.Image == "" {
|
||
return ""
|
||
}
|
||
return domain + m.Image
|
||
}
|
||
|
||
// Images 多个图片信息
|
||
type Images struct {
|
||
Images string `gorm:"column:images;type:text;comment:图片" json:"images"`
|
||
}
|
||
|
||
// AnalysisSlice Slice解析
|
||
func (m *Images) AnalysisSlice(domain string) string {
|
||
images := strings.Split(m.Images, ",")
|
||
|
||
for k, v := range images {
|
||
images[k] = domain + v
|
||
}
|
||
return strings.Join(images, ",")
|
||
}
|
||
|
||
// AccountStatus 账号状态
|
||
type AccountStatus struct {
|
||
Status AccountStatusKind `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:启用,2:禁用)" json:"-"`
|
||
}
|
||
|
||
// AccountStatusKind 状态
|
||
type AccountStatusKind int
|
||
|
||
const (
|
||
// AccountStatusForEnable 启用
|
||
AccountStatusForEnable AccountStatusKind = iota + 1
|
||
// AccountStatusForDisable 禁用
|
||
AccountStatusForDisable
|
||
)
|
||
|
||
// Shelf 上下架状态
|
||
type Shelf struct {
|
||
ShelfStatus ShelfStatusKind `gorm:"column:shelf_status;type:tinyint(1);default:0;comment:上下架状态(1:上架,2:下架)" json:"shelf_status"`
|
||
}
|
||
|
||
type ShelfStatusKind int
|
||
|
||
const (
|
||
// ShelfStatusForUp 上架
|
||
ShelfStatusForUp ShelfStatusKind = iota + 1
|
||
// ShelfStatusForDown 下架
|
||
ShelfStatusForDown
|
||
)
|
||
|
||
// Examine 审核状态
|
||
type Examine struct {
|
||
ExamineStatus ExamineStatusKind `gorm:"column:examine_status;type:tinyint(1);default:0;comment:审核状态(1:审核中,2:审核通过,3:审核拒绝)" json:"examine_status"`
|
||
ExamineRemark string `gorm:"column:examine_remark;type:varchar(255);default:'';comment:审核备注" json:"examine_remark"`
|
||
ExamineAt time.Time `gorm:"column:examine_at;type:datetime;default:null;comment:审核时间" json:"examine_at"`
|
||
}
|
||
|
||
// ExamineStatusKind 审核状态
|
||
type ExamineStatusKind int
|
||
|
||
const (
|
||
// ExamineStatusForOngoing 审核中
|
||
ExamineStatusForOngoing ExamineStatusKind = iota + 1
|
||
// ExamineStatusForAgree 审核通过
|
||
ExamineStatusForAgree
|
||
// ExamineStatusForRefuse 审核拒绝
|
||
ExamineStatusForRefuse
|
||
)
|
||
|
||
// InvalidStatus 失效状态
|
||
type InvalidStatus struct {
|
||
InvalidStatus ExamineStatusKind `gorm:"column:invalid_status;type:tinyint(1);default:0;comment:失效状态(0:未失效,1:已失效" json:"invalid_status"`
|
||
}
|
||
|
||
// InvalidStatusKind 失效状态
|
||
type InvalidStatusKind int
|
||
|
||
const (
|
||
// InvalidStatusForYes 已失效
|
||
InvalidStatusForYes InvalidStatusKind = iota - 1
|
||
// InvalidStatusForNot 未失效
|
||
InvalidStatusForNot
|
||
)
|
||
|
||
// TechnologyStatus 科技信息状态
|
||
type TechnologyStatus struct {
|
||
Status TechnologyStatusKind `gorm:"column:status;type:tinyint(1);default:0;comment:状态" json:"status"`
|
||
}
|
||
|
||
type TechnologyStatusKind int
|
||
|
||
const (
|
||
// TechnologyStatusKindForDraft 草稿箱
|
||
TechnologyStatusKindForDraft TechnologyStatusKind = iota
|
||
// TechnologyStatusKindForExamining 审核中
|
||
TechnologyStatusKindForExamining
|
||
// TechnologyStatusKindForAgree 审核通过
|
||
TechnologyStatusKindForAgree
|
||
// TechnologyStatusKindForRefuse 审核拒绝
|
||
TechnologyStatusKindForRefuse
|
||
)
|
||
|
||
type Area struct {
|
||
Province string `gorm:"column:province;type:varchar(8);default:'';comment:所在省" json:"province"`
|
||
City string `gorm:"column:city;type:varchar(8);default:'';comment:所在市" json:"city"`
|
||
District string `gorm:"column:district;type:varchar(8);default:'';comment:所在区/县" json:"district"`
|
||
Address string `gorm:"column:address;type:varchar(255);default:'';comment:详细地址" json:"address"`
|
||
}
|
||
|
||
func (m *Area) FormatBasic() string {
|
||
address := make([]string, 0)
|
||
address = append(address, config2.MemoryForAreaInfo[config.DefaultChinaAreaCode][m.Province])
|
||
|
||
if m.City != "" {
|
||
address = append(address, config2.MemoryForAreaInfo[m.Province][m.City])
|
||
}
|
||
if m.District != "" {
|
||
address = append(address, config2.MemoryForAreaInfo[m.City][m.District])
|
||
}
|
||
return strings.Join(address, "-")
|
||
}
|
||
|
||
func (m *Area) FormatDetail() string {
|
||
return m.FormatBasic() + ";" + m.Address
|
||
}
|
||
|
||
// Position 坐标信息
|
||
type Position struct {
|
||
Longitude float64 `json:"longitude"` // 经度
|
||
Latitude float64 `json:"latitude"` // 纬度
|
||
}
|
||
|
||
// Format 格式化
|
||
func (m *Position) Format() string {
|
||
return utils.AnyToJSON(m)
|
||
}
|