-
Notifications
You must be signed in to change notification settings - Fork 0
/
advertisement.go
70 lines (60 loc) · 1.4 KB
/
advertisement.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
/**
* Copyright 2015 @ z3q.net.
* name : advertisement
* author : jarryliu
* date : -- :
* description :
* history :
*/
package ad
import (
"go2o/src/core/domain/interface/ad"
"time"
)
var _ ad.IAdvertisement = new(Advertisement)
type Advertisement struct {
Rep ad.IAdvertisementRep
Value *ad.ValueAdvertisement
}
// 获取领域对象编号
func (this *Advertisement) GetDomainId() int {
if this.Value != nil {
return this.Value.Id
}
return 0
}
// 是否为系统内置的广告
func (this *Advertisement) System() bool {
return this.Value.IsInternal == 1
}
// 广告类型
func (this *Advertisement) Type() int {
return this.Value.Type
}
// 广告名称
func (this *Advertisement) Name() string {
return this.Value.Name
}
// 设置值
func (this *Advertisement) SetValue(v *ad.ValueAdvertisement) error {
// 如果为系统内置广告,不能修改名称
if !this.System() {
this.Value.Name = v.Name
this.Value.Enabled = v.Enabled
}
this.Value.Type = v.Type
return nil
}
// 获取值
func (this *Advertisement) GetValue() *ad.ValueAdvertisement {
return this.Value
}
// 保存广告
func (this *Advertisement) Save() (int, error) {
id := this.Rep.GetIdByName(this.Value.PartnerId, this.Value.Name)
if id > 0 && id != this.GetDomainId() {
return this.GetDomainId(), ad.ErrNameExists
}
this.Value.UpdateTime = time.Now().Unix()
return this.Rep.SaveAdvertisementValue(this.Value)
}