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

Skip to content

Commit b781d93

Browse files
committed
用户一个月内发完邮件
1 parent 7d20448 commit b781d93

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ welcome.png
4141

4242
*.json
4343

44-
.DS_Store
44+
.DS_Store
45+
/env.ini

src/logic/email.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ func (self EmailLogic) EmailNotice() {
170170
users = make([]*model.User, 0)
171171
)
172172

173+
day := time.Now().Day()
174+
monthDayNum := util.MonthDayNum(time.Now())
175+
173176
for {
174177
err = MasterDB.Where("uid>?", lastUid).Asc("uid").Limit(limit).Find(&users)
175178
if err != nil {
@@ -186,6 +189,10 @@ func (self EmailLogic) EmailNotice() {
186189
lastUid = user.Uid
187190
}
188191

192+
if user.Uid%monthDayNum != day {
193+
continue
194+
}
195+
189196
if user.Unsubscribe == 1 {
190197
logger.Infoln("user unsubscribe", user)
191198
continue
@@ -208,7 +215,7 @@ func (self EmailLogic) EmailNotice() {
208215
self.SendMail("每周精选", content, []string{user.Email})
209216

210217
// 控制发信速度
211-
time.Sleep(2 * time.Second)
218+
time.Sleep(60 * time.Second)
212219
}
213220

214221
users = make([]*model.User, 0)

src/server/studygolang/background.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func ServeBackGround() {
5757
c.AddFunc("@daily", logic.GenSitemap)
5858

5959
// 给用户发邮件,如通知网站最近的动态,每周的晨读汇总等
60-
c.AddFunc("0 0 4 * * 1", logic.DefaultEmail.EmailNotice)
60+
c.AddFunc("0 0 0 * * *", logic.DefaultEmail.EmailNotice)
6161
}
6262

6363
// 每天对活跃用户奖励铜币

src/util/time.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 util
8+
9+
import "time"
10+
11+
// MonthDayNum t 所在时间的月份总天数
12+
func MonthDayNum(t time.Time) int {
13+
isLeapYear := isLeap(t.Year())
14+
15+
month := t.Month()
16+
switch month {
17+
case time.January, time.March, time.May, time.July, time.August, time.October, time.December:
18+
return 31
19+
case time.February:
20+
if isLeapYear {
21+
return 29
22+
}
23+
24+
return 28
25+
default:
26+
return 30
27+
}
28+
}
29+
30+
// 是否闰年
31+
func isLeap(year int) bool {
32+
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
33+
}

src/vendor/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
{
312312
"importpath": "github.com/polaris1119/nosql",
313313
"repository": "https://github.com/polaris1119/nosql",
314-
"revision": "182e26aeeef42c383b9eb2d809f07c7f723cb403",
314+
"revision": "f62516f53b5a1d584c925e364938d404ada94f4d",
315315
"branch": "master"
316316
},
317317
{

0 commit comments

Comments
 (0)