/
dict_service.go
79 lines (72 loc) · 1.73 KB
/
dict_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package service
import (
"github.com/GoodHot/TinyCMS/model"
"github.com/GoodHot/TinyCMS/orm"
)
type DictService struct {
PageSize int `val:"${website.page_size}"`
ORM *orm.ORM `ioc:"auto"`
}
func (s *DictService) Init() {
s.Save(&model.Dict{
Key: "website_name",
Name: "网站名称",
Description: "网站名称",
Type: model.DictTypeText,
Options: "",
Value: "网站名称",
ReadOnly: false,
})
s.Save(&model.Dict{
Key: "website_url",
Name: "网站地址",
Description: "网站地址",
Type: model.DictTypeText,
Options: "",
Value: "网站地址",
ReadOnly: false,
})
s.Save(&model.Dict{
Key: "keyword",
Name: "关键字",
Description: "SEO关键字",
Type: model.DictTypeText,
Options: "",
Value: "网站名称",
ReadOnly: false,
})
s.Save(&model.Dict{
Key: "description",
Name: "描述",
Description: "SEO描述",
Type: model.DictTypeTextArea,
Options: "",
Value: "网站名称",
ReadOnly: false,
})
s.Save(&model.Dict{
Key: "select",
Name: "select测试",
Description: "select测试",
Type: model.DictTypeSelect,
Options: "1,2,3,4,5",
Value: "1",
ReadOnly: false,
})
}
func (s *DictService) Save(dict *model.Dict) {
s.ORM.DB.Save(dict)
}
func (s *DictService) All() []*model.Dict {
dicts := []*model.Dict{}
s.ORM.DB.Find(&dicts)
return dicts
}
func (s *DictService) GetByKey(key string) *model.Dict {
var dict model.Dict
s.ORM.DB.Where("key = ?", key).Find(&dict)
return &dict
}
func (s *DictService) Update(dict *model.Dict) {
s.ORM.DB.Model(dict).Update("value", dict.Value)
}