-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad_c.go
195 lines (164 loc) · 4.34 KB
/
ad_c.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
* Copyright 2014 @ z3q.net.
* name :
* author : jarryliu
* date : 2014-02-05 21:53
* description :
* history :
*/
package partner
import (
"encoding/json"
"github.com/jsix/gof"
"github.com/jsix/gof/web"
"go2o/src/core/domain/interface/ad"
"go2o/src/core/service/dps"
"go2o/src/core/variable"
"go2o/src/x/echox"
"html/template"
"net/http"
"strconv"
)
// 广告控制器
type adC struct {
}
//广告列表
func (this *adC) List(ctx *echox.Context) error {
return ctx.RenderOK("ad.list.html", ctx.NewData())
}
// 修改广告
func (this *adC) Edit(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
id, _ := strconv.Atoi(ctx.Query("id"))
e := dps.AdvertisementService.GetAdvertisement(partnerId, id)
js, _ := json.Marshal(e)
d := ctx.NewData()
d.Map["entity"] = template.JS(js)
return ctx.RenderOK("ad.edit.html", d)
}
// 保存广告
func (this *adC) Create(ctx *echox.Context) error {
e := ad.ValueAdvertisement{
Enabled: 1,
}
js, _ := json.Marshal(e)
d := ctx.NewData()
d.Map["entity"] = template.JS(js)
return ctx.RenderOK("ad.edit.html", d)
}
// 删除广告(POST)
func (this *adC) Delete_ad(ctx *echox.Context) error {
req := ctx.HttpRequest()
if req.Method == "POST" {
req.ParseForm()
var result gof.Message
partnerId := getPartnerId(ctx)
adId, _ := strconv.Atoi(req.FormValue("id"))
err := dps.AdvertisementService.DelAdvertisement(partnerId, adId)
if err != nil {
result.Message = err.Error()
} else {
result.Result = true
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}
// 保存广告(POST)
func (this *adC) SaveAd(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
req := ctx.HttpRequest()
if req.Method == "POST" {
req.ParseForm()
var result gof.Message
e := ad.ValueAdvertisement{}
web.ParseFormToEntity(req.Form, &e)
//更新
e.PartnerId = partnerId
id, err := dps.AdvertisementService.SaveAdvertisement(partnerId, &e)
if err != nil {
result.Message = err.Error()
} else {
result.Result = true
result.Data = id
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}
func (this *adC) Ad_data1(ctx *echox.Context) error {
return ctx.String(http.StatusOK, `<span style="color:red">暂只支持轮播广告</span>`)
}
func (this *adC) Ad_data2(ctx *echox.Context) error {
return ctx.String(http.StatusOK, `<span style="color:red">暂只支持轮播广告</span>`)
}
//轮播广告
func (this *adC) Ad_data3(ctx *echox.Context) error {
d := ctx.NewData()
d.Map["adId"] = ctx.Query("id")
return ctx.RenderOK("ad.data3.html", d)
}
// 创建广告图片
func (this *adC) CreateAdImage(ctx *echox.Context) error {
adId, _ := strconv.Atoi(ctx.Query("ad_id"))
e := ad.ValueImage{
Enabled: 1,
AdvertisementId: adId,
LinkUrl: "http://",
ImageUrl: ctx.App.Config().GetString(variable.NoPicPath),
}
js, _ := json.Marshal(e)
d := ctx.NewData()
d.Map["entity"] = template.JS(js)
return ctx.RenderOK("ad.image.html", d)
}
// 保存广告
func (this *adC) EditAdImage(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
adId, _ := strconv.Atoi(ctx.Query("ad_id"))
imgId, _ := strconv.Atoi(ctx.Query("id"))
e := dps.AdvertisementService.GetValueAdImage(partnerId, adId, imgId)
js, _ := json.Marshal(e)
d := ctx.NewData()
d.Map["entity"] = template.JS(js)
return ctx.RenderOK("ad.image.html", d)
}
// 保存图片(POST)
func (this *adC) SaveImage(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
r := ctx.HttpRequest()
if r.Method == "POST" {
r.ParseForm()
var result gof.Message
e := ad.ValueImage{}
web.ParseFormToEntity(r.Form, &e)
id, err := dps.AdvertisementService.SaveImage(partnerId, e.AdvertisementId, &e)
if err != nil {
result.Message = err.Error()
} else {
result.Result = true
result.Data = id
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}
// 删除广告图片(POST)
func (this *adC) Delete_image(ctx *echox.Context) error {
req := ctx.HttpRequest()
if req.Method == "POST" {
req.ParseForm()
var result gof.Message
partnerId := getPartnerId(ctx)
adId, _ := strconv.Atoi(req.FormValue("ad_id"))
imgId, _ := strconv.Atoi(req.FormValue("id"))
err := dps.AdvertisementService.DelAdImage(partnerId, adId, imgId)
if err != nil {
result.Message = err.Error()
} else {
result.Result = true
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}