92 lines
3.6 KiB
Go
92 lines
3.6 KiB
Go
package models
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// CmsSolution CMS 解决方案(特色服务) yz_cms_solution
|
|
type CmsSolution struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
|
|
Title string `orm:"column(title);size(100)" json:"title"`
|
|
Thumb string `orm:"column(thumb);size(500);default()" json:"thumb"`
|
|
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
|
|
Content string `orm:"column(content);type(mediumtext);null" json:"content"`
|
|
URL string `orm:"column(url);size(500);default()" json:"url"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
|
|
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
|
}
|
|
|
|
func (m *CmsSolution) TableName() string {
|
|
return "yz_cms_solution"
|
|
}
|
|
|
|
// CmsSolutionCategory CMS 解决方案分类 yz_cms_solution_category
|
|
type CmsSolutionCategory struct {
|
|
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
|
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
|
|
Title string `orm:"column(title);size(100)" json:"title"`
|
|
Pid uint64 `orm:"column(pid);default(0)" json:"pid"`
|
|
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
|
|
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
|
Status int8 `orm:"column(status);default(1)" json:"status"`
|
|
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
|
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
|
|
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
|
}
|
|
|
|
func (m *CmsSolutionCategory) TableName() string {
|
|
return "yz_cms_solution_category"
|
|
}
|
|
|
|
var cmsSolutionTablesOnce sync.Once
|
|
|
|
// EnsureCmsSolutionTables 首次使用时自动建表(若不存在)。
|
|
func EnsureCmsSolutionTables() error {
|
|
var err error
|
|
cmsSolutionTablesOnce.Do(func() {
|
|
_, err = Orm.Raw(`
|
|
CREATE TABLE IF NOT EXISTS yz_cms_solution (
|
|
id bigint unsigned NOT NULL AUTO_INCREMENT,
|
|
tid bigint unsigned NOT NULL DEFAULT 0,
|
|
title varchar(100) NOT NULL DEFAULT '',
|
|
thumb varchar(500) NOT NULL DEFAULT '',
|
|
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
|
content mediumtext,
|
|
url varchar(500) NOT NULL DEFAULT '',
|
|
sort int NOT NULL DEFAULT 0,
|
|
status tinyint NOT NULL DEFAULT 1,
|
|
create_time datetime NOT NULL,
|
|
update_time datetime DEFAULT NULL,
|
|
delete_time datetime DEFAULT NULL,
|
|
PRIMARY KEY (id),
|
|
KEY idx_tid_status (tid, status)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
|
|
if err != nil {
|
|
return
|
|
}
|
|
// 确保已有表补齐 content 字段
|
|
_, _ = Orm.Raw("ALTER TABLE yz_cms_solution ADD COLUMN content mediumtext").Exec()
|
|
_, err = Orm.Raw(`
|
|
CREATE TABLE IF NOT EXISTS yz_cms_solution_category (
|
|
id bigint unsigned NOT NULL AUTO_INCREMENT,
|
|
tid bigint unsigned NOT NULL DEFAULT 0,
|
|
title varchar(100) NOT NULL DEFAULT '',
|
|
pid bigint unsigned NOT NULL DEFAULT 0,
|
|
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
|
|
sort int NOT NULL DEFAULT 0,
|
|
status tinyint NOT NULL DEFAULT 1,
|
|
create_time datetime NOT NULL,
|
|
update_time datetime DEFAULT NULL,
|
|
delete_time datetime DEFAULT NULL,
|
|
PRIMARY KEY (id),
|
|
KEY idx_tid_pid (tid, pid)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
|
|
})
|
|
return err
|
|
}
|