|
@@ -79,10 +79,26 @@ func init() {
|
|
duration_hour = time.Duration(tmp) * time.Second
|
|
duration_hour = time.Duration(tmp) * time.Second
|
|
}
|
|
}
|
|
minutes, _ = strconv.Atoi(timerHMS[2])
|
|
minutes, _ = strconv.Atoi(timerHMS[2])
|
|
|
|
+
|
|
|
|
+ http.HandleFunc("/m", saveHandlerFunc)
|
|
|
|
+ http.ListenAndServe(":8878", nil)
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+var TesB = make(chan bool, 1)
|
|
|
|
+
|
|
|
|
+func saveHandlerFunc(res http.ResponseWriter, req *http.Request) {
|
|
|
|
+ req.ParseForm()
|
|
|
|
+ form := req.Form
|
|
|
|
+ t := form.Get("t")
|
|
|
|
+ ts := strings.Split(t, ".")
|
|
|
|
+ swordfish_subHour, _ = strconv.Atoi(ts[0])
|
|
|
|
+ minutes, _ = strconv.Atoi(ts[1])
|
|
|
|
+ TesB <- true
|
|
|
|
+}
|
|
|
|
+
|
|
func main() {
|
|
func main() {
|
|
crpc := new(creditrpc.CreditRpc)
|
|
crpc := new(creditrpc.CreditRpc)
|
|
rpc.Register(crpc)
|
|
rpc.Register(crpc)
|
|
@@ -92,6 +108,7 @@ func main() {
|
|
go http.Serve(l, nil)
|
|
go http.Serve(l, nil)
|
|
quartz()
|
|
quartz()
|
|
log.Println("启动积分系统", port)
|
|
log.Println("启动积分系统", port)
|
|
|
|
+
|
|
flag := make(chan bool)
|
|
flag := make(chan bool)
|
|
<-flag
|
|
<-flag
|
|
}
|
|
}
|
|
@@ -123,7 +140,7 @@ func quartz() {
|
|
//每天一次检查剑鱼积分
|
|
//每天一次检查剑鱼积分
|
|
//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
|
|
//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
|
|
|
|
|
|
- //TimerSwordFishFromUser()
|
|
|
|
|
|
+ TimerSwordFishFromUser()
|
|
|
|
|
|
//定时任务转赠积分24后无人接收即退回,本月不做了
|
|
//定时任务转赠积分24后无人接收即退回,本月不做了
|
|
/**
|
|
/**
|
|
@@ -165,55 +182,63 @@ func TimerSwordFishFromUser() {
|
|
now := time.Now()
|
|
now := time.Now()
|
|
// 计算下一个零点
|
|
// 计算下一个零点
|
|
next := now.Add(duration_hour)
|
|
next := now.Add(duration_hour)
|
|
- next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, minutes, 0, 0, next.Location())
|
|
|
|
|
|
+ next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, minutes, 10, 0, next.Location())
|
|
next64 := next.Unix()
|
|
next64 := next.Unix()
|
|
|
|
+ if int64(next.Sub(now)) < 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
t := time.NewTimer(next.Sub(now))
|
|
t := time.NewTimer(next.Sub(now))
|
|
- <-t.C
|
|
|
|
- /*执行逻辑*/
|
|
|
|
- log.Println("执行定时任务...")
|
|
|
|
- util.Try(func() {
|
|
|
|
- session := mongodb.GetMgoConn()
|
|
|
|
- defer mongodb.DestoryMongoConn(session)
|
|
|
|
- coll := session.DB("qfw").C("user")
|
|
|
|
- for code, typeName := range map[string]string{
|
|
|
|
- "A1": "tender",
|
|
|
|
- "A2": "bid",
|
|
|
|
- } {
|
|
|
|
- query := coll.Find(&map[string]interface{}{
|
|
|
|
- "o_msgset." + typeName + ".l_enddate": map[string]interface{}{
|
|
|
|
- "$gte": next64 - 600,
|
|
|
|
- "$lte": next64 + int64(swordfish_tipBeforeDays[0]*24*3600) + 7200,
|
|
|
|
- },
|
|
|
|
- "o_msgset." + typeName + ".i_status": 1,
|
|
|
|
- "o_msgset." + typeName + ".i_switchstatus": 1,
|
|
|
|
- }).Iter()
|
|
|
|
|
|
+ select {
|
|
|
|
+ case <-t.C:
|
|
|
|
+ /*执行逻辑*/
|
|
|
|
+ log.Println("执行定时任务...")
|
|
|
|
+ util.Try(func() {
|
|
|
|
+ session := mongodb.GetMgoConn()
|
|
|
|
+ defer mongodb.DestoryMongoConn(session)
|
|
|
|
+ coll := session.DB("qfw").C("user")
|
|
|
|
+ for code, typeName := range map[string]string{
|
|
|
|
+ "A1": "tender",
|
|
|
|
+ "A2": "bid",
|
|
|
|
+ } {
|
|
|
|
+ query := coll.Find(&map[string]interface{}{
|
|
|
|
+ "o_msgset." + typeName + ".l_enddate": map[string]interface{}{
|
|
|
|
+ "$gte": next64 - 600,
|
|
|
|
+ "$lte": next64 + int64(swordfish_tipBeforeDays[0]*24*3600) + 7200,
|
|
|
|
+ },
|
|
|
|
+ "o_msgset." + typeName + ".i_status": 1,
|
|
|
|
+ "o_msgset." + typeName + ".i_switchstatus": 1,
|
|
|
|
+ }).Iter()
|
|
|
|
|
|
- for tmp := make(map[string]interface{}); query.Next(tmp); {
|
|
|
|
- log.Println(tmp)
|
|
|
|
- util.Try(func() {
|
|
|
|
- tmpCode := tmp["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})
|
|
|
|
- endDate := tmpCode["l_enddate"].(int64)
|
|
|
|
- sub64 := (endDate - next64) / 86400
|
|
|
|
- if sub64 == 0 {
|
|
|
|
- //自动扣费
|
|
|
|
- doSubCreditByUser(util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string), typeName, code, &next, tmp)
|
|
|
|
- } else {
|
|
|
|
- //提示
|
|
|
|
- for _, v := range swordfish_tipBeforeDays {
|
|
|
|
- if int64(v) == sub64 {
|
|
|
|
- creditrpc.SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string))
|
|
|
|
|
|
+ for tmp := make(map[string]interface{}); query.Next(tmp); {
|
|
|
|
+ log.Println(tmp)
|
|
|
|
+ util.Try(func() {
|
|
|
|
+ tmpCode := tmp["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})
|
|
|
|
+ endDate := tmpCode["l_enddate"].(int64)
|
|
|
|
+ sub64 := (endDate - next64) / 86400
|
|
|
|
+ if sub64 == 0 {
|
|
|
|
+ //自动扣费
|
|
|
|
+ doSubCreditByUser(util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string), typeName, code, &next, tmp)
|
|
|
|
+ } else {
|
|
|
|
+ //提示
|
|
|
|
+ for _, v := range swordfish_tipBeforeDays {
|
|
|
|
+ if int64(v) == sub64 {
|
|
|
|
+ creditrpc.SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string))
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }, func(e interface{}) {})
|
|
|
|
- tmp = make(map[string]interface{})
|
|
|
|
|
|
+ }, func(e interface{}) {})
|
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }, func(e interface{}) {
|
|
|
|
- log.Println("定时任务,扣剑鱼积分时报错", e)
|
|
|
|
- })
|
|
|
|
- TimerSwordFishFromUser()
|
|
|
|
- break
|
|
|
|
|
|
+ }, func(e interface{}) {
|
|
|
|
+ log.Println("定时任务,扣剑鱼积分时报错", e)
|
|
|
|
+ })
|
|
|
|
+ //TimerSwordFishFromUser()
|
|
|
|
+ break
|
|
|
|
+ case <-TesB:
|
|
|
|
+ //TimerSwordFishFromUser()
|
|
|
|
+ break
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
}
|
|
}
|
|
@@ -230,7 +255,7 @@ func doSubCreditByUser(userId, umid, typeName, code string, next *time.Time, use
|
|
bsub = true
|
|
bsub = true
|
|
}
|
|
}
|
|
if bsub { //扣分操作
|
|
if bsub { //扣分操作
|
|
- newDate := next.AddDate(0, 1, 0)
|
|
|
|
|
|
+ newDate := next.AddDate(0, 1, -1)
|
|
creditDoc := map[string]interface{}{
|
|
creditDoc := map[string]interface{}{
|
|
"s_uid": userId,
|
|
"s_uid": userId,
|
|
"s_umid": umid,
|
|
"s_umid": umid,
|