wcj 5 年之前
父节点
当前提交
aa06de4369
共有 1 个文件被更改,包括 38 次插入0 次删除
  1. 38 0
      src/jfw/modules/subscribepay/src/timetask/timetask.go

+ 38 - 0
src/jfw/modules/subscribepay/src/timetask/timetask.go

@@ -0,0 +1,38 @@
+package timetask
+
+import (
+	"time"
+)
+
+func Run() {
+	checkIsExpire()
+	expireRemind()
+}
+
+//每天0点 检查试用、vip服务是否到期
+func checkIsExpire() {
+	crontab(0, func() {
+
+	})
+}
+
+//即将到期或者已到期发推送消息
+func expireRemind() {
+	crontab(10, func() {
+
+	})
+}
+
+func crontab(hour int, f func()) {
+	go f()
+	now := time.Now()
+	t := time.Date(now.Year(), now.Month(), now.Day()+1, hour, 0, 0, 0, time.Local)
+	timer := time.NewTimer(t.Sub(now))
+	for {
+		select {
+		case <-timer.C:
+			go f()
+			timer.Reset(24 * time.Hour)
+		}
+	}
+}