Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc35ef1

Browse files
committed
广告管理
1 parent 33096a6 commit bc35ef1

24 files changed

+326
-145
lines changed

config/db.sql

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,19 +428,22 @@ CREATE TABLE `book` (
428428

429429
CREATE TABLE IF NOT EXISTS `advertisement` (
430430
`id` int unsigned NOT NULL AUTO_INCREMENT,
431-
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '广告名称',
432-
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '广告内容代码(html、js等)',
433-
`source` varchar(20) NOT NULL DEFAULT '' COMMENT '广告来源,如 baidu_union,shiyanlou',
434-
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
431+
`name` varchar(31) NOT NULL DEFAULT '' COMMENT '广告名称',
432+
`ad_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '广告类型:0-直接在html显示;1-js 操作 html',
433+
`code` varchar(1022) NOT NULL DEFAULT '' COMMENT '广告内容代码(html、js等)',
434+
`source` varchar(31) NOT NULL DEFAULT '' COMMENT '广告来源,如 百度联盟,阿里云',
435+
`is_online` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否在线:0-下线;1-在线',
436+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
435437
PRIMARY KEY (`id`)
436438
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '广告表';
437439

438440
CREATE TABLE IF NOT EXISTS `page_ad` (
439441
`id` int unsigned NOT NULL AUTO_INCREMENT,
440-
`ad_id` varchar(20) NOT NULL DEFAULT '' COMMENT '广告名称',
441-
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '广告内容代码(html、js等)',
442-
`source` varchar(20) NOT NULL DEFAULT '' COMMENT '广告来源,如 baidu_union,shiyanlou',
443-
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
442+
`path` varchar(31) NOT NULL DEFAULT '' COMMENT '页面路径',
443+
`ad_id` int unsigned NOT NULL DEFAULT 0 COMMENT '广告ID',
444+
`position` varchar(15) NOT NULL DEFAULT '' COMMENT '广告在页面的位置,英文字符串',
445+
`is_online` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否在线:0-下线;1-在线',
446+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
444447
PRIMARY KEY (`id`)
445448
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '页面广告管理表';
446449

src/http/http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ func Render(ctx echo.Context, contentTpl string, data map[string]interface{}) er
120120
return err
121121
}
122122

123+
data["pos_ad"] = logic.DefaultAd.FindAll(ctx, ctx.Path())
124+
123125
return executeTpl(ctx, tpl, data)
124126
}
125127

src/logic/ad.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2017 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author:polaris [email protected]
6+
7+
package logic
8+
9+
import (
10+
"model"
11+
12+
. "db"
13+
14+
"github.com/polaris1119/set"
15+
"golang.org/x/net/context"
16+
)
17+
18+
type AdLogic struct{}
19+
20+
var DefaultAd = AdLogic{}
21+
22+
func (AdLogic) FindAll(ctx context.Context, path string) map[string]*model.Advertisement {
23+
objLog := GetLogger(ctx)
24+
25+
pageAds := make([]*model.PageAd, 0)
26+
err := MasterDB.Where("path=? AND is_online=1", path).Find(&pageAds)
27+
if err != nil {
28+
objLog.Errorln("AdLogic FindAll PageAd error:", err)
29+
return nil
30+
}
31+
32+
adIdSet := set.New(set.NonThreadSafe)
33+
for _, pageAd := range pageAds {
34+
adIdSet.Add(pageAd.AdId)
35+
}
36+
37+
adMap := make(map[int]*model.Advertisement)
38+
err = MasterDB.In("id", set.IntSlice(adIdSet)).Find(&adMap)
39+
if err != nil {
40+
objLog.Errorln("AdLogic FindAll Advertisement error:", err)
41+
return nil
42+
}
43+
44+
posAdsMap := make(map[string]*model.Advertisement, len(pageAds))
45+
for _, pageAd := range pageAds {
46+
if adMap[pageAd.AdId].IsOnline {
47+
posAdsMap[pageAd.Position] = adMap[pageAd.AdId]
48+
}
49+
}
50+
51+
return posAdsMap
52+
}

src/logic/email.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,16 @@ func (self EmailLogic) EmailNotice() {
151151
logger.Errorln("find topic error:", err)
152152
}
153153

154+
global.App.SetCopyright()
155+
154156
data := map[string]interface{}{
155157
"readings": readings,
156158
"articles": articles,
157159
"topics": topics,
158160
"beginDate": beginDate,
159161
"endDate": endDate,
162+
"setting": WebsiteSetting,
163+
"app": global.App,
160164
}
161165

162166
// 给所有用户发送邮件

src/model/ad.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
package model
8+
9+
import "time"
10+
11+
type Advertisement struct {
12+
Id int `json:"id" xorm:"pk autoincr"`
13+
Name string `json:"name"`
14+
AdType int `json:"ad_type"`
15+
Code string `json:"code"`
16+
Source string `json:"source"`
17+
IsOnline bool `json:"is_online"`
18+
CreatedAt time.Time `json:"created_at" xorm:"<-"`
19+
}
20+
21+
type PageAd struct {
22+
Id int `json:"id" xorm:"pk autoincr"`
23+
Path string `json:"path"`
24+
AdId int `json:"ad_id"`
25+
Position string `json:"position"`
26+
IsOnline bool `json:"is_online"`
27+
CreatedAt time.Time `json:"created_at" xorm:"<-"`
28+
}

src/model/default_avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ import "time"
1111
type DefaultAvatar struct {
1212
Id int `json:"-" xorm:"pk autoincr"`
1313
Filename string
14-
CreatedAt time.Time `json:"-" xorm:"created"`
14+
CreatedAt time.Time `json:"-" xorm:"<-"`
1515
}

template/articles/detail.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ <h2>文章点评:</h2>
144144
</div>
145145
</div>
146146

147-
<div class="row box_white sidebar">
148-
<script type="text/javascript">
149-
var cpro_id="u1996895";
150-
(window["cproStyleApi"] = window["cproStyleApi"] || {})[cpro_id]={at:"3",rsi0:"291",rsi1:"291",pat:"6",tn:"baiduCustNativeAD",rss1:"#FFFFFF",conBW:"0",adp:"1",ptt:"0",titFF:"%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91",titFS:"14",rss2:"#000000",titSU:"0",ptbg:"90",piw:"0",pih:"0",ptp:"0"}
151-
</script>
152-
<script src="//cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script>
147+
{{if .pos_ad.right1}}
148+
<div class="row box_white sidebar" id="ad-right1">
149+
{{if eq .pos_ad.right1.AdType 0}}
150+
{{noescape .pos_ad.right1.Code}}
151+
{{end}}
153152
</div>
153+
{{end}}
154154

155155
<div class="row box_white sidebar">
156156
<div class="top">
@@ -308,6 +308,13 @@ <h3 class="title"><i class="glyphicon glyphicon-fire"></i>&nbsp;<a href="/projec
308308
});
309309

310310
</script>
311+
312+
{{if .pos_ad.right1}}
313+
{{if eq .pos_ad.right1.AdType 1}}
314+
{{noescape .pos_ad.right1.Code}}
315+
{{end}}
316+
{{end}}
317+
311318
<script>
312319
var baiduImagePlus = {
313320
noLogo:true,

template/articles/list.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ <h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
113113
</div>
114114
</div>
115115

116-
<div class="row box_white sidebar">
117-
<script type="text/javascript">
118-
var cpro_id="u1996895";
119-
(window["cproStyleApi"] = window["cproStyleApi"] || {})[cpro_id]={at:"3",rsi0:"291",rsi1:"291",pat:"6",tn:"baiduCustNativeAD",rss1:"#FFFFFF",conBW:"0",adp:"1",ptt:"0",titFF:"%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91",titFS:"14",rss2:"#000000",titSU:"0",ptbg:"90",piw:"0",pih:"0",ptp:"0"}
120-
</script>
121-
<script src="//cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script>
116+
{{if .pos_ad.right1}}
117+
<div class="row box_white sidebar" id="ad-right1">
118+
{{if eq .pos_ad.right1.AdType 0}}
119+
{{noescape .pos_ad.right1.Code}}
120+
{{end}}
122121
</div>
122+
{{end}}
123+
123124
</div>
124125

125126
</div>
@@ -133,4 +134,11 @@ <h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
133134
"/comments/recent",
134135
];
135136
</script>
137+
138+
{{if .pos_ad.right1}}
139+
{{if eq .pos_ad.right1.AdType 1}}
140+
{{noescape .pos_ad.right1.Code}}
141+
{{end}}
142+
{{end}}
143+
136144
{{end}}

template/books/detail.html

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ <h2>文章点评:</h2>
137137
</div>
138138
</div>
139139

140-
<div class="row box_white sidebar">
141-
<script type="text/javascript">
142-
var cpro_id="u1996895";
143-
(window["cproStyleApi"] = window["cproStyleApi"] || {})[cpro_id]={at:"3",rsi0:"291",rsi1:"291",pat:"6",tn:"baiduCustNativeAD",rss1:"#FFFFFF",conBW:"0",adp:"1",ptt:"0",titFF:"%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91",titFS:"14",rss2:"#000000",titSU:"0",ptbg:"90",piw:"0",pih:"0",ptp:"0"}
144-
</script>
145-
<script src="//cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script>
140+
{{if .pos_ad.right1}}
141+
<div class="row box_white sidebar" id="ad-right1">
142+
{{if eq .pos_ad.right1.AdType 0}}
143+
{{noescape .pos_ad.right1.Code}}
144+
{{end}}
146145
</div>
146+
{{end}}
147147

148148
<div class="row box_white sidebar">
149149
<div class="top">
@@ -199,17 +199,11 @@ <h3 class="title"><i class="glyphicon glyphicon-fire"></i>&nbsp;<a href="/projec
199199
});
200200
</script>
201201
<script type="text/javascript" src="/static/ckeditor/config.js"></script>
202-
<script>
203-
var baiduImagePlus = {
204-
noLogo:true,
205-
unionId:'u2368846',
206-
formList:[{formId:10}]
207-
};
208-
</script>
209-
<script src="//cpro.baidustatic.com/cpro/ui/i.js"></script>
210-
<script type="text/javascript">
211-
/* 内文方式 创建于 2015-03-15*/
212-
var cpro_id = "u1989498";
213-
</script>
214-
<script src="//cpro.baidustatic.com/cpro/ui/cnw.js" type="text/javascript"></script>
202+
203+
{{if .pos_ad.right1}}
204+
{{if eq .pos_ad.right1.AdType 1}}
205+
{{noescape .pos_ad.right1.Code}}
206+
{{end}}
207+
{{end}}
208+
215209
{{end}}

template/books/list.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ <h4><a href="/book/{{.Id}}" target="_blank" title="{{.Name}}">{{.Name}}</a></h4>
7272
</div>
7373
</div>
7474

75-
<div class="row box_white sidebar">
76-
<script type="text/javascript">
77-
var cpro_id="u1996895";
78-
(window["cproStyleApi"] = window["cproStyleApi"] || {})[cpro_id]={at:"3",rsi0:"291",rsi1:"291",pat:"6",tn:"baiduCustNativeAD",rss1:"#FFFFFF",conBW:"0",adp:"1",ptt:"0",titFF:"%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91",titFS:"14",rss2:"#000000",titSU:"0",ptbg:"90",piw:"0",pih:"0",ptp:"0"}
79-
</script>
80-
<script src="//cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script>
75+
{{if .pos_ad.right1}}
76+
<div class="row box_white sidebar" id="ad-right1">
77+
{{if eq .pos_ad.right1.AdType 0}}
78+
{{noescape .pos_ad.right1.Code}}
79+
{{end}}
8180
</div>
81+
{{end}}
82+
8283
</div>
8384

8485
</div>
@@ -95,4 +96,11 @@ <h4><a href="/book/{{.Id}}" target="_blank" title="{{.Name}}">{{.Name}}</a></h4>
9596
"/comments/recent",
9697
];
9798
</script>
99+
100+
{{if .pos_ad.right1}}
101+
{{if eq .pos_ad.right1.AdType 1}}
102+
{{noescape .pos_ad.right1.Code}}
103+
{{end}}
104+
{{end}}
105+
98106
{{end}}

template/email.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5-
<title>Go语言中文网 —— 每周精选</title>
5+
<title>{{.setting.Name}} —— 每周精选</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
77
</head>
88
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif; font-size: 16px;">
@@ -11,7 +11,7 @@
1111
<td style="padding:30px 0 5px 0;">
1212
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="background-color: white; padding: 10px;">
1313
<tr>
14-
<td style="font-size: 20px;"><a href="http://studygolang.com?fr=email" target="_blank" style="text-decoration: none;">Go语言中文网</a>&nbsp;每周精选</td>
14+
<td style="font-size: 20px;"><a href="http://{{.setting.Domain}}?fr=email" target="_blank" style="text-decoration: none;">{{.setting.Name}}</a>&nbsp;每周精选</td>
1515
<td align="right">{{.beginDate}}至{{.endDate}}</td>
1616
</tr>
1717
</table>
@@ -24,15 +24,15 @@
2424
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="background-color: white; padding: 10px;">
2525
<tr>
2626
<td style="padding: 10px 0 20px 0;font-size: 20px;" width="85%">本周每日晨读</td>
27-
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://studygolang.com/readings?fr=email" target="_blank">历史晨读>></a></td>
27+
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://{{.setting.Domain}}/readings?fr=email" target="_blank">历史晨读>></a></td>
2828
</tr>
2929
<tr>
3030
<td colspan="2">
3131
<table border="0" cellpadding="0" cellspacing="0" width="100%">
3232
{{range .readings}}
3333
<tr>
3434
<td width="10%" align="center" style="background-color: #DB6D4C; color: white;">{{time_format .Ctime}}</td>
35-
<td style="padding-left: 10px;">{{.Content}}<a href="http://studygolang.com/readings/{{.Id}}?fr=email" target="_blank">我要阅读>></a>{{if .Urls}}&nbsp;&nbsp;相关阅读:{{range .Urls}}<a href="http://studygolang.com/wr?u={{.}}&fr=email" target="_blank">{{end}}{{end}}</td>
35+
<td style="padding-left: 10px;">{{.Content}}<a href="http://{{$.setting.Domain}}/readings/{{.Id}}?fr=email" target="_blank">我要阅读>></a>{{if .Urls}}&nbsp;&nbsp;相关阅读:{{range .Urls}}<a href="http://{{$.setting.Domain}}/wr?u={{.}}&fr=email" target="_blank">{{end}}{{end}}</td>
3636
</tr>
3737
<tr><td>&nbsp;</td><td></td></tr>
3838
{{end}}
@@ -50,7 +50,7 @@
5050
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="background-color: white; padding: 10px;">
5151
<tr>
5252
<td style="padding: 10px 0 20px 0;font-size: 20px;" width="85%">本周精彩文章</td>
53-
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://studygolang.com/articles?fr=email" target="_blank">更多文章>></a></td>
53+
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://{{.setting.Domain}}/articles?fr=email" target="_blank">更多文章>></a></td>
5454
</tr>
5555
<tr>
5656
<td colspan="2">
@@ -60,11 +60,11 @@
6060
<td>
6161
<table>
6262
<tr>
63-
<td style="padding-bottom: 5px;"><a href="http://studygolang.com/articles/{{.Id}}?fr=email" target="_blank" title="{{.Title}}">{{.Title}}</a></td>
63+
<td style="padding-bottom: 5px;"><a href="http://{{$.setting.Domain}}/articles/{{.Id}}?fr=email" target="_blank" title="{{.Title}}">{{.Title}}</a></td>
6464
</tr>
6565
<tr>
6666
<td style="font-size: 13px; color: #aaa;">
67-
{{substring .Txt 250 "..."}}<a href="http://studygolang.com/articles/{{.Id}}?fr=email" target="_blank">阅读全文</a>
67+
{{substring .Txt 250 "..."}}<a href="http://{{$.setting.Domain}}/articles/{{.Id}}?fr=email" target="_blank">阅读全文</a>
6868
</td>
6969
</tr>
7070
</table>
@@ -86,7 +86,7 @@
8686
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="background-color: white; padding: 10px;">
8787
<tr>
8888
<td style="padding: 10px 0 20px 0;font-size: 20px;" width="85%">本周热门主题</td>
89-
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://studygolang.com/topics?fr=email" target="_blank">更多主题>></a></td>
89+
<td align="right" style="padding: 10px 0 20px 0;"><a href="http://{{.setting.Domain}}/topics?fr=email" target="_blank">更多主题>></a></td>
9090
</tr>
9191
<tr>
9292
<td colspan="2">
@@ -96,14 +96,14 @@
9696
<td>
9797
<table>
9898
<tr>
99-
<td style="padding-bottom: 5px;"><a href="http://studygolang.com/topics/{{.Tid}}?fr=email" target="_blank" title="{{.Title}}">
99+
<td style="padding-bottom: 5px;"><a href="http://{{$.setting.Domain}}/topics/{{.Tid}}?fr=email" target="_blank" title="{{.Title}}">
100100
{{.Title}}
101101
</a></td>
102102
</tr>
103103
<tr>
104104
<td style="font-size: 13px; color: #aaa;">
105105
{{substring .Content 250 "..."}}
106-
<a href="http://studygolang.com/topics/{{.Tid}}?fr=email">阅读全文</a></td>
106+
<a href="http://{{$.setting.Domain}}/topics/{{.Tid}}?fr=email">阅读全文</a></td>
107107
</tr>
108108
</table>
109109
</td>
@@ -122,10 +122,10 @@
122122
<td>
123123
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="padding: 10px;">
124124
<tr>
125-
<td align="center" style="font-family: Arial, sans-serif; font-size: 13px;">这封邮件的收件地址是 {{.email}};点击 <a href="http://studygolang.com/user/email/unsubscribe?u={{.token}}&email={{.email}}" target="_blank">退订</a></td>
125+
<td align="center" style="font-family: Arial, sans-serif; font-size: 13px;">这封邮件的收件地址是 {{.email}};点击 <a href="http://{{.setting.Domain}}/user/email/unsubscribe?u={{.token}}&email={{.email}}" target="_blank">退订</a></td>
126126
</tr>
127127
<tr>
128-
<td align="center" style="font-family: Arial, sans-serif; font-size: 13px; padding: 5px 0 10px 0;">© 2012-2015 Go语言中文网 studygolang.com</td>
128+
<td align="center" style="font-family: Arial, sans-serif; font-size: 13px; padding: 5px 0 10px 0;">© {{.app.Copyright}}</td>
129129
</tr>
130130
</table>
131131
</td>

0 commit comments

Comments
 (0)